diff --git a/Dockerfile b/Dockerfile index 9519b434f72..89e6eb06cfc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,16 @@ from mozorg/bedrock_base -RUN apt-get install -y --no-install-recommends npm - -COPY . /app - +COPY ./node_modules ./ +COPY package.json ./ RUN npm install --production + +COPY ./requirements/ ./requirements/ RUN pip install --no-cache-dir -r requirements/dev.txt RUN pip install --no-cache-dir -r requirements/prod.txt RUN pip install --no-cache-dir -r requirements/docker.txt +RUN pip install --no-cache-dir -r requirements/docker-dev.txt + +COPY . ./ RUN ./manage.py collectstatic -l --noinput @@ -18,5 +21,7 @@ RUN ./docker/bin/softlinkstatic.py RUN bash -c "if [[ ! -e locale ]]; then git clone --depth 1 https://github.com/mozilla-l10n/bedrock-l10n locale; fi" # Change User +# No USER directive since supervisor is set to run processes as webdev RUN chown webdev.webdev -R . -USER webdev + +CMD ["docker/run-supervisor.sh"] diff --git a/docker/run-supervisor.sh b/docker/run-supervisor.sh new file mode 100755 index 00000000000..7540542eff1 --- /dev/null +++ b/docker/run-supervisor.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -xe + +enable_proc() { + cp "etc/supervisor_available/$1.conf" "etc/supervisor_enabled/$1.conf" +} + +DEV=$(echo "$DEV" | tr '[:upper:]' '[:lower:]') + +enable_proc bedrock +[[ "$DEV" == "true" ]] && enable_proc cron || true + +exec supervisord -c etc/supervisord.conf diff --git a/etc/supervisor_available/bedrock.conf b/etc/supervisor_available/bedrock.conf new file mode 100644 index 00000000000..6e3443b731a --- /dev/null +++ b/etc/supervisor_available/bedrock.conf @@ -0,0 +1,8 @@ +[program:bedrock] +command = /app/docker/run-prod.sh +numprocs = 1 +autostart = true +user = webdev +redirect_stderr = true +stdout_logfile = /dev/stdout +stdout_logfile_maxbytes = 0 diff --git a/etc/supervisor_available/cron.conf b/etc/supervisor_available/cron.conf new file mode 100644 index 00000000000..e75075a8782 --- /dev/null +++ b/etc/supervisor_available/cron.conf @@ -0,0 +1,8 @@ +[program:cron] +command = /app/bin/cron.py +numprocs = 1 +autostart = true +user = webdev +redirect_stderr = true +stdout_logfile = /dev/stdout +stdout_logfile_maxbytes = 0 diff --git a/etc/supervisor_enabled/.gitignore b/etc/supervisor_enabled/.gitignore new file mode 100644 index 00000000000..fee92170833 --- /dev/null +++ b/etc/supervisor_enabled/.gitignore @@ -0,0 +1 @@ +*.conf diff --git a/etc/supervisord.conf b/etc/supervisord.conf new file mode 100644 index 00000000000..a35bc458dd0 --- /dev/null +++ b/etc/supervisord.conf @@ -0,0 +1,5 @@ +[supervisord] +nodaemon = true + +[include] +files = supervisor_enabled/*.conf diff --git a/requirements/docker-dev.txt b/requirements/docker-dev.txt new file mode 100644 index 00000000000..ad89940f652 --- /dev/null +++ b/requirements/docker-dev.txt @@ -0,0 +1,5 @@ +supervisor==3.2.3 \ + --hash=sha256:3d6f0304c8ce74ab2100dfc4ab0f70050568504216f9508a81b8ed269aec9705 +meld3==1.0.2 \ + --hash=sha256:b28a9bfac342aadb4557aa144bea9f8e6208bfb0596190570d10a892d35ff7dc \ + --hash=sha256:f7b754a0fde7a4429b2ebe49409db240b5699385a572501bb0d5627d299f9558