From 5cc91500cdca0719518f3a46d76e707d81255bad Mon Sep 17 00:00:00 2001 From: Nils Mechtel Date: Wed, 4 Dec 2024 09:53:48 +0100 Subject: [PATCH] add docker image version tag --- .github/workflows/docker-publish.yml | 12 +++++++++-- Dockerfile | 2 +- scripts/build_and_push.sh | 32 ---------------------------- 3 files changed, 11 insertions(+), 35 deletions(-) delete mode 100644 scripts/build_and_push.sh diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 341e0f9..a9c7f5e 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -28,13 +28,21 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Build and push Docker image (latest tag) + - name: Extract version from project.toml + id: extract_version + run: | + VERSION=$(grep '^version' project.toml | sed -E 's/version *= *"([0-9.]+)"/\1/') + echo "version=$VERSION" >> $GITHUB_ENV + + - name: Build and push Docker image (latest and version tags) uses: docker/build-push-action@v5.0.0 with: context: . file: Dockerfile push: true - tags: ghcr.io/${{ github.repository }}:latest + tags: | + ghcr.io/${{ github.repository }}:latest + ghcr.io/${{ github.repository }}:${{ env.version }} labels: | org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} cache-from: type=gha diff --git a/Dockerfile b/Dockerfile index 8d1fc5b..19e70f7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,4 +46,4 @@ RUN chmod +x /app/start_service.sh USER bioimageio_colab # Use the start script as the entrypoint and forward arguments -ENTRYPOINT ["/app/start_service.sh"] +ENTRYPOINT ["python", "register_sam_service.py"] diff --git a/scripts/build_and_push.sh b/scripts/build_and_push.sh deleted file mode 100644 index b207327..0000000 --- a/scripts/build_and_push.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -# Load environment variables from .env file -if [ -f .env ]; then - export $(grep -v '^#' .env | xargs) -else - echo ".env file not found!" - exit 1 -fi - -# Ensure GHCR_PAT is set -if [ -z "$GHCR_PAT" ]; then - echo "GHCR_PAT is not set in the .env file!" - exit 1 -fi - -# Extract GitHub actor and repository info -GITHUB_ACTOR=$(git config --global user.email) -GITHUB_REPOSITORY=$(git remote get-url origin | sed -E 's|https://github.com/([^/]+/[^.]+).git|\1|') -IMAGE_NAME=ghcr.io/${GITHUB_REPOSITORY}:latest - -# Log in to GHCR -echo "$GHCR_PAT" | docker login ghcr.io -u "$GITHUB_ACTOR" --password-stdin - -# Generate a dynamic CACHEBUST value (timestamp) -export CACHEBUST=$(date +%Y%m%d%H%M%S) - -# Build the Docker image using Docker Compose with the CACHEBUST argument -docker-compose build - -# Push the Docker image to GHCR -docker push "$IMAGE_NAME"