Skip to content

Commit d06adb8

Browse files
authored
Merge pull request #320 from somakeit/smib-v2.0
S.M.I.B. v2.0
2 parents 8b8af72 + d14f6f4 commit d06adb8

File tree

126 files changed

+4242
-4205
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+4242
-4205
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
db/
2+
static/
3+
.venv/
4+
.env

.gitignore

Lines changed: 212 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,213 @@
1-
syntax: glob
2-
.idea/
3-
*.pyc
4-
**/__pycache__/
5-
smib/log/
6-
.vscode/
7-
.micropico
8-
*.pyi
9-
.env
10-
/package-lock.json
11-
/node_modules/
12-
logs/
1+
### venv template
2+
# Virtualenv
3+
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
4+
.Python
5+
[Bb]in
6+
[Ii]nclude
7+
[Ll]ib
8+
[Ll]ib64
9+
[Ll]ocal
10+
[Ss]cripts
11+
pyvenv.cfg
12+
.venv
13+
pip-selfcheck.json
14+
15+
### PythonVanilla template
16+
# Byte-compiled / optimized / DLL files
17+
__pycache__/
18+
*.py[cod]
19+
*$py.class
20+
21+
# C extensions
22+
*.so
23+
24+
# Distribution / packaging
25+
build/
26+
develop-eggs/
27+
dist/
28+
downloads/
29+
eggs/
30+
.eggs/
31+
lib/
32+
lib64/
33+
parts/
34+
sdist/
35+
var/
36+
wheels/
37+
share/python-wheels/
38+
*.egg-info/
39+
.installed.cfg
40+
*.egg
41+
MANIFEST
42+
43+
# Installer logs
44+
pip-log.txt
45+
pip-delete-this-directory.txt
46+
47+
# Unit test / coverage reports
48+
htmlcov/
49+
.tox/
50+
.nox/
51+
.coverage
52+
.coverage.*
53+
.cache
54+
nosetests.xml
55+
coverage.xml
56+
*.cover
57+
*.py,cover
58+
.hypothesis/
59+
.pytest_cache/
60+
cover/
61+
.coveragerc
62+
pytestdebug.log
63+
64+
65+
# Translations
66+
*.mo
67+
*.pot
68+
69+
# pyenv
70+
# For a library or package, you might want to ignore these files since the code is
71+
# intended to run in multiple environments; otherwise, check them in:
72+
# .python-version
73+
74+
# pipenv
75+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
76+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
77+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
78+
# install all needed dependencies.
79+
#Pipfile.lock
80+
81+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
82+
__pypackages__/
83+
84+
85+
### VirtualEnv template
86+
# Virtualenv
87+
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
88+
89+
### Python template
90+
# Byte-compiled / optimized / DLL files
91+
92+
# C extensions
93+
94+
# Distribution / packaging
95+
96+
# PyInstaller
97+
# Usually these files are written by a python script from a template
98+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
99+
*.manifest
100+
*.spec
101+
102+
# Installer logs
103+
104+
# Unit test / coverage reports
105+
106+
# Translations
107+
108+
# Django stuff:
13109
*.log
14-
.pylintrc
110+
local_settings.py
111+
db.sqlite3
112+
db.sqlite3-journal
113+
114+
# Flask stuff:
115+
instance/
116+
.webassets-cache
117+
118+
# Scrapy stuff:
119+
.scrapy
120+
121+
# Sphinx documentation
122+
docs/_build/
123+
124+
# PyBuilder
125+
.pybuilder/
126+
target/
127+
128+
# Jupyter Notebook
129+
.ipynb_checkpoints
130+
131+
# IPython
132+
profile_default/
133+
ipython_config.py
134+
135+
# pyenv
136+
# For a library or package, you might want to ignore these files since the code is
137+
# intended to run in multiple environments; otherwise, check them in:
138+
# .python-version
139+
140+
# pipenv
141+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
142+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
143+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
144+
# install all needed dependencies.
145+
#Pipfile.lock
146+
147+
# poetry
148+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
149+
# This is especially recommended for binary packages to ensure reproducibility, and is more
150+
# commonly ignored for libraries.
151+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
152+
#poetry.lock
153+
154+
# pdm
155+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
156+
#pdm.lock
157+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
158+
# in version control.
159+
# https://pdm.fming.dev/#use-with-ide
160+
.pdm.toml
161+
162+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
163+
164+
# Celery stuff
165+
celerybeat-schedule
166+
celerybeat.pid
167+
168+
# SageMath parsed files
169+
*.sage.py
170+
171+
# Environments
172+
.env
173+
env/
174+
venv/
175+
ENV/
176+
env.bak/
177+
venv.bak/
178+
179+
# Spyder project settings
180+
.spyderproject
181+
.spyproject
182+
183+
# Rope project settings
184+
.ropeproject
185+
186+
# mkdocs documentation
187+
/site
188+
189+
# mypy
190+
.mypy_cache/
191+
.dmypy.json
192+
dmypy.json
193+
194+
# Pyre type checker
195+
.pyre/
196+
197+
# pytype static type analyzer
198+
.pytype/
199+
200+
# Cython debug symbols
201+
cython_debug/
202+
203+
# PyCharm
204+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
205+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
206+
# and can be added to the global gitignore or merged into this file. For a more nuclear
207+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
208+
.idea/
209+
210+
.output.txt
211+
static/
212+
db/
213+
src/plugins/sam-dev

Dockerfile

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,51 @@
1-
# Use an official Python 3.11 runtime as a base image
2-
FROM python:3.12.3-bullseye AS builder
1+
## ------------------------------- Builder Stage ------------------------------ ##
2+
FROM python:3.13-bookworm AS builder
33

4-
RUN pip install poetry==2
4+
RUN apt-get update && apt-get install --no-install-recommends -y \
5+
build-essential && \
6+
apt-get clean && rm -rf /var/lib/apt/lists/*
57

6-
ENV POETRY_NO_INTERACTION=1 \
7-
POETRY_VIRTUALENVS_IN_PROJECT=1 \
8-
POETRY_VIRTUALENVS_CREATE=1 \
9-
POETRY_CACHE_DIR=/tmp/poetry_cache
8+
# Download the latest installer, install it and then remove it
9+
ADD https://astral.sh/uv/install.sh /install.sh
10+
RUN chmod -R 755 /install.sh && /install.sh && rm /install.sh
1011

11-
# Set the working directory in the container to /smib
12-
WORKDIR /app
13-
14-
# Copy the entire smib package into the container at /smib
15-
COPY smib ./smib
16-
COPY pyproject.toml poetry.lock README.md ./
12+
# Set up the UV environment path correctly
13+
ENV PATH="/root/.local/bin:${PATH}"
1714

18-
# Install all dependencies without the source code first (caches dependencies)
19-
RUN poetry install --no-root --no-directory && rm -rf $POETRY_CACHE_DIR
15+
WORKDIR /app
2016

21-
# Re-run poetry install to install the `smib` module itself in editable mode
22-
RUN poetry install --only-root
17+
# Copy bare minimum for requirements install
18+
COPY pyproject.toml README.md ./
2319

20+
# Override to dummy version when installing dependancies only
21+
ENV SETUPTOOLS_SCM_PRETEND_VERSION=0.0.0
22+
RUN uv sync --no-install-project --no-install-workspace
2423

25-
# The runtime image, used to just run the code provided its virtual environment
26-
FROM python:3.12.3-slim-bullseye AS runtime
24+
# Copy entire context - so we can caculate the git revision
25+
COPY . .
2726

28-
ENV VIRTUAL_ENV=/app/.venv \
29-
PATH="/app/.venv/bin:$PATH"
27+
# Unset version so actual version number can be used
28+
ENV SETUPTOOLS_SCM_PRETEND_VERSION=
29+
RUN uv pip install -e .
3030

31-
COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}
31+
## ------------------------------- Production Stage ------------------------------ ##
32+
FROM python:3.13-slim-bookworm AS runtime
3233

33-
# Set timezone - can still be overridden in the docker-compose file
34-
COPY --from=builder /etc/environment /etc/environment
35-
COPY --from=builder /etc/localtime /etc/localtime
34+
RUN useradd smibuser
35+
USER smibuser
3636

3737
WORKDIR /app
38-
COPY smib ./smib
3938

40-
# Remove logging.json from container
41-
RUN rm ./smib/logging.json
39+
# Copy the entire source directory and virtual environment
40+
COPY --from=builder /app/src ./src
41+
COPY --from=builder /app/.venv ./.venv
42+
COPY --from=builder /app/pyproject.toml ./pyproject.toml
43+
44+
# Set up environment variables for production
45+
ENV PATH="/app/.venv/bin:$PATH"
46+
ENV PYTHONPATH="/app/src"
4247

43-
# Copy logging.json into correct container location
44-
COPY smib/logging.json /app/config/logging.json
48+
HEALTHCHECK --interval=10s --timeout=10s --start-period=8s --retries=3 \
49+
CMD python -c "import os, urllib.request; exit(0) if urllib.request.urlopen(f'http://localhost:{os.environ.get(\"SMIB_WEBSERVER_PORT\", \"80\")}/ping').status == 200 else exit(1)"
4550

46-
# Copy .env if it exists
47-
COPY .env* /app/config/
51+
CMD ["python", "-m", "smib"]

0 commit comments

Comments
 (0)