Skip to content

Commit 8a253b2

Browse files
committed
build: update Dockerfile, Makefile, and .dockerignore for improved build process
- Refine Dockerfile for better multi-stage builds and environment setup - Update Makefile to streamline build and development commands - Adjust .dockerignore to optimize Docker context and image size
1 parent 476881e commit 8a253b2

3 files changed

Lines changed: 30 additions & 9 deletions

File tree

.dockerignore

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ __pycache__/
1616
.hypothesis/
1717
pip-log.txt
1818
pip-delete-this-directory.txt
19+
requirements.txt
1920

2021
# Editor directories and OS files
2122
.idea/
@@ -41,4 +42,13 @@ mkdocs.yml
4142

4243
# Project files you don't want in image
4344
LICENSE
44-
Makefile
45+
Makefile
46+
47+
# Github
48+
.devcontainer/
49+
.github/
50+
51+
# Docker files
52+
Dockerfile
53+
docker-compose.yml
54+
.dockerignore

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ COPY . /app
2121
RUN --mount=type=cache,target=/root/.cache/uv \
2222
uv sync --locked --no-dev
2323

24+
# Remove the uv lock file and pyproject.toml, so that the final image does not
25+
RUN rm -f pyproject.toml uv.lock .python-version
2426

2527
# Then, use a final image without uv
2628
FROM python:3.12-slim-bookworm
@@ -36,4 +38,4 @@ WORKDIR /app
3638
# Place executables in the environment at the front of the path
3739
ENV PATH="/app/.venv/bin:$PATH"
3840

39-
ENTRYPOINT ["/bin/sh", "./docker/docker-entrypoint.sh"]
41+
CMD ["/bin/sh", "./docker/docker-entrypoint.sh"]

Makefile

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
PROJECT_NAME = python-boilerplate
2+
CONTAINER_NAME = py-blplt
3+
d = docker
4+
dc = docker compose
25

36
run:
47
uv run __main__.py
@@ -16,25 +19,31 @@ typecheck:
1619
uv run mypy --config-file=pyproject.toml --explicit-package-bases ./src/
1720

1821
docker-build:
19-
docker build -t $(PROJECT_NAME) .
22+
$(d) build -t $(PROJECT_NAME) .
23+
24+
docker-bash:
25+
$(d) run --rm -it --env-file .env $(PROJECT_NAME) /bin/bash
2026

2127
docker-run:
22-
docker run --rm -it --env-file example.env $(PROJECT_NAME)
28+
$(d) run --rm -it --env-file .env $(PROJECT_NAME)
29+
30+
docker-logs:
31+
$(d) logs -f $(CONTAINER_NAME)
2332

2433
compose-build:
25-
docker compose up --build -d
34+
$(dc) up --build -d
2635

2736
compose-up:
28-
docker compose up -d
37+
$(dc) up -d
2938

3039
compose-stop:
31-
docker compose stop
40+
$(dc) stop
3241

3342
compose-down:
34-
docker compose down
43+
$(dc) down
3544

3645
clean:
3746
find . -type d -name '__pycache__' -exec rm -rf {} +
3847
rm -rf .mypy_cache .ruff_cache .pytest_cache
3948

40-
.PHONY: run test lint format typecheck check docker-build docker-run compose-build compose-up compose-stop compose-down clean
49+
.PHONY: run test lint format typecheck check docker-build docker-bash docker-run compose-build compose-up compose-stop compose-down clean

0 commit comments

Comments
 (0)