From 1090ed5a46123e4ef76ccee8c2cf17539603619b Mon Sep 17 00:00:00 2001 From: EliseCastle23 <109446148+EliseCastle23@users.noreply.github.com> Date: Thu, 24 Oct 2024 11:30:12 -0600 Subject: [PATCH] updating dockerfile to consolidate --- Dockerfile | 50 +++++-------------------------------- deployment/nginx/nginx.conf | 44 -------------------------------- dockerrun.bash | 2 +- 3 files changed, 7 insertions(+), 89 deletions(-) delete mode 100644 deployment/nginx/nginx.conf diff --git a/Dockerfile b/Dockerfile index 8c717f88..46274345 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,38 +1,24 @@ ARG AZLINUX_BASE_VERSION=master -# Base stage with python-build-base -FROM quay.io/cdis/python-build-base:${AZLINUX_BASE_VERSION} AS base +## For local development +# FROM quay.io/cdis/python-nginx-al2:feat_python-nginx 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-build-base:${AZLINUX_BASE_VERSION} as base +FROM 707767160287.dkr.ecr.us-east-1.amazonaws.com/gen3/python-nginx-al2:feat_python-nginx as base ENV appname=indexd -ENV POETRY_NO_INTERACTION=1 \ - POETRY_VIRTUALENVS_IN_PROJECT=1 \ - POETRY_VIRTUALENVS_CREATE=1 WORKDIR /${appname} -# create gen3 user -# Create a group 'gen3' with GID 1000 and a user 'gen3' with UID 1000 -RUN groupadd -g 1000 gen3 && \ - useradd -m -s /bin/bash -u 1000 -g gen3 gen3 && \ - chown -R gen3:gen3 /$appname && \ - chown -R gen3:gen3 /venv - +RUN chown -R gen3:gen3 /$appname # Builder stage FROM base AS builder USER gen3 - -RUN python -m venv /venv - COPY poetry.lock pyproject.toml /${appname}/ -RUN pip install --upgrade poetry && \ - poetry install -vv --only main --no-interaction +RUN poetry install -vv --only main --no-interaction COPY --chown=gen3:gen3 . /$appname COPY --chown=gen3:gen3 ./deployment/wsgi/wsgi.py /$appname/wsgi.py @@ -46,35 +32,11 @@ RUN git config --global --add safe.directory /${appname} && COMMIT=`git rev-pars # Final stage FROM base -COPY --from=builder /venv /venv COPY --from=builder /$appname /$appname -# Install nginx -RUN yum install nginx -y - -# allows nginx to run on port 80 without being root user -RUN setcap 'cap_net_bind_service=+ep' /usr/sbin/nginx - -# chown nginx directories -RUN chown -R gen3:gen3 /var/log/nginx - -# pipe nginx logs to stdout and stderr -RUN ln -sf /dev/stdout /var/log/nginx/access.log && ln -sf /dev/stderr /var/log/nginx/error.log - -# create /var/lib/nginx/tmp/client_body to allow nginx to write to indexd -RUN mkdir -p /var/lib/nginx/tmp/client_body -RUN chown -R gen3:gen3 /var/lib/nginx/ - -# copy nginx config -COPY ./deployment/nginx/nginx.conf /etc/nginx/nginx.conf - - # Switch to non-root user 'gen3' for the serving process USER gen3 -RUN source /venv/bin/activate - -ENV PYTHONUNBUFFERED=1 \ - PYTHONIOENCODING=UTF-8 +WORKDIR /$appname CMD ["/bin/bash", "-c", "/indexd/dockerrun.bash"] diff --git a/deployment/nginx/nginx.conf b/deployment/nginx/nginx.conf deleted file mode 100644 index c64485a9..00000000 --- a/deployment/nginx/nginx.conf +++ /dev/null @@ -1,44 +0,0 @@ -user gen3; -worker_processes auto; -error_log /var/log/nginx/error.log notice; -pid /var/lib/nginx/nginx.pid; - -# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. -include /usr/share/nginx/modules/*.conf; - -events { - worker_connections 1024; -} - -http { - log_format main '$remote_addr - $remote_user [$time_local] "$request" ' - '$status $body_bytes_sent "$http_referer" ' - '"$http_user_agent" "$http_x_forwarded_for"'; - - access_log /var/log/nginx/access.log main; - - sendfile on; - tcp_nopush on; - keepalive_timeout 65; - types_hash_max_size 4096; - - include /etc/nginx/mime.types; - default_type application/octet-stream; - - # Load modular configuration files from the /etc/nginx/conf.d directory. - # See http://nginx.org/en/docs/ngx_core_module.html#include - # for more information. - include /etc/nginx/conf.d/*.conf; - - server { - - listen 80; - server_name localhost; - - location / { - proxy_pass http://127.0.0.1:8000; - proxy_set_header Host $host; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - } - } -} diff --git a/dockerrun.bash b/dockerrun.bash index 8b14b2bb..ea022df9 100755 --- a/dockerrun.bash +++ b/dockerrun.bash @@ -1,4 +1,4 @@ #!/bin/bash - +source .venv/bin/activate nginx gunicorn -c "/indexd/deployment/wsgi/gunicorn.conf.py"