2023-01-30 16:18:17 +01:00
# Base image to share ENV vars that activate VENV.
2024-01-29 14:09:36 -05:00
FROM python:3.12.1-slim-bookworm AS base
2023-01-30 16:18:17 +01:00
ENV VIRTUAL_ENV = /app/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH = " $VIRTUAL_ENV /bin: $PATH "
WORKDIR /app
2023-11-16 07:18:11 -08:00
######################## - DEPLOYMENT
2023-01-31 16:14:22 -05:00
# base plus packages needed for deployment. Could just install these in final, but then we can't cache as much.
2023-02-22 15:16:13 -05:00
# vim is just for debugging
2023-01-31 16:14:22 -05:00
FROM base AS deployment
2023-10-19 14:22:52 -04:00
# git-core because the app does "git commit", etc
# curl because the docker health check uses it
2023-11-16 07:18:11 -08:00
# procps because it is useful for debugging
2023-10-19 14:22:52 -04:00
# gunicorn3 for web server
# default-mysql-client for convenience accessing mysql docker container
# vim ftw
2024-05-03 13:50:42 -04:00
# jq because it is really useful, even for scenarios where people might have environment variables with json values they might need to use for configs. about 1MB.
2024-07-14 20:31:39 +00:00
# libpq5 in order to be able to use postgres at runtime
2023-01-31 16:14:22 -05:00
RUN apt-get update \
2024-05-03 13:50:42 -04:00
&& apt-get clean -y \
2024-07-16 21:12:46 -04:00
&& apt-get install -y -q git-core curl procps gunicorn3 default-mysql-client vim-tiny jq libpq5 \
2024-05-03 13:50:42 -04:00
&& rm -rf /var/lib/apt/lists/*
2023-01-31 16:14:22 -05:00
2023-12-08 13:32:49 -05:00
# keep pip up to date
RUN pip install --upgrade pip
2024-02-28 09:49:45 -05:00
RUN pip install poetry = = 1.8.1
2023-10-19 14:22:52 -04:00
2024-10-01 04:52:22 -07:00
# Avoid host:container file ownership issues
2024-10-01 08:43:30 -04:00
RUN git config --global --add safe.directory '*'
2024-10-01 04:52:22 -07:00
2023-11-16 07:18:11 -08:00
######################## - SETUP
2023-01-30 16:18:17 +01:00
# Setup image for installing Python dependencies.
FROM base AS setup
2022-10-12 10:22:22 -04:00
2023-03-06 16:16:55 -05:00
# poetry 1.4 seems to cause an issue where it errors with
# This error originates from the build backend, and is likely not a
# problem with poetry but with lazy-object-proxy (1.7.1) not supporting PEP 517 builds.
# You can verify this by running 'pip wheel --use-pep517 "lazy-object-proxy (==1.7.1) ; python_version >= "3.6""'.
# Pinnning to 1.3.2 to attempt to avoid it.
2023-10-19 14:22:52 -04:00
RUN pip install poetry = = 1.6.1
2022-10-12 10:22:22 -04:00
RUN useradd _gunicorn --no-create-home --user-group
2023-07-12 10:14:49 -04:00
# default-libmysqlclient-dev for mysqlclient lib
2024-07-14 20:31:39 +00:00
# libpq-dev in order to be able to poetry install postgres lib, psycopg2. See also libpq5 above in deployment image.
2023-01-30 16:18:17 +01:00
RUN apt-get update \
2024-05-03 13:50:42 -04:00
&& apt-get install -y -q gcc libssl-dev libpq-dev default-libmysqlclient-dev pkg-config libffi-dev
2022-10-12 10:22:22 -04:00
2023-02-01 07:53:35 -05:00
# poetry install takes a long time and can be cached if dependencies don't change,
# so that's why we tolerate running it twice.
COPY pyproject.toml poetry.lock /app/
RUN poetry install --without dev
2023-01-30 16:18:17 +01:00
COPY . /app
2022-11-09 15:45:49 -05:00
RUN poetry install --without dev
2022-10-12 10:22:22 -04:00
2023-11-16 07:18:11 -08:00
######################## - FINAL
2023-01-30 16:18:17 +01:00
# Final image without setup dependencies.
2023-01-31 16:14:22 -05:00
FROM deployment AS final
2022-10-12 10:22:22 -04:00
2023-11-20 16:49:30 -05:00
LABEL source = "https://github.com/sartography/spiff-arena/spiffworkflow-backend"
2023-05-13 19:53:50 -04:00
LABEL description = "Backend component of SpiffWorkflow, a software development platform for building, running, and monitoring executable diagrams"
2022-10-12 10:22:22 -04:00
2023-01-30 16:18:17 +01:00
COPY --from= setup /app /app
2023-01-31 16:14:22 -05:00
CMD [ "./bin/boot_server_in_docker" ]