-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docker Image Change to Amazon Linux (#1207)
* 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: Jawad Qureshi <qureshi@uchicago.edu> Co-authored-by: EliseCastle23 <109446148+EliseCastle23@users.noreply.github.com> Co-authored-by: Alexander VanTol <avantol@uchicago.edu> Co-authored-by: Alexander VanTol <Avantol13@users.noreply.github.com> Co-authored-by: Sai Shanmukha <nss10@outlook.com> Co-authored-by: J. Q. <55899496+jawadqur@users.noreply.github.com>
- Loading branch information
1 parent
7dcce30
commit b2fa0ae
Showing
16 changed files
with
425 additions
and
398 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
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,56 +1,63 @@ | ||
# To run: docker run --rm -d -v /path/to/fence-config.yaml:/var/www/fence/fence-config.yaml --name=fence -p 80:80 fence | ||
# To check running container do: docker exec -it fence /bin/bash | ||
# To build: docker build -t fence:latest . | ||
# To run interactive: | ||
# docker run -v ~/.gen3/fence/fence-config.yaml:/var/www/fence/fence-config.yaml -v ./keys/:/fence/keys/ fence:latest | ||
# To check running container do: docker exec -it CONTAINER bash | ||
|
||
FROM quay.io/cdis/python:python3.9-buster-2.0.0 | ||
ARG AZLINUX_BASE_VERSION=master | ||
|
||
# ------ Base stage ------ | ||
FROM quay.io/cdis/python-nginx-al:${AZLINUX_BASE_VERSION} AS base | ||
|
||
# Comment this in, and comment out the line above, if quay is down | ||
# FROM 707767160287.dkr.ecr.us-east-1.amazonaws.com/gen3/python-nginx-al:${AZLINUX_BASE_VERSION} as base | ||
|
||
ENV appname=fence | ||
|
||
RUN pip install --upgrade pip | ||
RUN pip install --upgrade poetry | ||
RUN apt-get update \ | ||
&& apt-get install -y --no-install-recommends curl bash git \ | ||
&& apt-get -y install vim \ | ||
libmcrypt4 mcrypt \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/ | ||
|
||
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 | ||
|
||
# aws cli v2 - needed for storing files in s3 during usersync k8s job | ||
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \ | ||
&& unzip awscliv2.zip \ | ||
&& ./aws/install \ | ||
&& /bin/rm -rf awscliv2.zip ./aws | ||
|
||
WORKDIR /$appname | ||
|
||
# copy ONLY poetry artifact, install the dependencies but not fence | ||
# 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 --without dev --no-interaction \ | ||
&& poetry show -v | ||
|
||
# copy source code ONLY after installing dependencies | ||
COPY . /$appname | ||
COPY ./deployment/uwsgi/uwsgi.ini /etc/uwsgi/uwsgi.ini | ||
COPY ./deployment/uwsgi/wsgi.py /$appname/wsgi.py | ||
COPY clear_prometheus_multiproc /$appname/clear_prometheus_multiproc | ||
|
||
# install fence | ||
RUN poetry config virtualenvs.create false \ | ||
&& poetry install -vv --without dev --no-interaction \ | ||
&& poetry show -v | ||
|
||
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 | ||
|
||
WORKDIR /var/www/$appname | ||
|
||
CMD ["sh","-c","bash /fence/dockerrun.bash && /dockerrun.sh"] | ||
WORKDIR /${appname} | ||
|
||
RUN chown -R gen3:gen3 /${appname} | ||
|
||
# ------ Builder stage ------ | ||
FROM base AS builder | ||
|
||
# Install just the deps without the code as it's own step to avoid redoing this on code changes | ||
COPY poetry.lock pyproject.toml /${appname}/ | ||
RUN poetry lock -vv --no-update \ | ||
&& poetry install -vv --only main --no-interaction | ||
|
||
# Move app files into working directory | ||
COPY --chown=gen3:gen3 . /$appname | ||
COPY --chown=gen3:gen3 ./deployment/wsgi/wsgi.py /$appname/wsgi.py | ||
|
||
# Do the install again incase the app itself needs install | ||
RUN poetry lock -vv --no-update \ | ||
&& poetry install -vv --only main --no-interaction | ||
|
||
# Setup version info | ||
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 | ||
|
||
|
||
|
||
# ------ Final stage ------ | ||
FROM base | ||
|
||
ENV PATH="/${appname}/.venv/bin:$PATH" | ||
|
||
# Install ccrypt to decrypt dbgap telmetry files | ||
RUN echo "Upgrading dnf"; \ | ||
dnf upgrade -y; \ | ||
echo "Installing Packages"; \ | ||
dnf install -y \ | ||
libxcrypt-compat-4.4.33 \ | ||
libpq-15.0 \ | ||
gcc \ | ||
tar xz; \ | ||
echo "Installing RPM"; \ | ||
rpm -i https://ccrypt.sourceforge.net/download/1.11/ccrypt-1.11-1.src.rpm && \ | ||
cd /root/rpmbuild/SOURCES/ && \ | ||
tar -zxf ccrypt-1.11.tar.gz && cd ccrypt-1.11 && ./configure --disable-libcrypt && make install && make check; | ||
|
||
COPY --chown=gen3:gen3 --from=builder /$appname /$appname | ||
|
||
CMD ["/bin/bash", "-c", "/fence/dockerrun.bash"] |
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,9 @@ | ||
wsgi_app = "deployment.wsgi.wsgi:application" | ||
bind = "0.0.0.0:8000" | ||
workers = 1 | ||
preload_app = True | ||
user = "root" | ||
group = "root" | ||
timeout = 300 | ||
keepalive = 2 | ||
keepalive_timeout = 5 |
File renamed without changes.
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
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.