-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a81ee3
commit 250166e
Showing
3 changed files
with
72 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 57 additions & 61 deletions
118
cookiecutter-django-ida/{{cookiecutter.repo_name}}/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,81 @@ | ||
FROM ubuntu:focal as app | ||
MAINTAINER [email protected] | ||
|
||
ENV DEBIAN_FRONTEND noninteractive | ||
# System requirements. | ||
RUN apt update && \ | ||
apt-get install -qy \ | ||
curl \ | ||
gettext \ | ||
# required by bower installer | ||
git \ | ||
language-pack-en \ | ||
build-essential \ | ||
python3.8-dev \ | ||
python3-virtualenv \ | ||
python3.8-distutils \ | ||
libmysqlclient-dev \ | ||
libssl-dev \ | ||
# mysqlclient >= 2.2.0 requires pkg-config. | ||
pkg-config \ | ||
libcairo2-dev && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# Use UTF-8. | ||
RUN locale-gen en_US.UTF-8 | ||
ENV LANG en_US.UTF-8 | ||
ENV LANGUAGE en_US:en | ||
ENV LC_ALL en_US.UTF-8 | ||
|
||
ARG COMMON_APP_DIR="/edx/app" | ||
ARG COMMON_CFG_DIR="/edx/etc" | ||
ARG COOKIECUTTER_SERVICE_NAME={{cookiecutter.repo_name}} | ||
ARG COOKIECUTTER_PROJECT_NAME={{cookiecutter.project_name}} | ||
ARG COOKIECUTTER_APP_DIR="${COMMON_APP_DIR}/${COOKIECUTTER_SERVICE_NAME}" | ||
ARG COOKIECUTTER_VENV_DIR="${COMMON_APP_DIR}/${COOKIECUTTER_SERVICE_NAME}/venvs/${COOKIECUTTER_SERVICE_NAME}" | ||
ARG COOKIECUTTER_CODE_DIR="${COOKIECUTTER_APP_DIR}/${COOKIECUTTER_PROJECT_NAME}" | ||
ARG COOKIECUTTER_NODEENV_DIR="${COOKIECUTTER_APP_DIR}/nodeenvs/${COOKIECUTTER_SERVICE_NAME}" | ||
# Packages installed: | ||
|
||
# language-pack-en locales; ubuntu locale support so that system utilities have a consistent | ||
# language and time zone. | ||
|
||
ENV PATH "${COOKIECUTTER_VENV_DIR}/bin:${COOKIECUTTER_NODEENV_DIR}/bin:$PATH" | ||
ENV COOKIECUTTER_CFG "/edx/etc/${COOKIECUTTER_SERVICE_NAME}.yml" | ||
ENV COOKIECUTTER_CODE_DIR "${COOKIECUTTER_CODE_DIR}" | ||
ENV COOKIECUTTER_APP_DIR "${COOKIECUTTER_APP_DIR}" | ||
# python; ubuntu doesnt ship with python, so this is the python we will use to run the application | ||
|
||
RUN virtualenv -p python3.8 --always-copy ${COOKIECUTTER_VENV_DIR} | ||
# python3-pip; install pip to install application requirements.txt files | ||
|
||
# No need to activate IDA venv as it is already in path | ||
RUN pip install nodeenv | ||
# libmysqlclient-dev; to install header files needed to use native C implementation for | ||
# MySQL-python for performance gains. | ||
|
||
RUN nodeenv ${COOKIECUTTER_NODEENV_DIR} --node=16.14.0 --prebuilt && npm install -g [email protected] | ||
# libssl-dev; # mysqlclient wont install without this. | ||
|
||
# Working directory will be root of repo. | ||
WORKDIR ${COOKIECUTTER_CODE_DIR} | ||
# python3-dev; to install header files for python extensions; much wheel-building depends on this | ||
|
||
# Copy over repository | ||
COPY . . | ||
# gcc; for compiling python extensions distributed with python packages like mysql-client | ||
|
||
RUN npm install --production && ./node_modules/.bin/bower install --allow-root --production && ./node_modules/.bin/webpack --config webpack.config.js --progress | ||
# If you add a package here please include a comment above describing what it is used for | ||
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -qy install --no-install-recommends \ | ||
language-pack-en locales \ | ||
python3.8 python3-dev python3-pip \ | ||
# The mysqlclient Python package has install-time dependencies | ||
libmysqlclient-dev libssl-dev pkg-config \ | ||
gcc | ||
|
||
|
||
RUN pip install --upgrade pip setuptools | ||
# delete apt package lists because we do not need them inflating our image | ||
RUN rm -rf /var/lib/apt/lists/* | ||
|
||
RUN ln -s /usr/bin/python3 /usr/bin/python | ||
|
||
RUN locale-gen en_US.UTF-8 | ||
ENV LANG en_US.UTF-8 | ||
ENV LANGUAGE en_US:en | ||
ENV LC_ALL en_US.UTF-8 | ||
|
||
# Expose canonical Cookie Cutter port | ||
EXPOSE {{cookiecutter.port}} | ||
RUN useradd -m --shell /bin/false app | ||
|
||
WORKDIR /edx/app/{{cookiecutter.repo_name}} | ||
|
||
FROM app as prod | ||
|
||
ENV DJANGO_SETTINGS_MODULE "${COOKIECUTTER_SERVICE_NAME}.settings.production" | ||
ENV DJANGO_SETTINGS_MODULE {{cookiecutter.project_name}}.settings.production | ||
|
||
# Copy the requirements explicitly even though we copy everything below | ||
# this prevents the image cache from busting unless the dependencies have changed. | ||
COPY requirements/production.txt /edx/app/{{cookiecutter.repo_name}}/requirements/production.txt | ||
|
||
RUN pip install -r ${COOKIECUTTER_CODE_DIR}/requirements/production.txt | ||
# Dependencies are installed as root so they cannot be modified by the application user. | ||
RUN pip install -r requirements/production.txt | ||
|
||
CMD gunicorn --bind=0.0.0.0:{{cookiecutter.port}} --workers 2 --max-requests=1000 -c ${COOKIECUTTER_CODE_DIR}/docker_gunicorn_configuration.py ${COOKIECUTTER_PROJECT_NAME}.wsgi:application | ||
RUN mkdir -p /edx/var/log | ||
|
||
# Code is owned by root so it cannot be modified by the application user. | ||
# So we copy it before changing users. | ||
USER app | ||
|
||
# Gunicorn 19 does not log to stdout or stderr by default. Once we are past gunicorn 19, the logging to STDOUT need not be specified. | ||
CMD gunicorn --workers=2 --name {{cookiecutter.repo_name}} -c /edx/app/{{cookiecutter.repo_name}}/{{cookiecutter.project_name}}/docker_gunicorn_configuration.py --log-file - --max-requests=1000 {{cookiecutter.project_name}}.wsgi:application | ||
|
||
# This line is after the requirements so that changes to the code will not | ||
# bust the image cache | ||
COPY . /edx/app/{{cookiecutter.repo_name}} | ||
|
||
FROM app as dev | ||
|
||
ENV DJANGO_SETTINGS_MODULE "${COOKIECUTTER_SERVICE_NAME}.settings.devstack" | ||
ENV DJANGO_SETTINGS_MODULE {{cookiecutter.project_name}}.settings.devstack | ||
|
||
RUN pip install -r ${COOKIECUTTER_CODE_DIR}/requirements/django.txt | ||
RUN pip install -r ${COOKIECUTTER_CODE_DIR}/requirements/local.txt | ||
RUN pip install -r requirements/dev.txt | ||
|
||
# Devstack related step for backwards compatibility | ||
RUN touch ${COOKIECUTTER_APP_DIR}/${COOKIECUTTER_SERVICE_NAME}_env | ||
|
||
CMD while true; do python ./manage.py runserver 0.0.0.0:{{cookiecutter.port}}; sleep 2; done | ||
RUN touch {{cookiecutter.project_name}}/{{cookiecutter.project_name}}_env | ||
|
||
########################################################### | ||
# Define k8s target | ||
FROM prod as kubernetes | ||
ENV COOKIECUTTER_SETTINGS='kubernetes' | ||
ENV DJANGO_SETTINGS_MODULE="${COOKIECUTTER_SERVICE_NAME}.settings.$COOKIECUTTER_SETTINGS" | ||
CMD while true; do python ./manage.py runserver 0.0.0.0:{{cookiecutter.port}}; sleep 2; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters