-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gunicorn): Updated image to use gunicorn and new base image (#209)
### Improvements - Update to use new Amazon Linux base image and use the same structure as our other python services. - Utilizing "gen3" user instead of "root" for more secure containers - Moving to Poetry to manage our virtual environments - Multi-stage Docker builds for smaller images - Move to Gunicorn --------- Co-authored-by: Edward Malinowski <[email protected]> Co-authored-by: Jawad Qureshi <[email protected]> Co-authored-by: EliseCastle23 <[email protected]> Co-authored-by: George Thomas <[email protected]>
- Loading branch information
1 parent
f64f5fc
commit 906dcd8
Showing
14 changed files
with
668 additions
and
753 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
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,63 +1,42 @@ | ||
# To run: | ||
# - Create and fill out `creds.json`: | ||
# { | ||
# "fence_host": "", | ||
# "fence_username": "", | ||
# "fence_password": "", | ||
# "fence_database": "", | ||
# "db_host": "", | ||
# "db_username": "", | ||
# "db_password": "", | ||
# "db_database": "", | ||
# "gdcapi_secret_key": "", | ||
# "hostname": "" | ||
# } | ||
# - Build the image: `docker build . -t peregrine -f Dockerfile` | ||
# - Run: `docker run -v /full/path/to/creds.json:/var/www/peregrine/creds.json -p 81:80 peregrines` | ||
# To check running container: `docker exec -it peregrine /bin/bash` | ||
|
||
FROM quay.io/cdis/python:python3.9-buster-2.0.0 | ||
ARG AZLINUX_BASE_VERSION=master | ||
|
||
FROM quay.io/cdis/python-nginx-al:${AZLINUX_BASE_VERSION} AS base | ||
|
||
ENV appname=peregrine | ||
|
||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
build-essential libffi-dev musl-dev gcc libxml2-dev libxslt-dev \ | ||
curl bash git vim | ||
RUN pip install --upgrade pip poetry | ||
WORKDIR /${appname} | ||
|
||
RUN chown -R gen3:gen3 /${appname} | ||
|
||
# Builder stage | ||
FROM base AS builder | ||
|
||
RUN dnf install -y python3-devel postgresql-devel gcc | ||
|
||
USER gen3 | ||
|
||
COPY poetry.lock pyproject.toml /${appname}/ | ||
|
||
RUN poetry install -vv --only main --no-interaction | ||
|
||
RUN mkdir -p /var/www/$appname \ | ||
&& mkdir -p /var/www/.cache/Python-Eggs/ \ | ||
&& mkdir /run/nginx/ \ | ||
&& ln -sf /dev/stdout /var/log/nginx/access.log \ | ||
&& ln -sf /dev/stderr /var/log/nginx/error.log \ | ||
&& chown nginx -R /var/www/.cache/Python-Eggs/ \ | ||
&& chown nginx /var/www/$appname | ||
COPY --chown=gen3:gen3 . /${appname} | ||
|
||
EXPOSE 80 | ||
# Run poetry again so this app itself gets installed too | ||
RUN poetry install --without dev --no-interaction | ||
|
||
WORKDIR /$appname | ||
RUN git config --global --add safe.directory /${appname} && COMMIT=`git rev-parse HEAD` && echo "COMMIT=\"${COMMIT}\"" > /${appname}/version_data.py \ | ||
&& VERSION=`git describe --always --tags` && echo "VERSION=\"${VERSION}\"" >> /${appname}/version_data.py | ||
|
||
# copy ONLY poetry artifact, install the dependencies but not indexd | ||
# this will make sure than the dependencies is cached | ||
COPY poetry.lock pyproject.toml /$appname/ | ||
RUN poetry config virtualenvs.create false \ | ||
&& poetry install -vv --no-root --no-dev --no-interaction \ | ||
&& poetry show -v | ||
# Final stage | ||
FROM base | ||
|
||
# copy source code ONLY after installing dependencies | ||
COPY . /$appname | ||
COPY ./deployment/uwsgi/uwsgi.ini /etc/uwsgi/uwsgi.ini | ||
COPY ./bin/settings.py /var/www/$appname/settings.py | ||
COPY ./bin/confighelper.py /var/www/$appname/confighelper.py | ||
RUN yum install -y postgresql-libs | ||
|
||
# install peregrine | ||
RUN poetry config virtualenvs.create false \ | ||
&& poetry install -vv --no-dev --no-interaction \ | ||
&& poetry show -v | ||
COPY --from=builder /${appname} /${appname} | ||
|
||
RUN COMMIT=`git rev-parse HEAD` && echo "COMMIT=\"${COMMIT}\"" >$appname/version_data.py \ | ||
&& VERSION=`git describe --always --tags` && echo "VERSION=\"${VERSION}\"" >>$appname/version_data.py | ||
# Switch to non-root user 'gen3' for the serving process | ||
USER gen3 | ||
|
||
WORKDIR /var/www/$appname | ||
WORKDIR /${appname} | ||
|
||
CMD /dockerrun.sh | ||
CMD ["/bin/bash", "-c", "/${appname}/dockerrun.bash"] |
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
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
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
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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
wsgi_app = "bin.settings:application" | ||
bind = "0.0.0.0:8000" | ||
workers = 1 | ||
user = "gen3" | ||
group = "gen3" | ||
timeout = 300 |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
nginx | ||
poetry run gunicorn -c /peregrine/deployment/wsgi/gunicorn.conf.py |
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
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
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
Oops, something went wrong.