Dockerfile which integrates mongo

This commit is contained in:
Ruben van de Ven 2020-12-17 10:58:41 +01:00
parent 61fd46777c
commit db151aca5c
2 changed files with 126 additions and 6 deletions

View file

@ -1,6 +1,106 @@
FROM node:12.16.1 as base FROM node:12.16.1 as base
ENV APP_HOME=/usr/src/app \ ENV APP_HOME=/usr/src/app \
TERM=xterm TERM=xterm
# Merge in mongodb to have a single image for Plesk deploy
# Code from: https://github.com/docker-library/mongo/blob/c9d4281a620f1e1ee95aaa084c5b60fc68ba65b9/3.6/Dockerfile
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
RUN groupadd -r mongodb && useradd -r -g mongodb mongodb
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
ca-certificates \
jq \
numactl \
; \
if ! command -v ps > /dev/null; then \
apt-get install -y --no-install-recommends procps; \
fi; \
rm -rf /var/lib/apt/lists/*
# grab gosu for easy step-down from root (https://github.com/tianon/gosu/releases)
ENV GOSU_VERSION 1.12
# grab "js-yaml" for parsing mongod's YAML config files (https://github.com/nodeca/js-yaml/releases)
ENV JSYAML_VERSION 3.13.1
RUN set -ex; \
\
savedAptMark="$(apt-mark showmanual)"; \
apt-get update; \
apt-get install -y --no-install-recommends \
wget \
; \
if ! command -v gpg > /dev/null; then \
apt-get install -y --no-install-recommends gnupg dirmngr; \
savedAptMark="$savedAptMark gnupg dirmngr"; \
elif gpg --version | grep -q '^gpg (GnuPG) 1\.'; then \
# "This package provides support for HKPS keyservers." (GnuPG 1.x only)
apt-get install -y --no-install-recommends gnupg-curl; \
fi; \
rm -rf /var/lib/apt/lists/*; \
\
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \
wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \
export GNUPGHOME="$(mktemp -d)"; \
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
command -v gpgconf && gpgconf --kill all || :; \
rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc; \
\
wget -O /js-yaml.js "https://github.com/nodeca/js-yaml/raw/${JSYAML_VERSION}/dist/js-yaml.js"; \
# TODO some sort of download verification here
\
apt-mark auto '.*' > /dev/null; \
apt-mark manual $savedAptMark > /dev/null; \
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
\
# smoke test
chmod +x /usr/local/bin/gosu; \
gosu --version; \
gosu nobody true
RUN mkdir /docker-entrypoint-initdb.d
ENV GPG_KEYS=2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
RUN set -ex; export GNUPGHOME="$(mktemp -d)"; for key in $GPG_KEYS; do gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; done; gpg --batch --export $GPG_KEYS > /etc/apt/trusted.gpg.d/mongodb.gpg; command -v gpgconf && gpgconf --kill all || :; rm -r "$GNUPGHOME"; apt-key list
# Allow build-time overrides (eg. to build image with MongoDB Enterprise version)
# Options for MONGO_PACKAGE: mongodb-org OR mongodb-enterprise
# Options for MONGO_REPO: repo.mongodb.org OR repo.mongodb.com
# Example: docker build --build-arg MONGO_PACKAGE=mongodb-enterprise --build-arg MONGO_REPO=repo.mongodb.com .
ARG MONGO_PACKAGE=mongodb-org
ARG MONGO_REPO=repo.mongodb.org
ENV MONGO_PACKAGE=${MONGO_PACKAGE} MONGO_REPO=${MONGO_REPO}
ENV MONGO_MAJOR 3.6
ENV MONGO_VERSION 3.6.21
# bashbrew-architectures:amd64 arm64v8
RUN echo "deb http://$MONGO_REPO/apt/debian stretch/${MONGO_PACKAGE%-unstable}/$MONGO_MAJOR main" | tee "/etc/apt/sources.list.d/${MONGO_PACKAGE%-unstable}.list"
RUN set -x \
# installing "mongodb-enterprise" pulls in "tzdata" which prompts for input
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install -y \
${MONGO_PACKAGE}=$MONGO_VERSION \
${MONGO_PACKAGE}-server=$MONGO_VERSION \
${MONGO_PACKAGE}-shell=$MONGO_VERSION \
${MONGO_PACKAGE}-mongos=$MONGO_VERSION \
${MONGO_PACKAGE}-tools=$MONGO_VERSION \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /var/lib/mongodb \
&& mv /etc/mongod.conf /etc/mongod.conf.orig
RUN mkdir -p /data/db /data/configdb \
&& chown -R mongodb:mongodb /data/db /data/configdb
VOLUME /data/db /data/configdb
# End mongo
RUN mkdir -p $APP_HOME RUN mkdir -p $APP_HOME
WORKDIR $APP_HOME WORKDIR $APP_HOME
EXPOSE 8000 EXPOSE 8000
@ -27,5 +127,11 @@ ENV NODE_ENV=production
COPY package.json package-lock.json index.js ./ COPY package.json package-lock.json index.js ./
RUN npm install --production RUN npm install --production
RUN npm rebuild node-sass RUN npm rebuild node-sass
# COPY --from=build $APP_HOME/dist ./dist
CMD ["npm", "run", "start:prod"]
COPY dist/static/images/* ./dist/static/images/
COPY dist/static/assets ./dist/static/assets
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod 755 /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]

View file

@ -10,6 +10,8 @@ There is a hidden link to have an overview of all users registered on the server
# Deployment # Deployment
## Manual
* Push to git (in case linting fails on commit use `git commit --no-verify`) * Push to git (in case linting fails on commit use `git commit --no-verify`)
* Pull on server. * Pull on server.
* `service p5.js-web-editor stop` * `service p5.js-web-editor stop`
@ -17,15 +19,27 @@ There is a hidden link to have an overview of all users registered on the server
* `npm run build:client` * `npm run build:client`
* `service p5.js-web-editor start` * `service p5.js-web-editor start`
## Docker
Branch `single_docker` has a Frankenstein Dockerfile to embed mongo in the single image for deployment to Plex (which doesn't know docker-compose...)
To build an image called `digitalplayground`:
`docker build -t digitalplayground .`
To run it we provide the port to publish, and need to map the volumes of mongo for persistent storage (don't use the tmp folder from the example if you really want persistent storage):
`docker run -it --env-file .env.production --publish 8001:8000 -v /tmp/dp/db:/data/db -v /tmp/dp/configdb:/data/configdb digitalplayground`
## s3 storage
Gebruik s3cmd om bucket in te stellen. Gebruik s3cmd om bucket in te stellen.
## Make bucket: ### Make bucket:
s3cmd mb s3://digitalplayground-p5 s3cmd mb s3://digitalplayground-p5
## Set the CORS rules ### Set the CORS rules
s3cmd -c .s3cfg setcors CORS.xml s3://digitalplayground-p5 s3cmd -c .s3cfg setcors CORS.xml s3://digitalplayground-p5
## Delete the CORS rules ### Delete the CORS rules
s3cmd -c .s3cfg delcors s3://digitalplayground-p5 s3cmd -c .s3cfg delcors s3://digitalplayground-p5
## Get bucket info including CORS rules ### Get bucket info including CORS rules
s3cmd -c .s3cfg info s3://digitalplayground-p5 s3cmd -c .s3cfg info s3://digitalplayground-p5