Skip to content

Commit

Permalink
Feat: version from git metadata (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
angela-tran authored Dec 18, 2023
2 parents 2162506 + cff026e commit df3d3d9
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 27 deletions.
12 changes: 5 additions & 7 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ FROM eligibility_server:latest
COPY docs/requirements.txt docs/requirements.txt
RUN pip install --no-cache-dir -r docs/requirements.txt

# copy files needed
COPY .git .git
COPY eligibility_server/ eligibility_server/
COPY pyproject.toml pyproject.toml

# install devcontainer requirements
RUN pip install -e .[dev,test]

# install pre-commit environments in throwaway Git repository
# https://stackoverflow.com/a/68758943
COPY .pre-commit-config.yaml .
RUN git init . && \
pre-commit install-hooks && \
rm -rf .git
1 change: 1 addition & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"service": "dev",
"runServices": ["dev", "docs"],
"workspaceFolder": "/home/calitp/app",
"postAttachCommand": ["/bin/bash", ".devcontainer/postAttach.sh"],
"postStartCommand": ["/bin/bash", "bin/init.sh"],
"customizations": {
// Set *default* container specific settings.json values on container create.
Expand Down
4 changes: 4 additions & 0 deletions .devcontainer/postAttach.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -eu

pre-commit install --install-hooks
13 changes: 8 additions & 5 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
.git/
.github/
.vscode/
.flake8
.*ignore
__pycache__/
.pytest_cache/
.coverage
.DS_Store
.env
config/*
!config/sample.py
eligibility_server.egg-info
3 changes: 0 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.formatting.provider": "none",
"python.languageServer": "Pylance",
"python.linting.enabled": true,
"python.linting.flake8Enabled": true,
"python.testing.pytestArgs": ["tests"],
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false,
Expand Down
24 changes: 18 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
FROM ghcr.io/cal-itp/docker-python-web:main
FROM ghcr.io/cal-itp/docker-python-web:main as build_wheel

ENV FLASK_APP=eligibility_server/app.py
WORKDIR /build

# upgrade pip
RUN python -m pip install --upgrade pip

COPY . .
RUN git config --global --add safe.directory /build

# build as root user so unnecessary files are not copied into tarball
USER root
RUN pip install build && python -m build

FROM ghcr.io/cal-itp/docker-python-web:main as appcontainer

WORKDIR /home/calitp/app

ENV FLASK_APP=eligibility_server.app:app

COPY --from=build_wheel /build/dist /build/dist

# copy source files
COPY bin bin
COPY eligibility_server/ eligibility_server/
COPY pyproject.toml pyproject.toml

# install source as a package
RUN pip install -e .
RUN pip install $(find /build/dist -name eligibility_server*.whl)

# start app
ENTRYPOINT ["/bin/bash"]
Expand Down
6 changes: 3 additions & 3 deletions eligibility_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
import logging

from flask import Flask, jsonify, make_response
from flask_restful import Api
from flask.logging import default_handler
from flask_restful import Api

from eligibility_server import db, sentry
from eligibility_server import __version__, db, sentry
from eligibility_server.keypair import get_server_public_key
from eligibility_server.settings import Configuration
from eligibility_server.verify import Verify


config = Configuration()

app = Flask(__name__)
Expand All @@ -29,6 +28,7 @@
# configure Flask's logger
app.logger.setLevel(config.log_level)
default_handler.formatter = logging.Formatter(format_string)
app.logger.info(f"Starting Eligibility Server {__version__}")


def TextResponse(content):
Expand Down
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "eligibility-server"
version = "2023.09.1"
dynamic = ["version"]
description = "Server implementation of the Eligibility Verification API"
readme = "README.md"
license = { file = "LICENSE" }
Expand All @@ -20,6 +20,7 @@ dev = [
"black",
"flake8",
"pre-commit",
"setuptools_scm>=8"
]
test = [
"coverage",
Expand All @@ -33,7 +34,7 @@ Documentation = "https://docs.calitp.org/eligibility-server"
Issues = "https://github.com/cal-itp/eligibility-server/issues"

[build-system]
requires = ["setuptools>=65", "wheel"]
requires = ["setuptools>=65", "setuptools-scm>=8"]
build-backend = "setuptools.build_meta"

[tool.black]
Expand All @@ -51,3 +52,6 @@ include = ["eligibility_server", "tests"]

[tool.setuptools]
packages = ["eligibility_server"]

[tool.setuptools_scm]
# intentionally left blank, but we need the section header to activate the tool
2 changes: 1 addition & 1 deletion tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ def test_version():
from eligibility_server import __version__

assert __version__ is not None
assert re.match(r"\d{4}\.\d{1,2}\.\d+", __version__)
assert re.match(r"\d+\.\d+\..+", __version__)

0 comments on commit df3d3d9

Please sign in to comment.