#FROM python:3.10-alpine FROM docker.io/python:3.10-slim AS base ENV \ LANG=C.UTF-8 \ LC_ALL=C.UTF-8 \ # python: PYTHONFAULTHANDLER=1 \ PYTHONUNBUFFERED=1 \ PYTHONHASHSEED=random \ PYTHONDONTWRITEBYTECODE=1 RUN apt-get update RUN apt-get install -y --no-install-recommends libmagic-dev libglib2.0-dev libpango-1.0-0 libpangoft2-1.0-0 RUN apt-get update && \ apt-get install -y curl gnupg && \ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \ apt-get update && \ apt-get install -y yarn && \ apt-get install -y --no-install-recommends build-essential gcc && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* ENV VIRTUAL_ENV=/venv # Use production configuration. ENV DJANGO_SETTINGS_MODULE=publichealth.settings ENV DJANGO_CONFIGURATION=production ### builder image FROM base as build ENV \ # pip: PIP_NO_CACHE_DIR=off \ PIP_DISABLE_PIP_VERSION_CHECK=on \ PIP_DEFAULT_TIMEOUT=100 RUN python3 -m venv $VIRTUAL_ENV RUN mkdir -p /build/static WORKDIR /build # Install python dependencies. COPY requirements.txt requirements.txt ./ RUN . /venv/bin/activate && pip install -r requirements.txt # We will run dumb-init as pid 1. RUN . /venv/bin/activate && pip install dumb-init # We will run our app using gunicorn. RUN . /venv/bin/activate && pip install gunicorn # Copy local code into to the build image. COPY . /build # Copy code required for runtime to the /app folder. RUN mkdir -p /app RUN cp -r publichealth feedler yarn.lock manage.py package.json Gruntfile.js setup_libs.sh /app/ #RUN curl -fsSLO https://deb.nodesource.com/setup_18.x && chmod +x setup_18.x && ./setup_18.x #RUN apt install -y nodejs #RUN npm install -g grunt-cli # Collect static data into /app/static. #RUN . /venv/bin/activate && \ # DJANGO_STATIC_ROOT=/app/static SECRET_KEY=sl DJANGO_SETTINGS_MODULE=publichealth.settings.production ./manage.py collectstatic --no-input -i media #RUN mkdir -p /app/publichealth/static/libs #RUN cp -rf node_modules/@bower_components/* /app/publichealth/static/libs #RUN . /venv/bin/activate && \ # DJANGO_STATIC_ROOT=/app/static SECRET_KEY=sl DJANGO_SETTINGS_MODULE=publichealth.settings.production ./manage.py compress --force #RUN cp -r /build/static /app/static ### runtime image FROM base as runtime #RUN apt-get install -y --no-install-recommends libpango-1.0-0 libpangoft2-1.0-0 #RUN apt-get install -y --no-install-recommends procps iproute2 curl COPY --from=build /venv /venv COPY --from=build /app /app WORKDIR /app # Ensure exectutables from virtualenv are prefered. ENV PATH="/venv/bin:$PATH" ENTRYPOINT ["/venv/bin/dumb-init", "--", "gunicorn", \ "-b [::]:8000", \ "--log-file=-", \ "--worker-tmp-dir", "/dev/shm", \ "--workers=2", "--threads=4", "--worker-class=gthread"] CMD ["publichealth.wsgi"]