Skip to content

Commit

Permalink
Fix setuptools-scm docker/CI behaviour and add simple test for versio…
Browse files Browse the repository at this point in the history
…n number

- Mount .git directory one level higher in docker build so that version gets picked up

- Mount .git directory in dev api container

- More version tweaks

- Set fetch-depth to 0 for pytest
  • Loading branch information
ml-evs committed Aug 20, 2024
1 parent 1e154e8 commit 7c382a1
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 4 deletions.
7 changes: 4 additions & 3 deletions .docker/server_dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ RUN [ "uv", "pip", "install", "gunicorn" ]
WORKDIR /app
COPY ./pydatalab/ ./

# Install the local version of the package and mount the repository data to get version info
RUN --mount=type=bind,target=/app/.git,source=./.git ["uv", "pip", "install", "--python", "/opt/.venv/bin/python", "."]

# This will define the number of gunicorn workers
ARG WEB_CONCURRENCY=4
ENV WEB_CONCURRENCY=${WEB_CONCURRENCY}
Expand All @@ -55,6 +52,10 @@ ARG PORT=5001
EXPOSE ${PORT}
ENV PORT=${PORT}

# Install the local version of the package and mount the repository data to get version info
RUN git config --global --add safe.directory /
RUN --mount=type=bind,target=/.git,source=./.git ["uv", "pip", "install", "--python", "/opt/.venv/bin/python", "."]

CMD ["/bin/bash", "-c", "/opt/.venv/bin/python -m gunicorn --preload -w ${WEB_CONCURRENCY} --error-logfile /logs/pydatalab_error.log --access-logfile - -b 0.0.0.0:${PORT} 'pydatalab.main:create_app()'"]

HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD curl --fail http://localhost:${PORT}/healthcheck/is_ready || exit 1
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
# tests need an unshallowed version of the repository to check the version
fetch-depth: 0

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ services:
- database_dev
volumes:
- ./logs:/logs
- ./.git:/.git
- ./pydatalab:/app
ports:
- "5001:5001"
Expand Down
3 changes: 3 additions & 0 deletions pydatalab/pydatalab/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from werkzeug.middleware.proxy_fix import ProxyFix

import pydatalab.mongo
from pydatalab import __version__
from pydatalab.config import CONFIG, FEATURE_FLAGS
from pydatalab.logger import LOGGER, setup_log
from pydatalab.login import LOGIN_MANAGER
Expand Down Expand Up @@ -148,7 +149,9 @@ def create_app(

app.config.update(dotenv_values(dotenv_path=env_file))

LOGGER.info("Launching datalab version %s", __version__)
LOGGER.info("Starting app with Flask app.config: %s", app.config)

_check_feature_flags(app)

if CONFIG.BEHIND_REVERSE_PROXY:
Expand Down
3 changes: 2 additions & 1 deletion pydatalab/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ include = ["pydatalab"]
namespaces = false

[tool.setuptools_scm]
fallback_version = "0.1"
root = ".."
fallback_version = "0.1.0"

[project.optional-dependencies]
dev = [
Expand Down
2 changes: 2 additions & 0 deletions pydatalab/tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ def test_version():
from pydatalab import __version__

assert isinstance(__version__, str)
assert int(__version__.split(".")[0]) == 0
assert int(__version__.split(".")[1]) >= 4

0 comments on commit 7c382a1

Please sign in to comment.