diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml new file mode 100644 index 0000000..6a668da --- /dev/null +++ b/.github/workflows/container.yml @@ -0,0 +1,43 @@ +name: Build Container + +on: + push: + branches: + - main + tags: + - v* + pull_request: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ghcr.io/netways/alertmanager-icinga-bridge + +jobs: + push: + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + if: startsWith(github.ref, 'refs/tags/v') + + steps: + - uses: actions/checkout@v6 + + - name: Build image + run: | + docker build --file Dockerfile --tag ghcr.io/netways/alertmanager-icinga-bridge --build-arg "BRIDGE_VERSION=${GITHUB_REF}" --build-arg "BRIDGE_COMMIT=${GITHUB_SHA}" . + + - name: Log in to registry + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + - name: Push image + run: | + IMAGE_ID=ghcr.io/netways/alertmanager-icinga-bridge + # This strips the git ref prefix from the version. + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + # This strips the "v" prefix from the tag name. + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + docker tag $IMAGE_NAME $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$VERSION