|
| 1 | +# Fourfront (Production) Dockerfile |
| 2 | +# Based off of the cgap-portal Dockerfile |
| 3 | +# Note that images are pinned via sha256 as opposed to tag |
| 4 | +# so that we don't pick up new images unintentionally |
| 5 | + |
| 6 | +# Debian Buster with Python 3.6.15 |
| 7 | +# Note image is updated from cgap-portal |
| 8 | +FROM python:3.6.15-slim-buster |
| 9 | + |
| 10 | +MAINTAINER William Ronchetti "william_ronchetti@hms.harvard.edu" |
| 11 | + |
| 12 | +# Build Arguments |
| 13 | +ARG INI_BASE |
| 14 | +ENV INI_BASE=${INI_BASE:-"fourfront_any_alpha.ini"} |
| 15 | + |
| 16 | +# Configure (global) Env |
| 17 | +ENV NGINX_USER=nginx |
| 18 | +ENV DEBIAN_FRONTEND=noninteractive |
| 19 | +ENV CRYPTOGRAPHY_DONT_BUILD_RUST=1 |
| 20 | +ENV PYTHONFAULTHANDLER=1 \ |
| 21 | + PYTHONUNBUFFERED=1 \ |
| 22 | + PYTHONHASHSEED=random \ |
| 23 | + PIP_NO_CACHE_DIR=off \ |
| 24 | + PIP_DISABLE_PIP_VERSION_CHECK=on \ |
| 25 | + PIP_DEFAULT_TIMEOUT=100 \ |
| 26 | + POETRY_VERSION=1.1.12 \ |
| 27 | + NODE_VERSION=12.22.9 |
| 28 | + |
| 29 | +# Install nginx, base system |
| 30 | +COPY deploy/docker/production/install_nginx.sh / |
| 31 | +RUN bash /install_nginx.sh && \ |
| 32 | + apt-get update && \ |
| 33 | + apt-get install -y curl vim emacs postgresql-client net-tools ca-certificates \ |
| 34 | + gcc zlib1g-dev libpq-dev git make |
| 35 | + |
| 36 | +# Configure Fourfront User (nginx) |
| 37 | +WORKDIR /home/nginx/.nvm |
| 38 | + |
| 39 | +# Install Node |
| 40 | +ENV NVM_DIR=/home/nginx/.nvm |
| 41 | +RUN apt install -y curl |
| 42 | +RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash |
| 43 | +RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION} |
| 44 | +RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION} |
| 45 | +RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION} |
| 46 | +ENV PATH="/home/nginx/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}" |
| 47 | +RUN node --version |
| 48 | +RUN npm --version |
| 49 | + |
| 50 | +WORKDIR /home/nginx |
| 51 | + |
| 52 | +# Configure venv |
| 53 | +ENV VIRTUAL_ENV=/opt/venv |
| 54 | +RUN python -m venv /opt/venv |
| 55 | +ENV PATH="$VIRTUAL_ENV/bin:$PATH" |
| 56 | + |
| 57 | +# Upgrade pip, install in layer |
| 58 | +RUN pip install --upgrade pip && \ |
| 59 | + pip install poetry==$POETRY_VERSION |
| 60 | + |
| 61 | +# Adjust permissions |
| 62 | +RUN chown -R nginx:nginx /opt/venv && \ |
| 63 | + mkdir -p /home/nginx/fourfront |
| 64 | + |
| 65 | +WORKDIR /home/nginx/fourfront |
| 66 | + |
| 67 | +# Do the back-end dependency install |
| 68 | +COPY pyproject.toml . |
| 69 | +COPY poetry.lock . |
| 70 | +RUN poetry install --no-root |
| 71 | + |
| 72 | +# Do the front-end dependency install |
| 73 | +COPY package.json . |
| 74 | +COPY package-lock.json . |
| 75 | +RUN npm ci --no-fund --no-progress --no-optional --no-audit --python=/opt/venv/bin/python |
| 76 | + |
| 77 | +# Build front-end |
| 78 | +# XXX: this fails but might be able to be made to succeed? - Will Oct 7 2021 |
| 79 | +# COPY *.js . |
| 80 | +# COPY src/encoded/static . |
| 81 | +# RUN npm run build && \ |
| 82 | + # npm run build-scss |
| 83 | + |
| 84 | +# Copy over the rest of the code |
| 85 | +COPY . . |
| 86 | + |
| 87 | +# Build front-end, remove node_modules when done |
| 88 | +RUN npm run build && \ |
| 89 | + npm run build-scss && \ |
| 90 | + rm -rf node_modules/ |
| 91 | + |
| 92 | +# Build remaining back-end |
| 93 | +RUN poetry install && \ |
| 94 | + python setup_eb.py develop && \ |
| 95 | + make fix-dist-info |
| 96 | + |
| 97 | +# Misc |
| 98 | +RUN make aws-ip-ranges && \ |
| 99 | + cat /dev/urandom | head -c 256 | base64 > session-secret.b64 |
| 100 | + |
| 101 | +# Copy config files in (down here for quick debugging) |
| 102 | +# Remove default configuration from Nginx |
| 103 | +RUN rm /etc/nginx/nginx.conf && \ |
| 104 | + rm /etc/nginx/conf.d/default.conf |
| 105 | +COPY deploy/docker/production/nginx.conf /etc/nginx/nginx.conf |
| 106 | + |
| 107 | +# nginx filesystem setup |
| 108 | +RUN chown -R nginx:nginx /var/cache/nginx && \ |
| 109 | + chown -R nginx:nginx /var/log/nginx && \ |
| 110 | + chown -R nginx:nginx /etc/nginx/conf.d && \ |
| 111 | + touch /var/run/nginx.pid && \ |
| 112 | + chown -R nginx:nginx /var/run/nginx.pid && \ |
| 113 | + rm -f /var/log/nginx/* && \ |
| 114 | + touch /var/log/nginx/access.log && \ |
| 115 | + chown -R nginx:nginx /var/log/nginx/access.log && \ |
| 116 | + touch /var/log/nginx/error.log && \ |
| 117 | + chown -R nginx:nginx /var/log/nginx/error.log && \ |
| 118 | + mkdir -p /data/nginx/cache && \ |
| 119 | + chown -R nginx:nginx /data/nginx/cache |
| 120 | + |
| 121 | +# Pull all required files |
| 122 | +# Note that *.ini must match the env name in secrets manager! |
| 123 | +# Note that deploy/docker/production/entrypoint.sh resolves which entrypoint to run |
| 124 | +# based on env variable "application_type". |
| 125 | +COPY deploy/docker/local/docker_development.ini development.ini |
| 126 | +COPY deploy/docker/local/entrypoint.bash entrypoint_local.bash |
| 127 | +RUN chown nginx:nginx development.ini |
| 128 | +RUN chmod +x entrypoint_local.bash |
| 129 | + |
| 130 | +# Production setup |
| 131 | +RUN touch production.ini |
| 132 | +RUN chown nginx:nginx production.ini |
| 133 | +COPY deploy/docker/production/$INI_BASE deploy/ini_files/. |
| 134 | +COPY deploy/docker/production/entrypoint.bash . |
| 135 | +COPY deploy/docker/production/entrypoint_portal.bash . |
| 136 | +COPY deploy/docker/production/entrypoint_deployment.bash . |
| 137 | +COPY deploy/docker/production/entrypoint_indexer.bash . |
| 138 | +# Note that fourfront does not have an ingester |
| 139 | +# COPY deploy/docker/production/entrypoint_ingester.sh . |
| 140 | +COPY deploy/docker/production/assume_identity.py . |
| 141 | +RUN chmod +x entrypoint.bash |
| 142 | +RUN chmod +x entrypoint_deployment.bash |
| 143 | +RUN chmod +x entrypoint_deployment.bash |
| 144 | +RUN chmod +x entrypoint_indexer.bash |
| 145 | +RUN chmod +x assume_identity.py |
| 146 | +EXPOSE 8000 |
| 147 | + |
| 148 | +# Container does not run as root |
| 149 | +USER nginx |
| 150 | + |
| 151 | +ENTRYPOINT ["/home/nginx/fourfront/entrypoint.bash"] |
0 commit comments