Skip to content

Commit 8389893

Browse files
authored
ci(package): add labels to container image (#54)
Also enable build triggered by event eodag_release. Signed-off-by: Aubin Lambaré <aubin.lambare@cs-soprasteria.com>
1 parent 9aa7ea7 commit 8389893

3 files changed

Lines changed: 43 additions & 1806 deletions

File tree

.github/workflows/package.yml

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
name: Create and publish a Docker image
1+
name: Build and publish a container image
22

33
on:
44
push:
55
branches: ['main']
66
tags: ['v*']
77
workflow_dispatch:
8+
repository_dispatch:
9+
types: [eodag_release]
810

911
env:
1012
REGISTRY: ghcr.io
@@ -13,42 +15,68 @@ env:
1315
jobs:
1416
build-and-push-image:
1517
runs-on: ubuntu-latest
16-
# Sets the permissions granted to the GITHUB_TOKEN for the actions in this job.
1718
permissions:
1819
contents: read
1920
packages: write
20-
attestations: write
2121
id-token: write
2222

23-
# Uses the docker/login-action action to log in to the Container registry
24-
# using the account and password that will publish the packages. Once published,
25-
# the packages are scoped to the account defined here.
2623
steps:
2724
- name: Checkout repository
2825
uses: actions/checkout@v5
2926

27+
- name: Install uv
28+
uses: astral-sh/setup-uv@v6
29+
30+
- name: Install dependencies
31+
run: uv sync --with server --with telemetry
32+
33+
- name: Determine the container tag and labels
34+
id: container_tag
35+
run: |
36+
APP_VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml'))['project']['version'])")
37+
echo "APP_VERSION=$APP_VERSION" >> $GITHUB_ENV
38+
39+
EODAG_VERSION=$(PYTHONWARNINGS="ignore::SyntaxWarning" uv run --active python -c "import eodag; print(eodag.__version__)")
40+
echo "EODAG_VERSION=$EODAG_VERSION" >> $GITHUB_ENV
41+
42+
# Default: branch name
43+
CONTAINER_TAG=${GITHUB_REF##*/}
44+
45+
# Check if this is a release or eodag dispatch
46+
if [[ "${GITHUB_REF_TYPE}" == "tag" || ( "${GITHUB_EVENT_NAME}" == "repository_dispatch" && "${GITHUB_EVENT_CLIENT_PAYLOAD_TYPE}" == "eodag_release" ) ]]; then
47+
CONTAINER_TAG="${APP_VERSION}-eodag-${EODAG_VERSION}"
48+
fi
49+
50+
echo "CONTAINER_TAG=$CONTAINER_TAG" >> $GITHUB_ENV
51+
3052
- name: Set up Docker Buildx
3153
uses: docker/setup-buildx-action@v3
3254

33-
- name: Log in to the Container registry
55+
- name: Log in to the container registry
3456
uses: docker/login-action@v3
3557
with:
3658
registry: ${{ env.REGISTRY }}
3759
username: ${{ github.actor }}
3860
password: ${{ secrets.GITHUB_TOKEN }}
3961

40-
# This step uses docker/metadata-action to extract tags and labels that will be applied to the
41-
# specified image. The id "meta" allows the output of this step to be referenced in a subsequent step.
42-
- name: Extract metadata (tags, labels) for Docker
62+
- name: Extract container metadata
4363
id: meta
4464
uses: docker/metadata-action@v5
4565
with:
4666
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
67+
tags: |
68+
custom=stac-fastapi-eodag:${{ env.CONTAINER_TAG }}
69+
labels: |
70+
org.opencontainers.image.title=stac-fastapi-eodag
71+
org.opencontainers.image.description=A STAC FastAPI backend using EODAG
72+
org.opencontainers.image.url=https://github.com/CS-SI/stac-fastapi-eodag
73+
org.opencontainers.image.source=https://github.com/CS-SI/stac-fastapi-eodag.git
74+
org.opencontainers.image.licenses=Apache-2.0
75+
org.opencontainers.image.authors=CS GROUP - France (CSSI) <eodag@csgroup.space>
76+
org.opencontainers.image.version=${{ env.APP_VERSION }}
77+
org.opencontainers.image.eodag.version=${{ env.EODAG_VERSION }}
4778
48-
# Use the docker/build-push-action action to build the image based on Dockerfile. If the build succeeds,
49-
# it pushes the image to GitHub Packages. It uses the tags and labels parameters to tag and label the image
50-
# with the output from the "meta" step.
51-
- name: Build and push Docker image
79+
- name: Build and push container image
5280
id: push
5381
uses: docker/build-push-action@v6
5482
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ wheels/
5151
*.egg-info/
5252
.installed.cfg
5353
*.egg
54+
uv.lock
5455

5556
# PyInstaller
5657
# Usually these files are written by a python script from a template

0 commit comments

Comments
 (0)