From 52fc4fce8239962d152af0d21f453166d36dbfc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Fatay=20G=C3=BCrt=C3=BCrk?= <963018+cagataygurturk@users.noreply.github.com> Date: Sat, 9 Nov 2024 00:53:54 +0100 Subject: [PATCH 1/7] Create build.yaml --- .github/workflows/build.yaml | 69 ++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 .github/workflows/build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..d93104c --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,69 @@ +name: Docker +on: + push: + branches: [ "main" ] + tags: [ 'v*.*.*' ] + pull_request: + branches: [ "main" ] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install cosign + if: github.event_name != 'pull_request' + uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0 + with: + cosign-release: 'v2.2.4' + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 + + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 + 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 + platforms: "linux/amd64,linux/arm64" + outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=gce_metadata_server + + - name: Sign the published Docker image + if: ${{ github.event_name != 'pull_request' }} + env: + TAGS: ${{ steps.meta.outputs.tags }} + DIGEST: ${{ steps.build-and-push.outputs.digest }} + run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} From ca6fb32b56ad6efafd56638eb4fc0a846e358936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Fatay=20G=C3=BCrt=C3=BCrk?= <963018+cagataygurturk@users.noreply.github.com> Date: Sat, 9 Nov 2024 00:55:10 +0100 Subject: [PATCH 2/7] Update Dockerfile --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index ca1ee4e..655672a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,14 @@ # go1.22.2 linux/amd64 -FROM docker.io/golang@sha256:d5302d40dc5fbbf38ec472d1848a9d2391a13f93293a6a5b0b87c99dc0eaa6ae as build +FROM --platform=$BUILDPLATFORM docker.io/golang@sha256:d5302d40dc5fbbf38ec472d1848a9d2391a13f93293a6a5b0b87c99dc0eaa6ae as build WORKDIR /go/src/app COPY . . RUN go mod download -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -buildvcs=false -o /go/bin/gce_metadata_server cmd/main.go +RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -buildvcs=false -o /go/bin/gce_metadata_server cmd/main.go RUN chown root:root /go/bin/gce_metadata_server # base-debian11-root FROM gcr.io/distroless/base@sha256:b31a6e02605827e77b7ebb82a0ac9669ec51091edd62c2c076175e05556f4ab9 COPY --from=build /go/bin/gce_metadata_server /gce_metadata_server EXPOSE 8080 -ENTRYPOINT [ "/gce_metadata_server" ] \ No newline at end of file +ENTRYPOINT [ "/gce_metadata_server" ] From 8807f9b7e7c3d5370ce975f3ae2a7ccb45702a3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Fatay=20G=C3=BCrt=C3=BCrk?= <963018+cagataygurturk@users.noreply.github.com> Date: Sat, 9 Nov 2024 00:56:43 +0100 Subject: [PATCH 3/7] Update build.yaml --- .github/workflows/build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index d93104c..6b4f74b 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,10 +1,10 @@ name: Docker on: push: - branches: [ "main" ] + branches: [ "master" ] tags: [ 'v*.*.*' ] pull_request: - branches: [ "main" ] + branches: [ "master" ] env: REGISTRY: ghcr.io From a06e3123f9be2be477d6c54ccecc310f3d6c71da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cagatay=20G=C3=BCrt=C3=BCrk?= <963018+cagataygurturk@users.noreply.github.com> Date: Sat, 9 Nov 2024 01:31:51 +0100 Subject: [PATCH 4/7] Revert "Update build.yaml" This reverts commit 8807f9b7e7c3d5370ce975f3ae2a7ccb45702a3f. --- .github/workflows/build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 6b4f74b..d93104c 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,10 +1,10 @@ name: Docker on: push: - branches: [ "master" ] + branches: [ "main" ] tags: [ 'v*.*.*' ] pull_request: - branches: [ "master" ] + branches: [ "main" ] env: REGISTRY: ghcr.io From e9bdc8e9026cc956462f9efce54f51f11d871bb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cagatay=20G=C3=BCrt=C3=BCrk?= <963018+cagataygurturk@users.noreply.github.com> Date: Sat, 9 Nov 2024 01:31:51 +0100 Subject: [PATCH 5/7] Revert "Update Dockerfile" This reverts commit ca6fb32b56ad6efafd56638eb4fc0a846e358936. --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 655672a..ca1ee4e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,14 @@ # go1.22.2 linux/amd64 -FROM --platform=$BUILDPLATFORM docker.io/golang@sha256:d5302d40dc5fbbf38ec472d1848a9d2391a13f93293a6a5b0b87c99dc0eaa6ae as build +FROM docker.io/golang@sha256:d5302d40dc5fbbf38ec472d1848a9d2391a13f93293a6a5b0b87c99dc0eaa6ae as build WORKDIR /go/src/app COPY . . RUN go mod download -RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -buildvcs=false -o /go/bin/gce_metadata_server cmd/main.go +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -buildvcs=false -o /go/bin/gce_metadata_server cmd/main.go RUN chown root:root /go/bin/gce_metadata_server # base-debian11-root FROM gcr.io/distroless/base@sha256:b31a6e02605827e77b7ebb82a0ac9669ec51091edd62c2c076175e05556f4ab9 COPY --from=build /go/bin/gce_metadata_server /gce_metadata_server EXPOSE 8080 -ENTRYPOINT [ "/gce_metadata_server" ] +ENTRYPOINT [ "/gce_metadata_server" ] \ No newline at end of file From 8e8d14671f201fa5104e5fed0f681ee33bc60717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cagatay=20G=C3=BCrt=C3=BCrk?= <963018+cagataygurturk@users.noreply.github.com> Date: Sat, 9 Nov 2024 01:31:51 +0100 Subject: [PATCH 6/7] Revert "Create build.yaml" This reverts commit 52fc4fce8239962d152af0d21f453166d36dbfc6. --- .github/workflows/build.yaml | 69 ------------------------------------ 1 file changed, 69 deletions(-) delete mode 100644 .github/workflows/build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml deleted file mode 100644 index d93104c..0000000 --- a/.github/workflows/build.yaml +++ /dev/null @@ -1,69 +0,0 @@ -name: Docker -on: - push: - branches: [ "main" ] - tags: [ 'v*.*.*' ] - pull_request: - branches: [ "main" ] - -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} - - -jobs: - build: - - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - id-token: write - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Install cosign - if: github.event_name != 'pull_request' - uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0 - with: - cosign-release: 'v2.2.4' - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 - - - name: Log into registry ${{ env.REGISTRY }} - if: github.event_name != 'pull_request' - uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Extract Docker metadata - id: meta - uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - - name: Build and push Docker image - id: build-and-push - uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 - 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 - platforms: "linux/amd64,linux/arm64" - outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=gce_metadata_server - - - name: Sign the published Docker image - if: ${{ github.event_name != 'pull_request' }} - env: - TAGS: ${{ steps.meta.outputs.tags }} - DIGEST: ${{ steps.build-and-push.outputs.digest }} - run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} From 5dc96990f202d05f6f7b778213c7c61635a3bf6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Fatay=20G=C3=BCrt=C3=BCrk?= <963018+cagataygurturk@users.noreply.github.com> Date: Sat, 9 Nov 2024 00:55:10 +0100 Subject: [PATCH 7/7] Update Dockerfile (cherry picked from commit ca6fb32b56ad6efafd56638eb4fc0a846e358936) --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index ca1ee4e..655672a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,14 @@ # go1.22.2 linux/amd64 -FROM docker.io/golang@sha256:d5302d40dc5fbbf38ec472d1848a9d2391a13f93293a6a5b0b87c99dc0eaa6ae as build +FROM --platform=$BUILDPLATFORM docker.io/golang@sha256:d5302d40dc5fbbf38ec472d1848a9d2391a13f93293a6a5b0b87c99dc0eaa6ae as build WORKDIR /go/src/app COPY . . RUN go mod download -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -buildvcs=false -o /go/bin/gce_metadata_server cmd/main.go +RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -buildvcs=false -o /go/bin/gce_metadata_server cmd/main.go RUN chown root:root /go/bin/gce_metadata_server # base-debian11-root FROM gcr.io/distroless/base@sha256:b31a6e02605827e77b7ebb82a0ac9669ec51091edd62c2c076175e05556f4ab9 COPY --from=build /go/bin/gce_metadata_server /gce_metadata_server EXPOSE 8080 -ENTRYPOINT [ "/gce_metadata_server" ] \ No newline at end of file +ENTRYPOINT [ "/gce_metadata_server" ]