Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerfile optimizations! #112

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/generate-pot-file.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ jobs:

- name: commit
run: |
mv -f master/data/locale/mybot.pot translations/data/locale/mybot.pot
mv -f master/resources/locale/mybot.pot translations/resources/locale/mybot.pot
cd translations
git add ./data/locale/mybot.pot
git add ./resources/locale/mybot.pot
git commit -m "POT file generated"
git push origin auto/translations-source
26 changes: 20 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
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
COPY ./alembic.ini ./src ./
COPY ./alembic ./alembic
ENV PATH="/opt/venv/bin:$PATH"
ENV PYTHONUNBUFFERED=0
COPY requirements.txt alembic.ini ./
RUN pip install -U -r requirements.txt


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: 1 addition & 1 deletion bin/po-to-mo.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env bash
python3 ./bin/msgfmt.py ./data/locale/**/LC_MESSAGES/*.po
python3 ./bin/msgfmt.py ./resources/locale/**/LC_MESSAGES/*.po
2 changes: 1 addition & 1 deletion bin/pot-generation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ pybabel extract \
--project="MyBot" \
--version="1.0" \
-k "_ __" \
-o ./data/locale/mybot.pot \
-o ./resources/locale/mybot.pot \
./src/
4 changes: 2 additions & 2 deletions crowdin.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
files:
- source: /data/locale/*.pot
translation: /data/locale/%locale%/LC_MESSAGES/%file_name%.po
- source: /resources/locale/*.pot
translation: /resources/locale/%locale%/LC_MESSAGES/%file_name%.po
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
File renamed without changes.