build: slim down the docker container (#60)

Co-authored-by: Ushie <ushiekane@gmail.com>
This commit is contained in:
Vitaly Artemyev 2023-09-26 08:56:16 +05:00 committed by GitHub
parent 1cfc41879d
commit 80b858c578
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 9 deletions

6
.dockerignore Normal file
View File

@ -0,0 +1,6 @@
.idea
.devcontainer
.git
.gitignore
.github
.vscode

2
.gitignore vendored
View File

@ -157,7 +157,7 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/
# custom
env.sh

View File

@ -1,14 +1,34 @@
FROM python:3.11-slim
ARG GITHUB_TOKEN
ENV GITHUB_TOKEN $GITHUB_TOKEN
## Build dependencies
FROM python:3.11-slim as dependencies
WORKDIR /usr/src/app
RUN apt-get update && \
apt-get install -y --no-install-recommends gcc \
&& rm -rf /var/lib/apt/lists/*
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
COPY requirements.txt .
RUN pip install -r requirements.txt
## Image
FROM python:3.11-slim
WORKDIR /usr/src/app
RUN apt-get update && \
apt-get install -y --no-install-recommends curl \
&& rm -rf /var/lib/apt/lists/*
ENV PATH="/opt/venv/bin:$PATH"
COPY --from=dependencies /opt/venv /opt/venv
COPY . .
RUN apt update && \
apt-get install build-essential libffi-dev libssl-dev openssl --no-install-recommends -y \
&& pip install --no-cache-dir -r requirements.txt
CMD docker/run-backend.sh
HEALTHCHECK CMD docker/run-healthcheck.sh
CMD [ "python3", "-m" , "sanic", "app:app", "--fast", "--access-logs", "--motd", "--noisy-exceptions", "-H", "0.0.0.0"]
EXPOSE 8000

1
docker/run-backend.sh Executable file
View File

@ -0,0 +1 @@
python3 -m sanic /usr/src/app --fast --access-logs --motd --noisy-exceptions -H 0.0.0.0

1
docker/run-healthcheck.sh Executable file
View File

@ -0,0 +1 @@
curl --fail http://0.0.0.0:8000/docs