From 62530eabfb8a7d278d570a8ee5375e6c67717fbb Mon Sep 17 00:00:00 2001 From: Hazel Atkinson Date: Wed, 9 Apr 2025 16:38:56 +0100 Subject: add deploy CI --- .github/workflows/publish.yml | 61 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..6ab5170 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,61 @@ +name: Publish Docker Image + +on: + push: + branches: + - master + tags: + - v** + workflow_dispatch: + +jobs: + publish: + name: Publish Docker Image to ghcr.io + runs-on: ubuntu-latest + permissions: + packages: write + steps: + - name: Check out the repo + uses: actions/checkout@v4 + + - name: Setup version number + run: | + # docker/build-push-action supports comma separated tags + DOCKER_IMAGE_TAG_BASE="ghcr.io/${{ github.repository }}" + DOCKER_IMAGE_TAGS="$DOCKER_IMAGE_TAG_BASE:dev" + + # if this is a versioned release, github.ref will start with 'refs/tags/v' + GH_REF="${{ github.ref }}" + # cut off 'refs/tags/v' + if [[ $GH_REF == "refs/tags/v"* ]]; then + VERSION=$(echo $GH_REF | cut -c 12-) + DOCKER_IMAGE_TAGS="$DOCKER_IMAGE_TAGS,$DOCKER_IMAGE_TAG_BASE:latest,$DOCKER_IMAGE_TAG_BASE:$VERSION" + fi + + echo "DOCKER_IMAGE_TAGS=\"$DOCKER_IMAGE_TAGS\"" >> $GITHUB_ENV + + - name: Check if version already exists in registry + run: | + if docker manifest inspect ghcr.io/${{ github.repository }}:$VERSION > /dev/null 2>&1; then + echo "Image with version $VERSION already exists in registry" + exit 1 + fi + + - name: Log in to ghcr.io + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push Docker Image + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ env.DOCKER_IMAGE_TAGS }} + platforms: linux/amd64,linux/arm64,linux/arm/v7 \ No newline at end of file -- cgit