Skip to content

Commit

Permalink
build: slim down the docker container (#60)
Browse files Browse the repository at this point in the history
Co-authored-by: Ushie <[email protected]>
  • Loading branch information
VitalyArt and Ushie authored Sep 26, 2023
1 parent 1cfc418 commit 80b858c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.idea
.devcontainer
.git
.gitignore
.github
.vscode
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 27 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
FROM python:3.11-slim
## 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"

ARG GITHUB_TOKEN
ENV GITHUB_TOKEN $GITHUB_TOKEN
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 change: 1 addition & 0 deletions docker/run-backend.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python3 -m sanic /usr/src/app --fast --access-logs --motd --noisy-exceptions -H 0.0.0.0
1 change: 1 addition & 0 deletions docker/run-healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --fail http://0.0.0.0:8000/docs

0 comments on commit 80b858c

Please sign in to comment.