Use separate entrypoint to combine compose files
Now, when you run `docker compose up`, it'll check for a `conf` directory during start-up, and run `node install` (with a bunch of options based on env vars). If not, it'll run `node update`. This means that the separate `docker-compose.setup.yml` is no longer needed, and that this plays nice with docker swarm mode.
This commit is contained in:
parent
5fd07ac619
commit
6e964a69a7
|
@ -1,2 +1,3 @@
|
||||||
*
|
*
|
||||||
!Dockerfile
|
!Dockerfile
|
||||||
|
!docker-entrypoint.sh
|
||||||
|
|
36
Dockerfile
36
Dockerfile
|
@ -1,8 +1,6 @@
|
||||||
FROM node:10-stretch
|
FROM node:12.18.4-stretch
|
||||||
|
|
||||||
ENV AAT_VER=0.2.2
|
ENV AAT_VER=0.10.4
|
||||||
|
|
||||||
MAINTAINER Vadim Prishlyak
|
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update && apt-get install -y \
|
||||||
build-essential \
|
build-essential \
|
||||||
|
@ -12,32 +10,24 @@ RUN apt-get update && apt-get install -y \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# global npm dependencies
|
# global npm dependencies
|
||||||
RUN npm install -g pm2 \
|
RUN npm install -g grunt-cli \
|
||||||
&& npm install -g grunt-cli \
|
|
||||||
&& npm install -g adapt-cli
|
&& npm install -g adapt-cli
|
||||||
|
|
||||||
RUN cd / \
|
RUN cd / \
|
||||||
&& git clone https://github.com/adaptlearning/adapt_authoring.git
|
&& wget -q https://github.com/adaptlearning/adapt_authoring/archive/v${AAT_VER}.tar.gz \
|
||||||
|
&& tar -xzf v${AAT_VER}.tar.gz \
|
||||||
|
&& mv adapt_authoring-${AAT_VER} adapt_authoring \
|
||||||
|
&& rm v${AAT_VER}.tar.gz
|
||||||
|
|
||||||
WORKDIR /adapt_authoring
|
WORKDIR /adapt_authoring
|
||||||
|
|
||||||
|
# 3wc: unfortunately the installer script then removes the node_modules directory
|
||||||
|
# https://github.com/adaptlearning/adapt_authoring/blob/master/lib/installHelpers.js#L647
|
||||||
RUN npm install --production
|
RUN npm install --production
|
||||||
|
|
||||||
## Currently have to run this within container so we can link to running mongodb container...
|
|
||||||
## docker run -it -P --link adaptdb --name adapt adaptframework bash
|
|
||||||
#RUN node install --install Y --serverPort 5000 --serverName localhost --dbHost 127.0.0.1 \
|
|
||||||
# --dbName adapt-tenant-master --dbPort 27017 \
|
|
||||||
# --dataRoot data --sessionSecret your-session-secret --useffmpeg Y \
|
|
||||||
# --smtpService dummy --smtpUsername smtpUser --smtpPassword smtpPass --fromAddress you@example.com \
|
|
||||||
# --name master --displayName Master --email admin --password password
|
|
||||||
|
|
||||||
# upgrade the AuthoringTool and or Framework
|
|
||||||
RUN node upgrade --Y/n Y
|
|
||||||
|
|
||||||
# guest: 5000, host: 5000
|
|
||||||
# guest: 5858, host: 5858
|
|
||||||
# guest: 27017, host: 27027
|
|
||||||
|
|
||||||
EXPOSE 5000
|
EXPOSE 5000
|
||||||
|
|
||||||
CMD pm2 start --no-daemon processes.json
|
COPY docker-entrypoint.sh /
|
||||||
|
|
||||||
|
ENTRYPOINT ["/docker-entrypoint.sh"]
|
||||||
|
CMD ["node", "server"]
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
version: '2'
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
adaptdata:
|
|
||||||
external:
|
|
||||||
name: authoring_adaptdata
|
|
||||||
|
|
||||||
services:
|
|
||||||
setup:
|
|
||||||
# build: .
|
|
||||||
image: ${REGISTRY:-pvadimr/adaptauthoring:${TAG:-latest}
|
|
||||||
container_name: adaptauthoring
|
|
||||||
# extends:
|
|
||||||
# file: docker-compose.yml
|
|
||||||
# service: authoring
|
|
||||||
# volumes_from:
|
|
||||||
# - adaptauthoring
|
|
||||||
volumes:
|
|
||||||
- adaptdata:/adapt_authoring
|
|
||||||
external_links:
|
|
||||||
- adaptdb
|
|
||||||
command: node install --install Y --serverPort 5000 --serverName localhost --dbHost adaptdb --dbName adapt-tenant-master --dbPort 27017 --dataRoot data --sessionSecret your-session-secret --useffmpeg Y --smtpService dummy --smtpUsername smtpUser --smtpPassword smtpPass --fromAddress you@example.com --name master --displayName Master --email ${ADMIN_EMAIL} --password ${ADMIN_PASSWORD} # && node upgrade --Y/n Y
|
|
||||||
upgrade:
|
|
||||||
extends:
|
|
||||||
service: setup
|
|
||||||
command: node upgrade --Y/n Y
|
|
|
@ -1,28 +1,41 @@
|
||||||
version: '2'
|
version: '2'
|
||||||
|
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
image: 3wordchant/adaptauthoring:0.10.4
|
||||||
|
build: .
|
||||||
|
volumes:
|
||||||
|
- adaptdata:/adapt_authoring
|
||||||
|
links:
|
||||||
|
- db
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
ports:
|
||||||
|
- "5000:5000"
|
||||||
|
networks:
|
||||||
|
- internal
|
||||||
|
environment:
|
||||||
|
- PORT=5000
|
||||||
|
- DOMAIN=adapt.localhost
|
||||||
|
- DB_HOST=db
|
||||||
|
- DB_NAME=adapt
|
||||||
|
- DB_USER=adapt
|
||||||
|
- SESSION_SECRET=foobar
|
||||||
|
- ADMIN_EMAIL=foo@bar.com
|
||||||
|
- ADMIN_PASSWORD=foo
|
||||||
|
- FROM_EMAIL=adapt@localhost
|
||||||
|
|
||||||
|
db:
|
||||||
|
container_name: adaptdb
|
||||||
|
image: mongo:3.6
|
||||||
|
volumes:
|
||||||
|
- adaptdb:/data/db
|
||||||
|
networks:
|
||||||
|
- internal
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
adaptdata:
|
adaptdata:
|
||||||
adaptdb:
|
adaptdb:
|
||||||
|
|
||||||
services:
|
networks:
|
||||||
db:
|
internal:
|
||||||
container_name: adaptdb
|
|
||||||
image: mongo
|
|
||||||
volumes:
|
|
||||||
- adaptdb:/data/db
|
|
||||||
# ports:
|
|
||||||
# - 27017:27017
|
|
||||||
authoring:
|
|
||||||
container_name: adaptauthoring
|
|
||||||
image: pvadimr/adaptauthoring
|
|
||||||
image: ${REGISTRY:-pvadimr/adaptauthoring:${TAG:-latest}
|
|
||||||
volumes:
|
|
||||||
- adaptdata:/adapt_authoring
|
|
||||||
# build: .
|
|
||||||
command: pm2 start --no-daemon processes.json
|
|
||||||
links:
|
|
||||||
- db
|
|
||||||
# depends_on:
|
|
||||||
# - db
|
|
||||||
ports:
|
|
||||||
- "5000:5000"
|
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
file_env() {
|
||||||
|
# 3wc: Load $VAR_FILE into $VAR - useful for secrets. See
|
||||||
|
# https://medium.com/@adrian.gheorghe.dev/using-docker-secrets-in-your-environment-variables-7a0609659aab
|
||||||
|
local var="$1"
|
||||||
|
local fileVar="${var}_FILE"
|
||||||
|
local def="${2:-}"
|
||||||
|
|
||||||
|
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
|
||||||
|
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
local val="$def"
|
||||||
|
if [ "${!var:-}" ]; then
|
||||||
|
val="${!var}"
|
||||||
|
elif [ "${!fileVar:-}" ]; then
|
||||||
|
val="$(< "${!fileVar}")"
|
||||||
|
fi
|
||||||
|
export "$var"="$val"
|
||||||
|
unset "$fileVar"
|
||||||
|
}
|
||||||
|
|
||||||
|
load_vars() {
|
||||||
|
file_env "DB_PASSWORD"
|
||||||
|
file_env "ADMIN_PASSWORD"
|
||||||
|
file_env "SESSION_KEY"
|
||||||
|
}
|
||||||
|
|
||||||
|
install_adapt() {
|
||||||
|
echo "No 'conf' dir found, installing Adapt"
|
||||||
|
# 3wc: use `yes` to skip the dbPass and dbAuthSource prompts
|
||||||
|
yes "" | node install --install Y \
|
||||||
|
--authoringToolRepository https://github.com/adaptlearning/adapt_authoring.git \
|
||||||
|
--frameworkRepository https://github.com/adaptlearning/adapt_framework.git \
|
||||||
|
--frameworkRevision tags/v5.7.0 \
|
||||||
|
--serverPort "${PORT}" --serverName "${DOMAIN}" \
|
||||||
|
--dbHost "${DB_HOST}" --dbName "${DB_NAME}" --dbPort 27017 \
|
||||||
|
--dbUser "${DB_USER}" \
|
||||||
|
--useConnectionUri false \
|
||||||
|
--dataRoot data \
|
||||||
|
--sessionSecret "${SESSION_KEY}" --useffmpeg Y \
|
||||||
|
--useSmtp true --smtpService dummy \
|
||||||
|
--smtpConnectionUrl smtp://postfix_relay_app \
|
||||||
|
--fromAddress "${FROM_EMAIL}" \
|
||||||
|
--masterTenantName main --masterTenantDisplayName Main \
|
||||||
|
--suEmail "${ADMIN_EMAIL}" --suPassword "${ADMIN_PASSWORD}" \
|
||||||
|
--suRetypePassword "${ADMIN_PASSWORD}"
|
||||||
|
#--dbPass "$DB_PASSWORD" --dbAuthSource ""
|
||||||
|
#--smtpUsername "${SMTP_USERNAME}" --smtpPassword "${SMTP_PASSWORD}" \
|
||||||
|
}
|
||||||
|
|
||||||
|
update_adapt() {
|
||||||
|
echo "Upgrade Adapt Authoring Tool & Framework"
|
||||||
|
node upgrade --continue Y --updateAutomatically Y
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
load_vars
|
||||||
|
|
||||||
|
if [ ! -d conf ]; then
|
||||||
|
install_adapt
|
||||||
|
else
|
||||||
|
update_adapt
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
main
|
||||||
|
|
||||||
|
exec "$@"
|
Loading…
Reference in New Issue