Skip to content

Commit ca3e58f

Browse files
authored
Merge pull request #485 from microsoft/psl-bug-23296
fix: optimize the Dockerfile for frontend and backend
2 parents 9ded43f + 894b2e6 commit ca3e58f

File tree

6 files changed

+366
-9
lines changed

6 files changed

+366
-9
lines changed

azure_custom.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ services:
1111
language: py
1212
host: containerapp
1313
docker:
14+
path: ./Dockerfile.NoCache
1415
image: backend
1516
remoteBuild: true
1617

src/backend/.dockerignore

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# Include any files or directories that you don't want to be copied to your
2+
# container here (e.g., local build artifacts, temporary files, etc.).
3+
#
4+
# For more help, visit the .dockerignore file reference guide at
5+
# https://docs.docker.com/engine/reference/builder/#dockerignore-file
6+
7+
**/.DS_Store
8+
**/__pycache__
9+
**/.venv
10+
**/.classpath
11+
**/.dockerignore
12+
**/.env
13+
**/.git
14+
**/.gitignore
15+
**/.project
16+
**/.settings
17+
**/.toolstarget
18+
**/.vs
19+
**/.vscode
20+
**/*.*proj.user
21+
**/*.dbmdl
22+
**/*.jfm
23+
**/bin
24+
**/charts
25+
**/docker-compose*
26+
**/compose*
27+
**/Dockerfile*
28+
**/node_modules
29+
**/npm-debug.log
30+
**/obj
31+
**/secrets.dev.yaml
32+
**/values.dev.yaml
33+
LICENSE
34+
README.md
35+
36+
# Byte-compiled / optimized / DLL files
37+
__pycache__/
38+
*.py[cod]
39+
*$py.class
40+
41+
# C extensions
42+
*.so
43+
44+
# Distribution / packaging
45+
.Python
46+
build/
47+
develop-eggs/
48+
dist/
49+
downloads/
50+
eggs/
51+
lib/
52+
lib64/
53+
parts/
54+
sdist/
55+
var/
56+
*.egg-info/
57+
.installed.cfg
58+
*.egg
59+
60+
# PyInstaller
61+
# Usually these files are written by a python script from a template
62+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
63+
*.manifest
64+
*.spec
65+
66+
# Installer logs
67+
pip-log.txt
68+
pip-delete-this-directory.txt
69+
70+
# Unit test / coverage reports
71+
htmlcov/
72+
.tox/
73+
.nox/
74+
.coverage
75+
.coverage.*
76+
.cache
77+
nosetests.xml
78+
coverage.xml
79+
*.cover
80+
*.log
81+
82+
# Translations
83+
*.mo
84+
*.pot
85+
86+
# Django stuff:
87+
*.log
88+
local_settings.py
89+
db.sqlite3
90+
91+
# Flask stuff:
92+
instance/
93+
.webassets-cache
94+
95+
# Scrapy stuff:
96+
.scrapy
97+
98+
# Sphinx documentation
99+
docs/_build/
100+
101+
# PyBuilder
102+
target/
103+
104+
# Jupyter Notebook
105+
.ipynb_checkpoints
106+
107+
# IPython
108+
profile_default/
109+
ipython_config.py
110+
111+
# pyenv
112+
.python-version
113+
114+
# celery beat schedule file
115+
celerybeat-schedule
116+
117+
# SageMath parsed files
118+
*.sage.py
119+
120+
# Environments
121+
.env
122+
.venv
123+
env/
124+
venv/
125+
ENV/
126+
env.bak/
127+
venv.bak/
128+
129+
# Spyder project settings
130+
.spyderproject
131+
.spyproject
132+
133+
# Rope project settings
134+
.ropeproject
135+
136+
# mkdocs documentation
137+
/site
138+
139+
# mypy
140+
.mypy_cache/
141+
.dmypy.json
142+
dmypy.json
143+
144+
# Pyre type checker
145+
.pyre/
146+
147+
# pytype static type analyzer
148+
.pytype/
149+
150+
# Cython debug symbols
151+
cython_debug/
152+
153+
# VS Code
154+
.vscode/
155+
156+
# Ignore other unnecessary files
157+
*.bak
158+
*.swp
159+
.DS_Store
160+
*.pdb
161+
*.sqlite3

src/backend/Dockerfile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Base Python image
2-
FROM mcr.microsoft.com/devcontainers/python:3.11-bullseye AS base
2+
FROM python:3.11-slim-bullseye AS base
33
WORKDIR /app
44

55
FROM base AS builder
@@ -10,16 +10,16 @@ WORKDIR /app
1010
COPY uv.lock pyproject.toml /app/
1111

1212
# Install the project's dependencies using the lockfile and settings
13-
# RUN --mount=type=cache,target=/root/.cache/uv \
14-
# --mount=type=bind,source=uv.lock,target=uv.lock \
15-
# --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
16-
# uv sync --frozen --no-install-project --no-dev
17-
RUN uv sync --frozen --no-install-project --no-dev
13+
RUN --mount=type=cache,target=/root/.cache/uv \
14+
--mount=type=bind,source=uv.lock,target=uv.lock \
15+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
16+
uv sync --frozen --no-install-project --no-dev
17+
#RUN uv sync --frozen --no-install-project --no-dev
1818

1919
# Backend app setup
2020
COPY . /app
21-
#RUN --mount=type=cache,target=/root/.cache/uv uv sync --frozen --no-dev
22-
RUN uv sync --frozen --no-dev
21+
RUN --mount=type=cache,target=/root/.cache/uv uv sync --frozen --no-dev
22+
#RUN uv sync --frozen --no-dev
2323

2424

2525
FROM base

src/backend/Dockerfile.NoCache

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Base Python image
2+
FROM python:3.11-slim-bullseye AS base
3+
WORKDIR /app
4+
5+
FROM base AS builder
6+
COPY --from=ghcr.io/astral-sh/uv:0.6.3 /uv /uvx /bin/
7+
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
8+
9+
WORKDIR /app
10+
COPY uv.lock pyproject.toml /app/
11+
12+
# Install the project's dependencies using the lockfile and settings
13+
# RUN --mount=type=cache,target=/root/.cache/uv \
14+
# --mount=type=bind,source=uv.lock,target=uv.lock \
15+
# --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
16+
# uv sync --frozen --no-install-project --no-dev
17+
RUN uv sync --frozen --no-install-project --no-dev
18+
19+
# Backend app setup
20+
COPY . /app
21+
#RUN --mount=type=cache,target=/root/.cache/uv uv sync --frozen --no-dev
22+
RUN uv sync --frozen --no-dev
23+
24+
25+
FROM base
26+
27+
COPY --from=builder /app /app
28+
COPY --from=builder /bin/uv /bin/uv
29+
30+
ENV PATH="/app/.venv/bin:$PATH"
31+
# Install dependencies
32+
33+
EXPOSE 8000
34+
CMD ["uv", "run", "uvicorn", "app_kernel:app", "--host", "0.0.0.0", "--port", "8000"]

0 commit comments

Comments
 (0)