From 8337e2632686cf8d0dcf39474019370f7d3dc752 Mon Sep 17 00:00:00 2001 From: Michal Kostewicz Date: Fri, 5 Feb 2021 19:18:05 +0100 Subject: Moved getferdi/server-docker into getferdi/server repository. Add sample docker-compose file and update README.md files in root and docker directories. --- docker/docker-compose.yml | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 docker/docker-compose.yml (limited to 'docker/docker-compose.yml') diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..7bf1b8c --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,37 @@ +version: "2" +services: + ferdi-server: + image: getferdi/ferdi-server + container_name: ferdi-server + environment: + - NODE_ENV=development + - EXTERNAL_DOMAIN=localhost + - DB_CONNECTION=sqlite + - DB_HOST=127.0.0.1 + - DB_PORT=3306 + - DB_USER=root + - DB_PASSWORD=password + - DB_DATABASE=adonis + - DB_SSL=false + - MAIL_CONNECTION=smtp + - SMPT_HOST=127.0.0.1 + - SMTP_PORT=2525 + - MAIL_SSL=false + - MAIL_USERNAME=username + - MAIL_PASSWORD=password + - MAIL_SENDER=noreply@getferdi.com + - IS_CREATION_ENABLED=true + - IS_DASHBOARD_ENABLED=true + - IS_REGISTRATION_ENABLED=true + - CONNECT_WITH_FRANZ=false + volumes: + - ferdi-config-vol:/config + - ferdi-database-vol:/app/database + - ferdi-recipes-vol:/app/recipes + ports: + - 3333:80 + restart: unless-stopped +volumes: + ferdi-config-vol: + ferdi-database-vol: + ferdi-recipes-vol: \ No newline at end of file -- cgit v1.2.3-54-g00ecf From 7329a7fd852082f0216b4f67f1912eaa601981fc Mon Sep 17 00:00:00 2001 From: Michal Kostewicz Date: Sun, 7 Feb 2021 12:43:41 +0100 Subject: Add new configuration for docker with small script to generate or use APP_KEY. docker-compose was adjusted to use DATA_DIR. --- .dockerignore | 2 +- docker/Dockerfile | 109 ++++------------- docker/docker-compose.yml | 5 +- docker/entrypoint.sh | 40 +++++++ docker/root/defaults/.env.example | 35 ------ docker/root/etc/cont-init.d/10-adduser | 32 ----- docker/root/etc/cont-init.d/50-config | 174 ---------------------------- docker/root/etc/services.d/ferdi-server/run | 10 -- 8 files changed, 64 insertions(+), 343 deletions(-) create mode 100755 docker/entrypoint.sh delete mode 100755 docker/root/defaults/.env.example delete mode 100755 docker/root/etc/cont-init.d/10-adduser delete mode 100755 docker/root/etc/cont-init.d/50-config delete mode 100755 docker/root/etc/services.d/ferdi-server/run (limited to 'docker/docker-compose.yml') diff --git a/.dockerignore b/.dockerignore index 43c6cd0..7dad3a9 100644 --- a/.dockerignore +++ b/.dockerignore @@ -14,7 +14,7 @@ README-secret.md # ignore other directories docker -!docker/root +!docker/entrypoint.sh node_modules diff --git a/docker/Dockerfile b/docker/Dockerfile index a561509..799bb0b 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,96 +1,27 @@ -FROM lsiobase/alpine:3.11 +FROM node:lts-alpine as build -# version labels -ARG BUILD_DATE -LABEL build_version="Ferdi-server-docker Build-date:- ${BUILD_DATE}" +WORKDIR /server-build + +RUN ["apk", "add", "--no-cache", "python", "make", "gcc", "g++", "libc-dev", "sqlite-dev"] + +COPY . /server-build + +RUN ["npm", "ci", "--production", "--build-from-source", "--sqlite=/usr/local"] + +FROM node:lts-alpine + +WORKDIR /app LABEL maintainer="xthursdayx" -ARG FERDI_RELEASE -ENV NODE_VERSION=10.16.3 -ENV S6_BEHAVIOUR_IF_STAGE2_FAILS=2 +ENV HOST=0.0.0.0 PORT=3333 -# install packages -RUN \ - echo "**** installing build packages ****" && \ - apk add --no-cache \ - libcap \ - libstdc++ \ - nano && \ - apk add --no-cache --virtual .build-deps \ - binutils-gold \ - curl \ - gnupg \ - gcc \ - g++ \ - linux-headers \ - make \ - memcached \ - python && \ - echo "**** downloading keys ****" && \ - # gpg keys listed at https://github.com/nodejs/node#release-keys - for key in \ - 94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \ - FD3A5288F042B6850C66B31F09FE44734EB7990E \ - 71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \ - DD8F2338BAE7501E3DD5AC78C273792F7D83545D \ - C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \ - B9AE9905FFD7803F25714661B63B535A4C206CA9 \ - 77984A986EBC2AA786BC0F66B01FBB92821C587A \ - 8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600 \ - 4ED778F539E3634C779C87C6D7062848A1AB005C \ - A48C2BEE680E841632CD4E44F07496B3EB3C1762 \ - B9E2F5981AA6E0CD28160D9FF13993A75599653C \ - ; do \ - gpg --batch --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys "$key" || \ - gpg --batch --keyserver hkp://ipv4.pool.sks-keyservers.net --recv-keys "$key" || \ - gpg --batch --keyserver hkp://pgp.mit.edu:80 --recv-keys "$key" ; \ - done && \ - echo "**** installing node ****" && \ - curl -fsSLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION.tar.xz" && \ - curl -fsSLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" && \ - gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc && \ - grep " node-v$NODE_VERSION.tar.xz\$" SHASUMS256.txt | sha256sum -c - && \ - tar -xf "node-v$NODE_VERSION.tar.xz" && \ - cd "node-v$NODE_VERSION" && \ - ./configure --prefix=/usr && \ - make -j$(getconf _NPROCESSORS_ONLN) V= && \ - make install && \ - apk del .build-deps && \ - cd / && \ - rm -Rf "node-v$NODE_VERSION" && \ - rm "node-v$NODE_VERSION.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt +RUN ["apk", "add", "--no-cache", "sqlite-libs", "curl"] -COPY . /app - -RUN \ - apk add --no-cache --virtual .build-deps-ferdi \ - curl \ - gnupg \ - tar && \ - echo "**** installing npm ****" && \ - npm config set unsafe-perm true && \ - npm install -g npm@latest && \ - find /usr/lib/node_modules/npm -name test -o -name .bin -type d | xargs rm -rf && \ - echo "**** cleanup ****" && \ - apk del .build-deps-ferdi && \ - rm -rf \ - ${RM_DIRS} \ - /SHASUMS256.txt \ - /tmp/* \ - /var/cache/apk/* \ - /usr/share/man/* \ - /usr/share/doc \ - /root/.node-gyp \ - /root/.config \ - /usr/lib/node_modules/npm/man \ - /usr/lib/node_modules/npm/doc \ - /usr/lib/node_modules/npm/html \ - /usr/lib/node_modules/npm/scripts - -COPY docker/root/ / +COPY --from=build /server-build /app +RUN ["touch", ".env"] +RUN ["npm", "i", "-g", "@adonisjs/cli"] -USER root +HEALTHCHECK --interval=5m --timeout=3s CMD curl -sSf http://localhost:${PORT}/health -# ports and volumes -EXPOSE 80 443 -VOLUME /app/database /app/recipes /config +COPY docker/entrypoint.sh /entrypoint.sh +CMD ["/entrypoint.sh"] \ No newline at end of file diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 7bf1b8c..364f9c3 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -24,12 +24,13 @@ services: - IS_DASHBOARD_ENABLED=true - IS_REGISTRATION_ENABLED=true - CONNECT_WITH_FRANZ=false + - DATA_DIR=/database volumes: - ferdi-config-vol:/config - - ferdi-database-vol:/app/database + - ferdi-database-vol:/database - ferdi-recipes-vol:/app/recipes ports: - - 3333:80 + - 3333:3333 restart: unless-stopped volumes: ferdi-config-vol: diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100755 index 0000000..cb0dd0f --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +echo << EOL +------------------------------------- + ____ ___ + / __/__ _______/ (_) + / _// -_) __/ _ / / + _/_/ \__/_/ \_,_/_/ + / __/__ _____ _____ ____ + _\ \/ -_) __/ |/ / -_) __/ + /___/\__/_/ |___/\__/_/ +Brought to you by getferdi.com +Support our Open Collective at: +https://opencollective.com/getferdi/ +EOL + +# Create APP key if needed +if [ ! -f "/config/FERDI_APP_KEY.txt" ]; + then + echo " " + echo "**** Generating Ferdi-server app key for first run ****" + adonis key:generate + source .env + echo $APP_KEY > /config/FERDI_APP_KEY.txt + echo "**** App Key set to $APP_KEY you can modify FERDI_APP_KEY.txt to update your key ****" + sed -i "s/APP_KEY=/APP_KEY=$APP_KEY/g" /config/config.txt +elif [ -f "/config/FERDI_APP_KEY.txt" ]; + then + echo " " + echo "**** App Key found ****" + APP_KEY=$(cat /config/FERDI_APP_KEY.txt) + sed -i "s/APP_KEY=.*/APP_KEY=$APP_KEY/g" /config/config.txt + echo "**** App Key set to $APP_KEY you can modify FERDI_APP_KEY.txt to update your key ****" +fi + +export APP_KEY=$APP_KEY + +node ace migration:run --force + +exec node server.js diff --git a/docker/root/defaults/.env.example b/docker/root/defaults/.env.example deleted file mode 100755 index 2ed73dc..0000000 --- a/docker/root/defaults/.env.example +++ /dev/null @@ -1,35 +0,0 @@ -HOST=0.0.0.0 -PORT=80 -NODE_ENV=development - -APP_NAME=AdonisJs -APP_URL=http://${EXTERNAL_DOMAIN} -EXTERNAL_DOMAIN=ferdi.domain.tld - -CACHE_VIEWS=false - -APP_KEY=appkey - -DB_CONNECTION=sqlite -DB_HOST=127.0.0.1 -DB_PORT=3306 -DB_USER=root -DB_PASSWORD=password -DB_DATABASE=adonis - -DB_SSL=false - -HASH_DRIVER=bcrypt - -IS_CREATION_ENABLED=true -IS_DASHBOARD_ENABLED=true -IS_REGISTRATION_ENABLED=true -CONNECT_WITH_FRANZ=true - -MAIL_CONNECTION=smtp -SMTP_PORT=2525 -SMTP_HOST=127.0.0.1 -MAIL_USERNAME=username -MAIL_PASSWORD=password -MAIL_SENDER=noreply@getferdi.com -MAIL_SSL=false diff --git a/docker/root/etc/cont-init.d/10-adduser b/docker/root/etc/cont-init.d/10-adduser deleted file mode 100755 index 8ba1aea..0000000 --- a/docker/root/etc/cont-init.d/10-adduser +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/with-contenv bash - -PUID=${PUID:-911} -PGID=${PGID:-911} - -groupmod -o -g "$PGID" abc -usermod -o -u "$PUID" abc - -echo ' -------------------------------------- - ____ ___ - / __/__ _______/ (_) - / _// -_) __/ _ / / - _/_/ \__/_/ \_,_/_/ - / __/__ _____ _____ ____ - _\ \/ -_) __/ |/ / -_) __/ - /___/\__/_/ |___/\__/_/ - -Brought to you by getferdi.com -Support our Open Collective at: -https://opencollective.com/getferdi/ -------------------------------------- -GID/UID --------------------------------------' -echo " -User uid: $(id -u abc) -User gid: $(id -g abc) -------------------------------------- -" -chown abc:abc /app -chown abc:abc /config -chown abc:abc /defaults \ No newline at end of file diff --git a/docker/root/etc/cont-init.d/50-config b/docker/root/etc/cont-init.d/50-config deleted file mode 100755 index 72b2d00..0000000 --- a/docker/root/etc/cont-init.d/50-config +++ /dev/null @@ -1,174 +0,0 @@ -#!/usr/bin/with-contenv bash - -# Display variables for troubleshooting -echo " " -echo "-------------------------------------" -echo " " -echo -e "Variables set:\\n\ -NODE_ENV=${NODE_ENV}\\n\ -EXTERNAL_DOMAIN=${EXTERNAL_DOMAIN}\\n\ -DB_CONNECTION=${DB_CONNECTION}\\n\ -DB_HOST=${DB_HOST}\\n\ -DB_PORT=${DB_PORT}\\n\ -DB_USER=${DB_USER}\\n\ -DB_PASSWORD=${DB_PASSWORD}\\n\ -DB_DATABASE=${DB_DATABASE}\\n\ -DB_SSL=${DB_SSL}\\n\ -IS_CREATION_ENABLED=${IS_CREATION_ENABLED}\\n\ -IS_DASHBOARD_ENABLED=${IS_DASHBOARD_ENABLED}\\n\ -IS_REGISTRATION_ENABLED=${IS_REGISTRATION_ENABLED}\\n\ -CONNECT_WITH_FRANZ=${CONNECT_WITH_FRANZ}\\n\ -MAIL_CONNECTION=${MAIL_CONNECTION}\\n\ -SMTP_PORT=${SMTP_PORT}\\n\ -SMTP_HOST=${SMTP_HOST}\\n\ -MAIL_SSL=${MAIL_SSL}\\n\ -MAIL_USERNAME=${MAIL_USERNAME}\\n\ -MAIL_PASSWORD=${MAIL_PASSWORD}\\n\ -MAIL_SENDER=${MAIL_SENDER}\\n" - -# Echo init finish for test runs -if [ -n "${TEST_RUN}" ]; then - echo " " - echo '**** [services.d] done ****' -fi - -# set ferdi-server status -echo " " -echo "**** Checking Ferdi-server settings ****" -if [ -f /config/config.txt ]; then - [[ "${NODE_ENV}" ]] && sed -i "s/NODE_ENV=.*/NODE_ENV=${NODE_ENV}/g" /config/config.txt - [[ "${EXTERNAL_DOMAIN}" ]] && sed -i "s/EXTERNAL_DOMAIN=.*/EXTERNAL_DOMAIN=${EXTERNAL_DOMAIN}/g" /config/config.txt - [[ "${IS_CREATION_ENABLED}" ]] && sed -i "s/IS_CREATION_ENABLED=.*/IS_CREATION_ENABLED=${IS_CREATION_ENABLED}/g" /config/config.txt - [[ "${IS_DASHBOARD_ENABLED}" ]] && sed -i "s/IS_DASHBOARD_ENABLED=.*/IS_DASHBOARD_ENABLED=${IS_DASHBOARD_ENABLED}/g" /config/config.txt - [[ "${IS_REGISTRATION_ENABLED}" ]] && sed -i "s/IS_REGISTRATION_ENABLED=.*/IS_REGISTRATION_ENABLED=${IS_REGISTRATION_ENABLED}/g" /config/config.txt - [[ "${CONNECT_WITH_FRANZ}" ]] && sed -i "s/CONNECT_WITH_FRANZ=.*/CONNECT_WITH_FRANZ=${CONNECT_WITH_FRANZ}/g" /config/config.txt - [[ "${DB_CONNECTION}" ]] && sed -i "s/DB_CONNECTION=.*/DB_CONNECTION=${DB_CONNECTION}/g" /config/config.txt - [[ "${DB_HOST}" ]] && sed -i "s/DB_HOST=.*/DB_HOST=${DB_HOST}/g" /config/config.txt - [[ "${DB_PORT}" ]] && sed -i "s/DB_PORT=.*/DB_PORT=${DB_PORT}/g" /config/config.txt - [[ "${DB_DATABASE}" ]] && sed -i "s/DB_DATABASE=.*/DB_DATABASE=${DB_DATABASE}/g" /config/config.txt - [[ "${DB_USER}" ]] && sed -i "s/DB_USER=.*/DB_USER=${DB_USER}/g" /config/config.txt - [[ "${DB_PASSWORD}" ]] && sed -i "s/DB_PASSWORD=.*/DB_PASSWORD=${DB_PASSWORD}/g" /config/config.txt - [[ "${DB_SSL}" ]] && sed -i "s/DB_SSL=.*/DB_SSL=${DB_SSL}/g" /config/config.txt - [[ "${MAIL_CONNECTION}" ]] && sed -i "s/MAIL_CONNECTION=.*/MAIL_CONNECTION=${MAIL_CONNECTION}/g" /config/config.txt - [[ "${SMTP_HOST}" ]] && sed -i "s/SMTP_HOST=.*/SMTP_HOST=${SMTP_HOST}/g" /config/config.txt - [[ "${SMTP_PORT}" ]] && sed -i "s/SMTP_PORT=.*/SMTP_PORT=${SMTP_PORT}/g" /config/config.txt - [[ "${MAIL_SSL}" ]] && sed -i "s/MAIL_SSL=.*/MAIL_SSL=${MAIL_SSL}/g" /config/config.txt - [[ "${MAIL_USERNAME}" ]] && sed -i "s/MAIL_USERNAME=.*/MAIL_USERNAME=${MAIL_USERNAME}/g" /config/config.txt - [[ "${MAIL_PASSWORD}" ]] && sed -i "s/MAIL_PASSWORD=.*/MAIL_PASSWORD=${MAIL_PASSWORD}/g" /config/config.txt - [[ "${MMAIL_SENDER}" ]] && sed -i "s/MAIL_SENDER=.*/MAIL_SENDER=${MAIL_SENDER}/g" /config/config.txt - rm /config/.env - cp /config/config.txt /config/.env -elif [ ! -f /config/config.txt ]; then - echo " " - echo "**** Generating .env file ****" - cp /defaults/.env.example /config/.env - [[ "${NODE_ENV}" ]] && sed -i "s/NODE_ENV=.*/NODE_ENV=${NODE_ENV}/g" /config/.env - [[ "${EXTERNAL_DOMAIN}" ]] && sed -i "s/EXTERNAL_DOMAIN=.*/EXTERNAL_DOMAIN=${EXTERNAL_DOMAIN}/g" /config/.env - [[ "${IS_CREATION_ENABLED}" ]] && sed -i "s/IS_CREATION_ENABLED=.*/IS_CREATION_ENABLED=${IS_CREATION_ENABLED}/g" /config/.env - [[ "${IS_DASHBOARD_ENABLED}" ]] && sed -i "s/IS_DASHBOARD_ENABLED=.*/IS_DASHBOARD_ENABLED=${IS_DASHBOARD_ENABLED}/g" /config/.env - [[ "${IS_REGISTRATION_ENABLED}" ]] && sed -i "s/IS_REGISTRATION_ENABLED=.*/IS_REGISTRATION_ENABLED=${IS_REGISTRATION_ENABLED}/g" /config/.env - [[ "${CONNECT_WITH_FRANZ}" ]] && sed -i "s/CONNECT_WITH_FRANZ=.*/CONNECT_WITH_FRANZ=${CONNECT_WITH_FRANZ}/g" /config/.env - [[ "${DB_CONNECTION}" ]] && sed -i "s/DB_CONNECTION=.*/DB_CONNECTION=${DB_CONNECTION}/g" /config/.env - [[ "${DB_HOST}" ]] && sed -i "s/DB_HOST=.*/DB_HOST=${DB_HOST}/g" /config/.env - [[ "${DB_PORT}" ]] && sed -i "s/DB_PORT=.*/DB_PORT=${DB_PORT}/g" /config/.env - [[ "${DB_DATABASE}" ]] && sed -i "s/DB_DATABASE=.*/DB_DATABASE=${DB_DATABASE}/g" /config/.env - [[ "${DB_USER}" ]] && sed -i "s/DB_USER=.*/DB_USER=${DB_USER}/g" /config/.env - [[ "${DB_PASSWORD}" ]] && sed -i "s/DB_PASSWORD=.*/DB_PASSWORD=${DB_PASSWORD}/g" /config/.env - [[ "${DB_SSL}" ]] && sed -i "s/DB_SSL=.*/DB_SSL=${DB_SSL}/g" /config/.env - [[ "${MAIL_CONNECTION}" ]] && sed -i "s/MAIL_CONNECTION=.*/MAIL_CONNECTION=${MAIL_CONNECTION}/g" /config/.env - [[ "${SMTP_HOST}" ]] && sed -i "s/SMTP_HOST=.*/SMTP_HOST=${SMTP_HOST}/g" /config/.env - [[ "${SMTP_PORT}" ]] && sed -i "s/SMTP_PORT=.*/SMTP_PORT=${SMTP_PORT}/g" /config/.env - [[ "${MAIL_SSL}" ]] && sed -i "s/MAIL_SSL=.*/MAIL_SSL=${MAIL_SSL}/g" /config/.env - [[ "${MAIL_USERNAME}" ]] && sed -i "s/MAIL_USERNAME=.*/MAIL_USERNAME=${MAIL_USERNAME}/g" /config/.env - [[ "${MAIL_PASSWORD}" ]] && sed -i "s/MAIL_PASSWORD=.*/MAIL_PASSWORD=${MAIL_PASSWORD}/g" /config/.env - [[ "${MMAIL_SENDER}" ]] && sed -i "s/MAIL_SENDER=.*/MAIL_SENDER=${MAIL_SENDER}/g" /config/.env - cp /config/.env /config/config.txt -fi - -# update .env -if [ -f /app/.env ]; then - rm /app/.env - ln -s /config/.env /app/.env -elif [ ! -f /app/.env ]; then - ln -s /config/.env /app/.env -fi - -# install adonisjs cli -echo " " -echo "**** Installing AdonisJS and deps ****" -cd /app -echo " " -npm config set unsafe-perm true -npm i -g @adonisjs/cli - -# install adonisjs dependencies -npm install - -# make custom recipe dir -if [ ! -f /app/recipes/dev ]; then -mkdir -p /app/recipes/dev -fi - -# setting the database helper -if [ "${DB_CONNECTION}" = "sqlite" ]; then - echo " " - echo "**** DB helper loaded ****" - else npm i ${DB_CONNECTION} - echo " " - echo "**** DB Helper loaded ****" -fi - -# check for the database endpoint for 30 seconds -echo " " -echo "**** Checking DB endpoint ****" -source .env -END=$((SECONDS+30)) -while [ ${SECONDS} -lt ${END} ] && [ "${DB_HOST} ${DB_PORT}" ]; - do - /usr/bin/nc -z ${DB_HOST} ${DB_PORT} && \ - if [ ! -z "$(/usr/bin/nc -w1 ${DB_HOST} ${DB_PORT})" ]; - then - [ ! -z "${RUN}" ] && break - RUN="RAN" - # we sleep here again due to first run init on DB containers - [ ! -f /dbwait.lock ] && sleep 5 - else - sleep 1 - fi - sleep 1 -done - -# source the .env file -source .env - -# database migration -echo " " -echo "**** Run DB migration ****" -adonis migration:run --force - -# Create APP key if needed -if [ ! -f "/config/FERDI_APP_KEY.txt" ]; - then - echo " " - echo "**** Generating Ferdi-server app key for first run ****" - adonis key:generate - source .env - echo $APP_KEY > /config/FERDI_APP_KEY.txt - echo "**** App Key set to $APP_KEY you can modify FERDI_APP_KEY.txt to update your key ****" - sed -i "s/APP_KEY=/APP_KEY=$APP_KEY/g" /config/config.txt -elif [ -f "/config/FERDI_APP_KEY.txt" ]; - then - echo " " - echo "**** App Key found ****" - APP_KEY=$(cat /config/FERDI_APP_KEY.txt) - sed -i "s/APP_KEY=.*/APP_KEY=$APP_KEY/g" /config/config.txt - echo "**** App Key set to $APP_KEY you can modify FERDI_APP_KEY.txt to update your key ****" -fi - -# set permissions -chown -R abc:abc \ - /config \ - /app - -# set lockfile to avoid DB waits for this specific container -touch /dbwait.lock diff --git a/docker/root/etc/services.d/ferdi-server/run b/docker/root/etc/services.d/ferdi-server/run deleted file mode 100755 index cf1568c..0000000 --- a/docker/root/etc/services.d/ferdi-server/run +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/with-contenv bash - -cd /app - -setcap 'cap_net_bind_service=+ep' `which node` - -# start server -echo " " -echo "**** Starting Ferdi-server ****" -exec s6-setuidgid abc adonis serve --dev \ No newline at end of file -- cgit v1.2.3-54-g00ecf From 02000d89159ba171cabbd341139871236f3df386 Mon Sep 17 00:00:00 2001 From: Michal Kostewicz Date: Sun, 7 Feb 2021 14:23:57 +0100 Subject: Revert line which choose DB folder using env. Move Dockerfile to root. Simplify export in entrypoint. Update README --- Dockerfile | 26 ++++++++++++++++++++++++++ README.md | 40 +--------------------------------------- config/database.js | 2 +- docker/Dockerfile | 27 --------------------------- docker/README.md | 1 + docker/docker-compose.yml | 6 +++--- docker/entrypoint.sh | 2 +- 7 files changed, 33 insertions(+), 71 deletions(-) create mode 100644 Dockerfile delete mode 100644 docker/Dockerfile (limited to 'docker/docker-compose.yml') diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..416c503 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM node:lts-alpine as build + +WORKDIR /server-build + +RUN ["apk", "add", "--no-cache", "python", "make", "gcc", "g++", "libc-dev", "sqlite-dev"] + +COPY . /server-build + +RUN ["npm", "ci", "--production", "--build-from-source", "--sqlite=/usr/local"] + +FROM node:lts-alpine + +WORKDIR /app +LABEL maintainer="xthursdayx" + +ENV HOST=0.0.0.0 PORT=3333 + +RUN ["apk", "add", "--no-cache", "sqlite-libs", "curl"] + +COPY --from=build /server-build /app +RUN ["npm", "i", "-g", "@adonisjs/cli"] + +HEALTHCHECK --interval=5m --timeout=3s CMD curl -sSf http://localhost:${PORT}/health + +COPY docker/entrypoint.sh /entrypoint.sh +CMD ["/entrypoint.sh"] \ No newline at end of file diff --git a/README.md b/README.md index 9d1b02d..60de4fc 100644 --- a/README.md +++ b/README.md @@ -78,45 +78,7 @@ After setting up the docker container we recommend you to set up an NGINX revers getferdi/ferdi-server ``` - Alternatively, you can also use docker-compose v2 schemas - - ```sh - --- - version: "2" - services: - ferdi-server: - image: getferdi/ferdi-server - container_name: ferdi-server - environment: - - NODE_ENV=development - - EXTERNAL_DOMAIN= - - DB_CONNECTION= - - DB_HOST= - - DB_PORT= - - DB_USER= - - DB_PASSWORD= - - DB_DATABASE= - - DB_SSL=true/false - - MAIL_CONNECTION= - - SMPT_HOST= - - SMTP_PORT= - - MAIL_SSL=true/false - - MAIL_USERNAME= - - MAIL_PASSWORD= - - MAIL_SENDER= - - IS_CREATION_ENABLED=true/false - - IS_DASHBOARD_ENABLED=true/false - - IS_REGISTRATION_ENABLED=true/false - - CONNECT_WITH_FRANZ=true/false - volumes: - - :/config - - :/app/database - - :/app/recipes - ports: - - :80 - restart: unless-stopped - ``` - You can also use sample [./docker/docker-compose.yml](https://github.com/getferdi/server/tree/master/docker/docker-compose.yml) file. + Alternatively, you can also use docker-compose v2 schemas. An example can be found in [./docker/docker-compose.yml](https://github.com/getferdi/server/tree/master/docker/docker-compose.yml) file. 3. Optionally, you can now [set up Nginx as a reverse proxy](https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04#set-up-nginx-as-a-reverse-proxy-server). diff --git a/config/database.js b/config/database.js index 6e08035..b7f57ad 100644 --- a/config/database.js +++ b/config/database.js @@ -31,7 +31,7 @@ module.exports = { sqlite: { client: 'sqlite3', connection: { - filename: `${Env.get('DATA_DIR', 'database')}/${Env.get('DB_DATABASE', 'development')}.sqlite`, + filename: Helpers.appRoot(`${Env.get('DATA_DIR', 'database')}/${Env.get('DB_DATABASE', 'development')}.sqlite`), }, useNullAsDefault: true, debug: Env.get('DB_DEBUG', false), diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index 799bb0b..0000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,27 +0,0 @@ -FROM node:lts-alpine as build - -WORKDIR /server-build - -RUN ["apk", "add", "--no-cache", "python", "make", "gcc", "g++", "libc-dev", "sqlite-dev"] - -COPY . /server-build - -RUN ["npm", "ci", "--production", "--build-from-source", "--sqlite=/usr/local"] - -FROM node:lts-alpine - -WORKDIR /app -LABEL maintainer="xthursdayx" - -ENV HOST=0.0.0.0 PORT=3333 - -RUN ["apk", "add", "--no-cache", "sqlite-libs", "curl"] - -COPY --from=build /server-build /app -RUN ["touch", ".env"] -RUN ["npm", "i", "-g", "@adonisjs/cli"] - -HEALTHCHECK --interval=5m --timeout=3s CMD curl -sSf http://localhost:${PORT}/health - -COPY docker/entrypoint.sh /entrypoint.sh -CMD ["/entrypoint.sh"] \ No newline at end of file diff --git a/docker/README.md b/docker/README.md index 5daa9fc..995ca8a 100644 --- a/docker/README.md +++ b/docker/README.md @@ -101,6 +101,7 @@ After the first run, Ferdi-server's configuration is saved inside the `config.tx | `-e IS_DASHBOARD_ENABLED=true` | for specifying whether to enable the Ferdi-server dashboard, default is true | | `-e IS_REGISTRATION_ENABLED=true` | for specifying whether to allow user registration, default is true | | `-e CONNECT_WITH_FRANZ=true` | for specifying whether to enable connections to the Franz server, default is true | +| `-e DATA_DIR=database` | for specifying sql-lite database folder, default is database | | `-v :/config` | this will store persistent ENV data on the docker host | | `-v :/app/database` | this will strore Ferdi-server's database on the docker host for persistence | | `-v :/app/recipes` | this will strore Ferdi-server's recipes on the docker host for persistence | diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 364f9c3..8a8c795 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -24,10 +24,10 @@ services: - IS_DASHBOARD_ENABLED=true - IS_REGISTRATION_ENABLED=true - CONNECT_WITH_FRANZ=false - - DATA_DIR=/database + - DATA_DIR=my-database volumes: - ferdi-config-vol:/config - - ferdi-database-vol:/database + - ferdi-database-vol:/app/my-database - ferdi-recipes-vol:/app/recipes ports: - 3333:3333 @@ -35,4 +35,4 @@ services: volumes: ferdi-config-vol: ferdi-database-vol: - ferdi-recipes-vol: \ No newline at end of file + ferdi-recipes-vol: diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index cb0dd0f..667196e 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -33,7 +33,7 @@ elif [ -f "/config/FERDI_APP_KEY.txt" ]; echo "**** App Key set to $APP_KEY you can modify FERDI_APP_KEY.txt to update your key ****" fi -export APP_KEY=$APP_KEY +export APP_KEY node ace migration:run --force -- cgit v1.2.3-54-g00ecf From b250a512363fb127d79078f13e1a0a132569e74e Mon Sep 17 00:00:00 2001 From: Michal Kostewicz Date: Mon, 8 Feb 2021 17:53:04 +0100 Subject: Fix DATA_DIR examples in README.md --- docker/README.md | 4 ++-- docker/docker-compose.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'docker/docker-compose.yml') diff --git a/docker/README.md b/docker/README.md index 6e18d16..8518e15 100644 --- a/docker/README.md +++ b/docker/README.md @@ -56,6 +56,7 @@ To create the docker container with the proper parameters: -e IS_DASHBOARD_ENABLED=true \ -e IS_REGISTRATION_ENABLED=true \ -e CONNECT_WITH_FRANZ=true \ + -e DATA_DIR=data \ -p :80 \ -v :/config \ -v :/app/database \ @@ -102,7 +103,7 @@ If any environmental parameter is not passed to the container, its value will be | `-e IS_DASHBOARD_ENABLED=true` | for specifying whether to enable the Ferdi-server dashboard, default is true | | `-e IS_REGISTRATION_ENABLED=true` | for specifying whether to allow user registration, default is true | | `-e CONNECT_WITH_FRANZ=true` | for specifying whether to enable connections to the Franz server, default is true | -| `-e DATA_DIR=database` | for specifying sql-lite database folder, default is database. Currently you need to use folder inside `/app` directory | +| `-e DATA_DIR=data` | for specifying sql-lite database folder, default is database. | | `-v :/config` | this will store persistent ENV data on the docker host | | `-v :/app/database` | this will strore Ferdi-server's database on the docker host for persistence | | `-v :/app/recipes` | this will strore Ferdi-server's recipes on the docker host for persistence | @@ -207,7 +208,6 @@ Below are the instructions for updating the container to get the most recent ver If you want to build this image locally, please run this command from root of [ferdi server repository](https://github.com/getferdi/server/tree/master/): ``` docker build \ - -f docker/Dockerfile \ --no-cache \ --pull \ -t getferdi/ferdi-server:latest . diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 8a8c795..64797c4 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -24,10 +24,10 @@ services: - IS_DASHBOARD_ENABLED=true - IS_REGISTRATION_ENABLED=true - CONNECT_WITH_FRANZ=false - - DATA_DIR=my-database + - DATA_DIR=data volumes: - ferdi-config-vol:/config - - ferdi-database-vol:/app/my-database + - ferdi-database-vol:/app/data - ferdi-recipes-vol:/app/recipes ports: - 3333:3333 -- cgit v1.2.3-54-g00ecf From 0437e56eb20791864a3ab45fafe029805bb05715 Mon Sep 17 00:00:00 2001 From: thursday Date: Fri, 9 Jul 2021 17:10:40 -0400 Subject: Update docker-compose.yml As per changes to database.js and the discussion here: https://github.com/getferdi/server/pull/48#discussion_r667150127 --- docker/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docker/docker-compose.yml') diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 64797c4..d558ed4 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -11,7 +11,7 @@ services: - DB_PORT=3306 - DB_USER=root - DB_PASSWORD=password - - DB_DATABASE=adonis + - DB_DATABASE=database - DB_SSL=false - MAIL_CONNECTION=smtp - SMPT_HOST=127.0.0.1 -- cgit v1.2.3-54-g00ecf From a347c97e6b1efb344752951af5db81d84e91e58f Mon Sep 17 00:00:00 2001 From: thursday Date: Fri, 9 Jul 2021 17:32:19 -0400 Subject: Update database name and volume. Updated to reflect the changes made to database.js and alert existing users to breaking changes. --- docker/docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docker/docker-compose.yml') diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index d558ed4..905d79b 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -11,7 +11,7 @@ services: - DB_PORT=3306 - DB_USER=root - DB_PASSWORD=password - - DB_DATABASE=database + - DB_DATABASE=database # existing Ferdi-server users who use the built-in sqlite database should use the database name "development" - DB_SSL=false - MAIL_CONNECTION=smtp - SMPT_HOST=127.0.0.1 @@ -27,7 +27,7 @@ services: - DATA_DIR=data volumes: - ferdi-config-vol:/config - - ferdi-database-vol:/app/data + - ferdi-database-vol:/app/data # existing Ferdi-server users who use the built-in sqlite database should use the volume name "/app/database" - ferdi-recipes-vol:/app/recipes ports: - 3333:3333 -- cgit v1.2.3-54-g00ecf From 0608dc7051bb0bdf22efc8af1c06a83c38b63c80 Mon Sep 17 00:00:00 2001 From: thursday Date: Mon, 12 Jul 2021 22:19:12 -0400 Subject: Update docker-compose.yml Update default database name. --- docker/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docker/docker-compose.yml') diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 905d79b..58c5bf5 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -11,7 +11,7 @@ services: - DB_PORT=3306 - DB_USER=root - DB_PASSWORD=password - - DB_DATABASE=database # existing Ferdi-server users who use the built-in sqlite database should use the database name "development" + - DB_DATABASE=ferdi # existing Ferdi-server users who use the built-in sqlite database should use the database name "development" - DB_SSL=false - MAIL_CONNECTION=smtp - SMPT_HOST=127.0.0.1 -- cgit v1.2.3-54-g00ecf From eac1b03b7cf41e0e234912155bb0b2ff25267738 Mon Sep 17 00:00:00 2001 From: thursday Date: Mon, 12 Jul 2021 22:34:02 -0400 Subject: Update docker-compose.yml Added additional migration note for existing users. --- docker/docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docker/docker-compose.yml') diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 58c5bf5..cf7269a 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -24,13 +24,13 @@ services: - IS_DASHBOARD_ENABLED=true - IS_REGISTRATION_ENABLED=true - CONNECT_WITH_FRANZ=false - - DATA_DIR=data + - DATA_DIR=data # existing Ferdi-server users should ensure that they add this variable to ensure data persistence. volumes: - ferdi-config-vol:/config - ferdi-database-vol:/app/data # existing Ferdi-server users who use the built-in sqlite database should use the volume name "/app/database" - ferdi-recipes-vol:/app/recipes ports: - - 3333:3333 + - 3333:3333 # existing Ferdi-server users will neeed to update their portt mappings from 80:3333 to 3333:3333. restart: unless-stopped volumes: ferdi-config-vol: -- cgit v1.2.3-54-g00ecf From f97d567dd8ca43b9b27153f4e98f45e84a22052d Mon Sep 17 00:00:00 2001 From: thursday Date: Tue, 13 Jul 2021 08:05:19 -0400 Subject: Update docker/docker-compose.yml Co-authored-by: Cromefire_ --- docker/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docker/docker-compose.yml') diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index cf7269a..acd1264 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -24,7 +24,7 @@ services: - IS_DASHBOARD_ENABLED=true - IS_REGISTRATION_ENABLED=true - CONNECT_WITH_FRANZ=false - - DATA_DIR=data # existing Ferdi-server users should ensure that they add this variable to ensure data persistence. + - DATA_DIR=/data # existing Ferdi-server users should ensure that they add this variable to ensure data persistence. volumes: - ferdi-config-vol:/config - ferdi-database-vol:/app/data # existing Ferdi-server users who use the built-in sqlite database should use the volume name "/app/database" -- cgit v1.2.3-54-g00ecf From c87515d488b5c7d8858f404dbca1627b87128b27 Mon Sep 17 00:00:00 2001 From: thursday Date: Tue, 13 Jul 2021 09:16:58 -0400 Subject: Update docker-compose.yml Fixed the DATA_DIR to align with the rest of the repo and removed the reference to the config volume. --- docker/docker-compose.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'docker/docker-compose.yml') diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index acd1264..7a67b87 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -26,13 +26,11 @@ services: - CONNECT_WITH_FRANZ=false - DATA_DIR=/data # existing Ferdi-server users should ensure that they add this variable to ensure data persistence. volumes: - - ferdi-config-vol:/config - - ferdi-database-vol:/app/data # existing Ferdi-server users who use the built-in sqlite database should use the volume name "/app/database" + - ferdi-database-vol:/data # existing Ferdi-server users who use the built-in sqlite database should use the volume name "/app/database" - ferdi-recipes-vol:/app/recipes ports: - 3333:3333 # existing Ferdi-server users will neeed to update their portt mappings from 80:3333 to 3333:3333. restart: unless-stopped volumes: - ferdi-config-vol: ferdi-database-vol: ferdi-recipes-vol: -- cgit v1.2.3-54-g00ecf From 38991cade3ee2898f057b087a1af2140407c99ab Mon Sep 17 00:00:00 2001 From: thursday Date: Sun, 18 Jul 2021 00:47:50 -0400 Subject: Update docker/docker-compose.yml Co-authored-by: Cromefire_ --- docker/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docker/docker-compose.yml') diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 7a67b87..577c546 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -11,7 +11,7 @@ services: - DB_PORT=3306 - DB_USER=root - DB_PASSWORD=password - - DB_DATABASE=ferdi # existing Ferdi-server users who use the built-in sqlite database should use the database name "development" + - DB_DATABASE=ferdi - DB_SSL=false - MAIL_CONNECTION=smtp - SMPT_HOST=127.0.0.1 -- cgit v1.2.3-54-g00ecf From 1e7416aa921375a264434fc1b8644027f70e87d9 Mon Sep 17 00:00:00 2001 From: thursday Date: Sun, 18 Jul 2021 00:48:16 -0400 Subject: Update docker/docker-compose.yml Co-authored-by: Cromefire_ --- docker/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docker/docker-compose.yml') diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 577c546..6f9adf3 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -24,7 +24,7 @@ services: - IS_DASHBOARD_ENABLED=true - IS_REGISTRATION_ENABLED=true - CONNECT_WITH_FRANZ=false - - DATA_DIR=/data # existing Ferdi-server users should ensure that they add this variable to ensure data persistence. + - DATA_DIR=/data volumes: - ferdi-database-vol:/data # existing Ferdi-server users who use the built-in sqlite database should use the volume name "/app/database" - ferdi-recipes-vol:/app/recipes -- cgit v1.2.3-54-g00ecf From c584dd81bbaad01b4ac58980fe18541cd5dd8a9b Mon Sep 17 00:00:00 2001 From: thursday Date: Sun, 18 Jul 2021 00:48:34 -0400 Subject: Update docker/docker-compose.yml Co-authored-by: Cromefire_ --- docker/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docker/docker-compose.yml') diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 6f9adf3..775d3e5 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -26,7 +26,7 @@ services: - CONNECT_WITH_FRANZ=false - DATA_DIR=/data volumes: - - ferdi-database-vol:/data # existing Ferdi-server users who use the built-in sqlite database should use the volume name "/app/database" + - ferdi-database-vol:/data - ferdi-recipes-vol:/app/recipes ports: - 3333:3333 # existing Ferdi-server users will neeed to update their portt mappings from 80:3333 to 3333:3333. -- cgit v1.2.3-54-g00ecf From 4ea7a59fd2441ddc322edcffe04e12b2d05fac9d Mon Sep 17 00:00:00 2001 From: thursday Date: Sun, 18 Jul 2021 00:48:57 -0400 Subject: Update docker/docker-compose.yml Co-authored-by: Cromefire_ --- docker/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docker/docker-compose.yml') diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 775d3e5..6d10cce 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -29,7 +29,7 @@ services: - ferdi-database-vol:/data - ferdi-recipes-vol:/app/recipes ports: - - 3333:3333 # existing Ferdi-server users will neeed to update their portt mappings from 80:3333 to 3333:3333. + - 3333:3333 restart: unless-stopped volumes: ferdi-database-vol: -- cgit v1.2.3-54-g00ecf From 4515cc9c0157aa71c6cfc0cd002b8a6eed1b423e Mon Sep 17 00:00:00 2001 From: thursday Date: Wed, 21 Jul 2021 02:53:32 -0400 Subject: Update docker-compose.yml Added PUID and PGID values --- docker/docker-compose.yml | 2 ++ 1 file changed, 2 insertions(+) (limited to 'docker/docker-compose.yml') diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 6d10cce..bd66ba2 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -25,6 +25,8 @@ services: - IS_REGISTRATION_ENABLED=true - CONNECT_WITH_FRANZ=false - DATA_DIR=/data + - PUID=1000 + - PGID=1000 volumes: - ferdi-database-vol:/data - ferdi-recipes-vol:/app/recipes -- cgit v1.2.3-54-g00ecf