Merge pull request #115 from sartography/backend/improve-dockerfile

backend: avoid redundant steps in Dockerfile
This commit is contained in:
Dan Funk 2023-01-30 17:02:35 -05:00 committed by GitHub
commit 53fc687a54
1 changed files with 25 additions and 18 deletions

View File

@ -1,28 +1,35 @@
FROM ghcr.io/sartography/python:3.11
# Base image to share ENV vars that activate VENV.
FROM ghcr.io/sartography/python:3.11 AS base
ENV VIRTUAL_ENV=/app/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
WORKDIR /app
# Setup image for installing Python dependencies.
FROM base AS setup
RUN pip install poetry
RUN useradd _gunicorn --no-create-home --user-group
RUN apt-get update && \
apt-get install -y -q \
gcc libssl-dev \
curl git-core libpq-dev \
gunicorn3 default-mysql-client
RUN apt-get update \
&& apt-get install -y -q gcc libssl-dev libpq-dev
WORKDIR /app
COPY pyproject.toml poetry.lock /app/
COPY . /app
RUN poetry install --without dev
RUN set -xe \
&& apt-get remove -y gcc python3-dev libssl-dev \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
# Final image without setup dependencies.
FROM base AS final
COPY . /app/
LABEL source="https://github.com/sartography/spiff-arena"
LABEL description="Software development platform for building, running, and monitoring executable diagrams"
# run poetry install again AFTER copying the app into the image
# otherwise it does not know what the main app module is
RUN poetry install --without dev
RUN apt-get update \
&& apt-get clean -y \
&& apt-get install -y -q curl git-core gunicorn3 default-mysql-client \
&& rm -rf /var/lib/apt/lists/*
CMD ./bin/boot_server_in_docker
COPY --from=setup /app /app
ENTRYPOINT ["./bin/boot_server_in_docker"]