From 62ce03ae5892a3c9966b684c5512f4b51dcd832f Mon Sep 17 00:00:00 2001 From: Tilly Woodfield <22456167+tillywoodfield@users.noreply.github.com> Date: Tue, 11 Feb 2025 15:09:00 +0200 Subject: [PATCH 1/3] build: add Dockerfile --- .github/workflows/ci.yml | 2 + Dockerfile | 18 +++++++ requirements.txt | 106 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 Dockerfile create mode 100644 requirements.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4f2ac72..960e766 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,3 +23,5 @@ jobs: run: mypy oc4ids_datastore_api/ tests/ - name: Run tests run: pytest + - name: Build docker image + run: docker build -t oc4ids-datastore-api . diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c682d4f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM python:3.12-slim + +RUN apt-get update \ + && apt-get install -y libpq-dev gcc + +WORKDIR /oc4ids_datastore_api + +COPY requirements.txt . + +RUN pip install -r requirements.txt + +COPY . . + +RUN pip install . + +EXPOSE 8000 + +ENTRYPOINT ["fastapi", "run", "oc4ids_datastore_api/main.py"] diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..9a2d202 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,106 @@ +# +# This file is autogenerated by pip-compile with Python 3.12 +# by the following command: +# +# pip-compile --output-file=requirements.txt pyproject.toml +# +annotated-types==0.7.0 + # via pydantic +anyio==4.8.0 + # via + # httpx + # starlette + # watchfiles +certifi==2025.1.31 + # via + # httpcore + # httpx +click==8.1.8 + # via + # rich-toolkit + # typer + # uvicorn +dnspython==2.7.0 + # via email-validator +email-validator==2.2.0 + # via fastapi +fastapi[standard]==0.115.8 + # via oc4ids-datastore-api (pyproject.toml) +fastapi-cli[standard]==0.0.7 + # via fastapi +h11==0.14.0 + # via + # httpcore + # uvicorn +httpcore==1.0.7 + # via httpx +httptools==0.6.4 + # via uvicorn +httpx==0.28.1 + # via fastapi +idna==3.10 + # via + # anyio + # email-validator + # httpx +jinja2==3.1.5 + # via fastapi +markdown-it-py==3.0.0 + # via rich +markupsafe==3.0.2 + # via jinja2 +mdurl==0.1.2 + # via markdown-it-py +psycopg2==2.9.10 + # via oc4ids-datastore-api (pyproject.toml) +pydantic==2.10.6 + # via + # fastapi + # sqlmodel +pydantic-core==2.27.2 + # via pydantic +pygments==2.19.1 + # via rich +python-dotenv==1.0.1 + # via uvicorn +python-multipart==0.0.20 + # via fastapi +pyyaml==6.0.2 + # via uvicorn +rich==13.9.4 + # via + # rich-toolkit + # typer +rich-toolkit==0.13.2 + # via fastapi-cli +shellingham==1.5.4 + # via typer +sniffio==1.3.1 + # via anyio +sqlalchemy==2.0.38 + # via sqlmodel +sqlmodel==0.0.22 + # via oc4ids-datastore-api (pyproject.toml) +starlette==0.45.3 + # via fastapi +typer==0.15.1 + # via fastapi-cli +typing-extensions==4.12.2 + # via + # anyio + # fastapi + # pydantic + # pydantic-core + # rich-toolkit + # sqlalchemy + # typer +uvicorn[standard]==0.34.0 + # via + # fastapi + # fastapi-cli +uvloop==0.21.0 + # via uvicorn +watchfiles==1.0.4 + # via uvicorn +websockets==14.2 + # via uvicorn From c8c00090fc1569643f564f258832baa8f9105687 Mon Sep 17 00:00:00 2001 From: Tilly Woodfield <22456167+tillywoodfield@users.noreply.github.com> Date: Tue, 11 Feb 2025 16:51:55 +0200 Subject: [PATCH 2/3] ci: add build and push image workflow --- .github/workflows/build-and-push-image.yml | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/build-and-push-image.yml diff --git a/.github/workflows/build-and-push-image.yml b/.github/workflows/build-and-push-image.yml new file mode 100644 index 0000000..a805ed2 --- /dev/null +++ b/.github/workflows/build-and-push-image.yml @@ -0,0 +1,32 @@ +name: Build and push image + +on: + release: + types: [created] + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + env: + IMAGE_NAME: "oc4ids-datastore-api" + steps: + - uses: actions/checkout@v4 + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract version + run: | + TAG=${GITHUB_REF#refs/*/} + echo "VERSION=${TAG#v}" >> $GITHUB_ENV + - name: Print version + run: echo $VERSION + - name: Build and push image + run: | + IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + echo $IMAGE_ID + docker build . -t ${IMAGE_ID}:${VERSION} -t ${IMAGE_ID}:latest + docker push --all-tags ${IMAGE_ID} From 362a631171dffa24cd2cae06389ceabaed2f92fe Mon Sep 17 00:00:00 2001 From: Tilly Woodfield <22456167+tillywoodfield@users.noreply.github.com> Date: Wed, 12 Feb 2025 17:08:09 +0200 Subject: [PATCH 3/3] docs: document release process in README --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 8510221..2fab362 100644 --- a/README.md +++ b/README.md @@ -40,3 +40,7 @@ isort oc4ids_datastore_api/ tests/ flake8 oc4ids_datastore_api/ tests/ mypy oc4ids_datastore_api/ tests/ ``` + +## Releasing + +To publish a new version, raise a PR to `main` updating the version in `pyproject.toml`. Once merged, create a git tag and GitHub release for the new version, with naming `vX.Y.Z`. This will trigger a docker image to to be built and pushed, tagged with the version and `latest`.