From 0045285e8a26da6e599f0856f2f98f1e42b7623a Mon Sep 17 00:00:00 2001 From: Stuart Caunt Date: Mon, 6 Jan 2025 16:06:49 +0100 Subject: [PATCH] add github action to build docker image and push to ghcr.io. --- .github/workflows/docker-image.yml | 53 ++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/docker-image.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..ced75e8 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,53 @@ +name: Build and push docker image + +on: + push: + branches: [ "dev" ] + tags: [ "*.*.*" ] + pull_request: + branches: [ "dev" ] + +jobs: + docker: + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + + - name: Login to GHCR + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v4 + with: + context : . + file : ./Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + + - name: Trigger external deploy pipeline + if: success() && github.ref == 'refs/heads/dev' + run: | + if [ -z "${{ secrets.DEPLOY_PIPELINE_URL }}" ]; then + echo "Error: DEPLOY_PIPELINE_URL is not set" + else + curl -X POST "${{ secrets.DEPLOY_PIPELINE_URL }}" + fi