backend: avoid redundant steps in Dockerfile
Use separate `base`, `setup` and `final` to avoid redundat steps. Avoid runnig `poetry` twice, and add `source` and `description`. Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
af5374fa04
commit
878f61ec49
|
@ -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"]
|
||||
|
|
Loading…
Reference in New Issue