Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish docker image #5

Merged
merged 3 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/build-and-push-image.yml
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
106 changes: 106 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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