From 70b0d25092b7453fb089316c7c122d93a680cef0 Mon Sep 17 00:00:00 2001 From: Jochem Bruijns Date: Thu, 27 Jul 2023 13:59:38 +0200 Subject: [PATCH 1/5] Add workflow to publish image --- .github/workflows/docker-publish.yml | 96 ++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 .github/workflows/docker-publish.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..73da806 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,96 @@ +name: Docker + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +on: + schedule: + - cron: '27 16 * * *' + push: + branches: [ "main" ] + # Publish semver tags as releases. + tags: [ 'v*.*.*' ] + pull_request: + branches: [ "main" ] + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + # github.repository as / + IMAGE_NAME: ${{ github.repository }} + + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + # This is used to complete the identity challenge + # with sigstore/fulcio when running outside of PRs. + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Install the cosign tool except on PR + # https://github.com/sigstore/cosign-installer + - name: Install cosign + if: github.event_name != 'pull_request' + uses: sigstore/cosign-installer@f3c664df7af409cb4873aa5068053ba9d61a57b6 #v2.6.0 + with: + cosign-release: 'v1.13.1' + + + # Workaround: https://github.com/docker/build-push-action/issues/461 + - name: Setup Docker buildx + uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + + # Sign the resulting Docker image digest except on PRs. + # This will only write to the public Rekor transparency log when the Docker + # repository is public to avoid leaking data. If you would like to publish + # transparency data even for private images, pass --force to cosign below. + # https://github.com/sigstore/cosign + - name: Sign the published Docker image + if: ${{ github.event_name != 'pull_request' }} + env: + COSIGN_EXPERIMENTAL: "true" + # This step uses the identity token to provision an ephemeral certificate + # against the sigstore community Fulcio instance. + run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign {}@${{ steps.build-and-push.outputs.digest }} From edbb3c0a4cf7d8e06ae5c97415665f6d6b29fe6d Mon Sep 17 00:00:00 2001 From: Jochem Bruijns Date: Thu, 27 Jul 2023 14:01:55 +0200 Subject: [PATCH 2/5] Remove old workflow --- .github/workflows/push.yml | 47 -------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 .github/workflows/push.yml diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml deleted file mode 100644 index 3d2d007..0000000 --- a/.github/workflows/push.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: Build Docker image - -on: - push: - branches: - - master - tags: - - v* - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Get all git tags - run: git fetch --prune --unshallow --tags - - - uses: actions/setup-go@v3 - with: - go-version: '>=1.17.0' - - - name: Run tests - run: make test - - - uses: sonarsource/sonarqube-scan-action@master - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} - - - uses: sonarsource/sonarqube-quality-gate-action@master - timeout-minutes: 5 - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - - - name: Build image - run: make image - - - name: Sign in to Docker Hub - run: echo -n ${{secrets.DOCKER_HUB_PASSWORD}} | docker login -u ${{secrets.DOCKER_HUB_USERNAME}} --password-stdin - - - name: Push image to registry - run: make publish - - - name: Sign out from Docker Hub - if: always() - run: docker logout From 9333263882454f1dbfd5e0ef878e6ded5bb82c51 Mon Sep 17 00:00:00 2001 From: Jochem Bruijns Date: Thu, 27 Jul 2023 14:03:27 +0200 Subject: [PATCH 3/5] Rename branch in action to master --- .github/workflows/docker-publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 73da806..12f221d 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -9,11 +9,11 @@ on: schedule: - cron: '27 16 * * *' push: - branches: [ "main" ] + branches: [ "master" ] # Publish semver tags as releases. tags: [ 'v*.*.*' ] pull_request: - branches: [ "main" ] + branches: [ "master" ] env: # Use docker.io for Docker Hub if empty From 9852da47a9c7663b3218c40fde4d9e0d8cafcdf8 Mon Sep 17 00:00:00 2001 From: Jochem Bruijns Date: Thu, 27 Jul 2023 16:39:06 +0200 Subject: [PATCH 4/5] Remove github workflow pull_request.yml --- .github/workflows/pull_request.yml | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 .github/workflows/pull_request.yml diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml deleted file mode 100644 index 4a4a56a..0000000 --- a/.github/workflows/pull_request.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Check pull request - -on: - pull_request: - branches: - - master - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Get all git tags - run: git fetch --prune --unshallow --tags - - - uses: actions/setup-go@v3 - with: - go-version: '>=1.17.0' - - - name: Run tests - run: make test - - - name: Build Docker image - run: make image From c2ceba910a89c217fd22b1f462c3aa90ad5fc152 Mon Sep 17 00:00:00 2001 From: Jochem Bruijns Date: Mon, 11 Mar 2024 11:43:07 +0100 Subject: [PATCH 5/5] Fix docker container --- Dockerfile | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index fa4cf13..71b4c62 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,9 @@ -FROM golang:1.19 AS build +FROM golang:1.22 WORKDIR /app ADD . . RUN make build -FROM centurylink/ca-certs -MAINTAINER Daniel Martins - -COPY --from=build /app/bin/pingdom-exporter /pingdom-exporter -ENTRYPOINT ["/pingdom-exporter"] +ENTRYPOINT ["/app/bin/pingdom-exporter"] USER 65534:65534