Skip to content

Commit

Permalink
Dockerfile optimisations!
Browse files Browse the repository at this point in the history
  • Loading branch information
AiroPi committed Dec 5, 2023
1 parent 9b76e85 commit 6159773
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
27 changes: 21 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
FROM python:3.11.2 as base
FROM python:3.12.0-alpine as build
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
RUN --mount=type=cache,target=/var/cache/apk/ \
--mount=type=cache,target=/root/.cache/pip \
--mount=type=bind,source=requirements.txt,target=requirements.txt \
: \
&& apk add gcc musl-dev linux-headers \
&& pip install -U -r requirements.txt


FROM python:3.12.0-alpine as base
WORKDIR /app
COPY --from=build /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
ENV PYTHONUNBUFFERED=0
COPY requirements.txt alembic.ini ./
RUN pip install -U -r requirements.txt
COPY ./alembic.ini ./
COPY ./alembic ./alembic
COPY ./src ./


FROM base as prod
COPY ./src ./
CMD ["/bin/bash", "-c", "alembic upgrade head && python ./main.py bot --sync -c ./config.toml"]
CMD ["/bin/sh", "-c", "alembic upgrade head && python ./main.py bot --sync -c ./config.toml"]


FROM base as debug
ENV DEBUG=1
ENV LOG_LEVEL=DEBUG
RUN pip install debugpy
CMD ["/bin/bash", "-c", "alembic upgrade head && python -m debugpy --wait-for-client --listen 0.0.0.0:5678 ./src/main.py bot -c ./config.toml"]
CMD ["/bin/sh", "-c", "alembic upgrade head && python -m debugpy --wait-for-client --listen 0.0.0.0:5678 ./main.py bot -c ./config.toml"]
2 changes: 2 additions & 0 deletions bin/alembic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
docker compose --progress quiet up database -d --quiet-pull
docker compose --progress quiet run --rm -t -v "${PWD}/alembic:/app/alembic" mybot alembic "$@"
2 changes: 0 additions & 2 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ services:
build:
target: debug
restart: "no"
volumes:
- ./src:/app/src
ports:
- 5678:5678 # for debugging
- 8080:8080
Expand Down
8 changes: 6 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ services:
context: .
dockerfile: ./Dockerfile
target: prod
develop:
watch:
- action: sync
path: ./src
target: /app
env_file:
- .env
tty: true
Expand All @@ -15,8 +20,7 @@ services:
database:
condition: service_healthy
volumes:
- ./data/locale:/app/locale
- ./alembic:/app/alembic
- ./resources/locale:/app/locale
- ./config.toml:/app/config.toml
ports:
- 666:8081
Expand Down

0 comments on commit 6159773

Please sign in to comment.