Skip to content

Commit df465cb

Browse files
committed
add Dockerfile__uv
1 parent 078e4b6 commit df465cb

File tree

4 files changed

+66
-26
lines changed

4 files changed

+66
-26
lines changed
Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
1+
# IDE / Editor config
12
.git
2-
.idea
3-
.vscode
4-
build
5-
dist
6-
*.egg-info
7-
venv*
8-
.venv
9-
.cache
3+
.idea/
4+
.vscode/
5+
6+
# Python build artifacts
7+
build/
8+
dist/
9+
*.egg-info/
10+
.eggs/
11+
pip-wheel-metadata/
12+
13+
# Virtual environments
14+
.venv/
15+
venv*/
16+
env*/
17+
18+
# Python cache
19+
__pycache__/
20+
*.py[cod]
21+
*.so
1022
.pytest_cache/
11-
**/__pycache__
23+
.cache/
24+
htmlcov/
25+
26+
# Docker-specific
1227
Dockerfile
13-
htmlcov
28+
docker-compose.yml
29+
30+
# Jupyter
31+
.ipynb_checkpoints/
32+
33+
# Logs and misc
34+
*.log
35+
*.tmp
36+
*.bak
37+
*.swp
Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
1-
ARG PYTHON_VERSION=3.11
2-
FROM python:${PYTHON_VERSION}-bullseye
3-
LABEL maintainer="{{ cookiecutter.company_name if cookiecutter.company_name else cookiecutter.full_name }}"
1+
FROM ghcr.io/astral-sh/uv:python3.11-bookworm AS builder
42

5-
# Install uv package manager
6-
RUN pip install uv
3+
LABEL maintainer="{{ cookiecutter.company_name if cookiecutter.company_name else cookiecutter.full_name }}"
74

85
WORKDIR /app
96

10-
# Copy uv configuration files (uv.toml and optional uv.lock if present)
11-
COPY uv.toml uv.lock* ./
7+
COPY pyproject.toml uv.lock* ./
128

13-
# Install project dependencies using uv
14-
RUN uv install --no-interaction && uv cache clear
9+
RUN uv sync --frozen --no-install-project && uv cache clean
1510

16-
# Copy the project source code
1711
COPY ./src /app/src
1812

19-
# Install the project package (similar to installing only the root package)
20-
RUN uv install --only-root
13+
RUN uv sync --frozen && uv cache clean
14+
15+
FROM python:3.11-slim-bookworm
16+
17+
WORKDIR /app
18+
19+
COPY --from=builder /app/.venv /app/.venv
20+
COPY --from=builder /app/src /app/src
21+
22+
COPY ./config /app/config
23+
24+
# Environment variables
25+
ENV PATH="/app/.venv/bin:$PATH" \
26+
PYTHONUNBUFFERED=1 \
27+
PYTHONDONTWRITEBYTECODE=1
2128

29+
# Run the application
2230
ENTRYPOINT ["python", "-OO", "-m", "{{ cookiecutter.module_name }}"]

{{cookiecutter.project_slug}}/docker-compose.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@ services:
44
{{ cookiecutter.project_slug }}:
55
image: 'at/{{ cookiecutter.project_slug }}:latest'
66
build:
7-
context: .{% if cookiecutter.package_manager != 'poetry' %}
7+
context: .
88
args:
9-
PYTHON_IMAGE_TAG: {% if cookiecutter.package_manager == 'conda' %}"4.8.2"{% else %}"3.8-stretch"{% endif %}{% endif %}
10-
command: '{% if cookiecutter.create_cli == 'yes' %}--help{% endif %}'
9+
{% if cookiecutter.package_manager == 'uv' %}
10+
PYTHON_IMAGE_TAG: "3.11-bookworm"
11+
{% elif cookiecutter.package_manager == 'poetry' %}
12+
PYTHON_IMAGE_TAG: "3.9-bullseye"
13+
{% elif cookiecutter.package_manager == 'conda' %}
14+
PYTHON_IMAGE_TAG: "3.9-slim"
15+
{% else %}
16+
PYTHON_IMAGE_TAG: "3.9-slim"
17+
{% endif %}
18+
command: '{% if cookiecutter.create_cli == "yes" %}--help{% else %}--config /app/config/config.yml{% endif %}'
1119
tty: true

{{cookiecutter.project_slug}}/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ dependencies = [
7777
"PyYAML>=6.0",
7878
{%- endif %}
7979
{%- if cookiecutter.create_cli == 'yes' %}
80-
"typer[all]>=0.15.1",
80+
"typer>=0.15.1",
8181
{%- endif %}
8282
]
8383

0 commit comments

Comments
 (0)