Skip to content

Commit 9ff1a55

Browse files
committed
Dockerfile changes
1 parent bcb7f42 commit 9ff1a55

File tree

11 files changed

+636
-475
lines changed

11 files changed

+636
-475
lines changed

.dockerignore

+152
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,155 @@ docker-compose*
66
.gitignore
77
.vscode
88
env
9+
10+
docker-scripts/
11+
examples/
12+
dev/
13+
secrets/
14+
dist/
15+
16+
17+
# Byte-compiled / optimized / DLL files
18+
__pycache__/
19+
*.py[cod]
20+
*$py.class
21+
22+
# C extensions
23+
*.so
24+
25+
# Distribution / packaging
26+
.Python
27+
build/
28+
develop-eggs/
29+
dist/
30+
downloads/
31+
eggs/
32+
.eggs/
33+
lib/
34+
lib64/
35+
parts/
36+
sdist/
37+
var/
38+
wheels/
39+
share/python-wheels/
40+
*.egg-info/
41+
.installed.cfg
42+
*.egg
43+
MANIFEST
44+
45+
# PyInstaller
46+
# Usually these files are written by a python script from a template
47+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
48+
*.manifest
49+
*.spec
50+
51+
# Installer logs
52+
pip-log.txt
53+
pip-delete-this-directory.txt
54+
55+
# Unit test / coverage reports
56+
htmlcov/
57+
.tox/
58+
.nox/
59+
.coverage
60+
.coverage.*
61+
.cache
62+
nosetests.xml
63+
coverage.xml
64+
*.cover
65+
*.py,cover
66+
.hypothesis/
67+
.pytest_cache/
68+
cover/
69+
70+
# Translations
71+
*.mo
72+
*.pot
73+
74+
# Django stuff:
75+
*.log
76+
local_settings.py
77+
db.sqlite3
78+
db.sqlite3-journal
79+
80+
# Flask stuff:
81+
instance/
82+
.webassets-cache
83+
84+
# Scrapy stuff:
85+
.scrapy
86+
87+
# Sphinx documentation
88+
docs/_build/
89+
90+
# PyBuilder
91+
.pybuilder/
92+
target/
93+
94+
# Jupyter Notebook
95+
.ipynb_checkpoints
96+
97+
# IPython
98+
profile_default/
99+
ipython_config.py
100+
101+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
102+
__pypackages__/
103+
104+
# Celery stuff
105+
celerybeat-schedule
106+
celerybeat.pid
107+
108+
# SageMath parsed files
109+
*.sage.py
110+
111+
# Environments
112+
.env
113+
.env.local
114+
.env.dev
115+
.env.prod
116+
.venv
117+
env/
118+
venv/
119+
ENV/
120+
env.bak/
121+
venv.bak/
122+
123+
# Spyder project settings
124+
.spyderproject
125+
.spyproject
126+
127+
# Rope project settings
128+
.ropeproject
129+
130+
# mkdocs documentation
131+
/site
132+
133+
# mypy
134+
.mypy_cache/
135+
.dmypy.json
136+
dmypy.json
137+
138+
# Pyre type checker
139+
.pyre/
140+
141+
# pytype static type analyzer
142+
.pytype/
143+
144+
# Cython debug symbols
145+
cython_debug/
146+
147+
148+
# Visual Studio Code IDE
149+
.vscode/*
150+
!.vscode/settings.json
151+
!.vscode/tasks.json
152+
!.vscode/launch.json
153+
!.vscode/extensions.json
154+
!.vscode/*.code-snippets
155+
156+
# Local History for Visual Studio Code
157+
.history/
158+
159+
# Built Visual Studio Code Extensions
160+
*.vsix

Dockerfile

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
##### Stage 'base' - Base image #####
2+
FROM python:3.12.2-slim AS base
3+
4+
# Update Ubuntu repos and install required dependencies
5+
RUN apt-get update -y && \
6+
apt-get install -y openssl && \
7+
python3 -m pip install --upgrade pip
8+
9+
10+
##### Stage 'builder' - Build wheel #####
11+
FROM base as builder
12+
13+
ENV POETRY_HOME=/opt/poetry \
14+
POETRY_NO_INTERACTION=1 \
15+
POETRY_CACHE_DIR=/tmp/poetry_cache
16+
17+
ENV PATH="${PATH}:${POETRY_HOME}/bin"
18+
19+
# Create directory for build artifacts
20+
RUN mkdir -p /build
21+
22+
# Install poetry
23+
ADD https://install.python-poetry.org install_poetry.py
24+
RUN python3 install_poetry.py
25+
26+
# Copy source code
27+
WORKDIR /app/src
28+
COPY . .
29+
30+
# Create a blank Readme file for poetry build
31+
RUN touch README.md
32+
33+
# Build package wheel
34+
RUN poetry check && \
35+
poetry build -f wheel -o /build/dist/
36+
37+
##### Stage 'server' - Build application #####
38+
FROM base AS server
39+
40+
LABEL maintainer="Narayan Bandodker <[email protected]>"
41+
42+
# Install dumb-init and cURL
43+
RUN apt-get install -y dumb-init curl
44+
45+
WORKDIR /app
46+
47+
# Copy build files from previous stage
48+
COPY --from=builder /build .
49+
50+
# Copy entrypoint script
51+
COPY ./docker-scripts/entrypoint.sh ./docker-scripts/dependencies.sh ./docker-scripts/requirements.txt ./
52+
RUN chmod +x ./entrypoint.sh ./dependencies.sh
53+
54+
ENTRYPOINT ["./entrypoint.sh"]
55+
56+
HEALTHCHECK --interval=30s --timeout=30s --start-period=30s --retries=20 CMD curl --include --request GET http://localhost:8000/health || exit 1

docker-scripts/dependencies.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
# Add installation script here.
4+
# For runtime changes, mount your modified file at `/app/dependencies.sh` to replace this file.
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/dumb-init /bin/sh
22

33
echo '[Entrypoint] Installing server package requirements...'
4-
python3 -m pip install --upgrade -r ./requirements.txt
4+
python3 -m pip install --find-links ./dist/ --upgrade -r ./requirements.txt
55

66
echo '[Entrypoint] Installing other dependencies...'
77
. ./dependencies.sh
88

99
echo '[Entrypoint] Starting app server...'
10-
exec python3 -m uvicorn --factory tredex_server:init_app "$@"
10+
exec python3 -m uvicorn --factory sample_fastapi:init_app "$@"

docker-scripts/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sample-fastapi

docker/docker-dev/Dockerfile

-23
This file was deleted.

docker/docker-dev/docker-compose.yml

-22
This file was deleted.

docker/docker-prod/.gitignore

-2
This file was deleted.

docker/docker-prod/Dockerfile

-25
This file was deleted.

docker/docker-prod/dependencies.sh

-12
This file was deleted.

0 commit comments

Comments
 (0)