diff --git a/Dockerfile b/Dockerfile index 9eb4cd09e1..2793c8198c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,34 +8,15 @@ ARG REQUIREMENTS_FILE_OVERWRITE="" WORKDIR /app ENV APP_CONTEXT=${CONTEXT} -### Query based on context value -RUN CONTEXT_INSTALLS=$(case "$APP_CONTEXT" in \ - tests) echo "make vim bash-completion";; \ - dev) echo "make vim bash-completion";; \ - *) echo "libc-dev" ;; esac) && \ - IGNORE_INSTALL_RECOMMENDS=${prod:+"--no-install-recommends"} && \ - apt-get -y update && apt-get -y upgrade && apt-get install ${IGNORE_INSTALL_RECOMMENDS} -y \ - curl \ - git \ - gcc \ - libpq-dev \ - libmagic1 \ - mime-support \ - ncat \ - ${CONTEXT_INSTALLS} && \ - rm -rf /var/lib/apt/lists/* - -### Requirements file will be autoselected, unless an overwrite is given via ARG REQUIEREMENTS_FILE_OVERWRITE +### Apt-get and pip requirements installs handled by dev/dockerfile-installs.sh COPY requirements/ requirements/ -RUN REQUIREMENTS_FILE=$(case "$APP_CONTEXT" in \ - tests) echo "requirements_development.txt";; \ - dev) echo "requirements_development.txt";; \ - *) echo "requirements_production.txt" ;; esac) && \ - REQUIREMENTS_FILE=${REQUIEREMENTS_FILE_OVERWRITE:-$REQUIREMENTS_FILE} && \ - . requirements/export_service_commits.sh && pip install --no-cache-dir --requirement requirements/${REQUIREMENTS_FILE} +COPY ./dev/dockerfile-installs.sh ./dockerfile-installs.sh +RUN chmod +x ./dockerfile-installs.sh && \ + bash ./dockerfile-installs.sh "${APP_CONTEXT}" "${REQUIREMENTS_FILE_OVERWRITE}" && \ + rm ./dockerfile-installs.sh +# Environment ENV PYTHONPATH=/app - ENV EMAIL_HOST=postfix ENV EMAIL_PORT=25 ENV EMAIL_CONNECTION_SECURITY=NONE diff --git a/dev/dockerfile-installs.sh b/dev/dockerfile-installs.sh new file mode 100644 index 0000000000..16fe64eacb --- /dev/null +++ b/dev/dockerfile-installs.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +set -e + +# There is high variance between different build targets for apt-get and pip. +# Writing these installs in Dockerfile is clunky and unreadable (e.g. inline switch cases) +# Moving these installs to this install-script causes significant reduction in clutter and +# a more understandable program process + +CONTEXT=${1-"prod"} +REQUIREMENTS_FILE_OVERWRITE=${2-""} + +# Derive variables from build target +if [ "$CONTEXT" = "dev" ] +then + CONTEXT_INSTALLS="make vim bash-completion" + REQUIREMENTS_FILE="requirements_development.txt" +elif [ "$CONTEXT" = "tests" ] +then + CONTEXT_INSTALLS="make vim bash-completion" + REQUIREMENTS_FILE="requirements_development.txt" +else + # Default is production target + CONTEXT_INSTALLS="libc-dev" + IGNORE_INSTALL_RECOMMENDS="--no-install-recommends" + REQUIREMENTS_FILE="requirements_production.txt" +fi + +if [ "$REQUIREMENTS_FILE_OVERWRITE" != "" ] +then + REQUIREMENTS_FILE="$REQUIREMENTS_FILE_OVERWRITE" +fi + +# Apt-get +apt-get -y update +apt-get -y upgrade +# shellcheck disable=SC2086 +apt-get install ${IGNORE_INSTALL_RECOMMENDS} -y \ + curl \ + git \ + gcc \ + libpq-dev \ + libmagic1 \ + mime-support \ + ncat \ + ${CONTEXT_INSTALLS} + +rm -rf /var/lib/apt/lists/* + +# Requirements +# shellcheck disable=SC1091 +. requirements/export_service_commits.sh +pip install --no-cache-dir --requirement requirements/"${REQUIREMENTS_FILE}"