From d5c635420ddde178f58571a1f7b603361c046fad Mon Sep 17 00:00:00 2001 From: mrrishi Date: Thu, 19 Dec 2024 19:44:46 +0530 Subject: [PATCH 1/4] feat: add multi arch build --- .github/workflows/public-ecr.yaml | 34 --------------- .github/workflows/release-image.yaml | 34 +++++++++++++++ .goreleaser.yaml | 62 ++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 34 deletions(-) delete mode 100644 .github/workflows/public-ecr.yaml create mode 100644 .github/workflows/release-image.yaml create mode 100644 .goreleaser.yaml diff --git a/.github/workflows/public-ecr.yaml b/.github/workflows/public-ecr.yaml deleted file mode 100644 index d236277..0000000 --- a/.github/workflows/public-ecr.yaml +++ /dev/null @@ -1,34 +0,0 @@ -name: ci -on: - push: - tags: - - '*' -jobs: - buildx: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: us-east-1 - - - name: Login to Amazon ECR Public - id: login-ecr-public - uses: aws-actions/amazon-ecr-login@v1 - with: - registry-type: public - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - with: - platforms: linux/amd64,linux/arm64 - - name: Build and push - uses: docker/build-push-action@v3 - with: - context: "{{defaultContext}}" - push: true - tags: public.ecr.aws/kubefirst/metrics-client:${{ github.ref_name }} diff --git a/.github/workflows/release-image.yaml b/.github/workflows/release-image.yaml new file mode 100644 index 0000000..79443d1 --- /dev/null +++ b/.github/workflows/release-image.yaml @@ -0,0 +1,34 @@ +name: release container image + +on: + push: + tags: + - '*' + +jobs: + gorelease: + name: build and push metrics-client + runs-on: ubuntu-24.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - name: Login to Github Container Registry + uses: docker/login-action@v3 + with: + registry: "ghcr.io" + username: ${{ github.actor }} + password: ${{ secrets.TOKEN }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Release container image to Github + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.TOKEN }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..5d1bd32 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,62 @@ +version: 2 + +builds: + - env: + - CGO_ENABLED=0 + - goos: + - linux + - goarch: + - amd64 + - arm + - arm64 + tags: + - netgo + flags: + - -trimpath + ldflags: + - -s -w -extldflags "-static" + +dockers: + - image_templates: + - "ghcr.io/kubefirst/metrics-client:{{ .Tag }}-amd64" + goos: linux + goarch: amd64 + use: buildx + build_flag_templates: + - "--platform=linux/amd64" + - "--label=org.opencontainers.image.title={{ .ProjectName }}" + - "--label=org.opencontainers.image.description={{ .ProjectName }} version {{ .Version }}. See release notes at https://github.com/kubefirst/{{ .ProjectName }}/releases/tag/v{{ .RawVersion }}" + - "--label=org.opencontainers.image.url=https://github.com/kubefirst/{{ .ProjectName }}" + - "--label=org.opencontainers.image.source=https://github.com/kubefirst/{{ .ProjectName }}" + - "--label=org.opencontainers.image.version={{ .Version }}" + - '--label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}' + - "--label=org.opencontainers.image.revision={{ .FullCommit }}" + + - image_templates: + - "ghcr.io/kubefirst/metrics-client:{{ .Tag }}-arm64" + goos: linux + goarch: arm64 + use: buildx + build_flag_templates: + - "--platform=linux/arm64" + - "--label=org.opencontainers.image.title={{ .ProjectName }}" + - "--label=org.opencontainers.image.description={{ .ProjectName }} version {{ .Version }}. See release notes at https://github.com/kubefirst/{{ .ProjectName }}/releases/tag/v{{ .RawVersion }}" + - "--label=org.opencontainers.image.url=https://github.com/kubefirst/{{ .ProjectName }}" + - "--label=org.opencontainers.image.source=https://github.com/kubefirst/{{ .ProjectName }}" + - "--label=org.opencontainers.image.version={{ .Version }}" + - '--label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}' + - "--label=org.opencontainers.image.revision={{ .FullCommit }}" + +docker_manifests: + - name_template: "ghcr.io/kubefirst/metrics-client:v{{ .RawVersion }}" + image_templates: + - "ghcr.io/kubefirst/metrics-client:{{ .Tag }}-amd64" + - "ghcr.io/kubefirst/metrics-client:{{ .Tag }}-arm64" + - name_template: "ghcr.io/kubefirst/metrics-client:v{{ .Major }}" + image_templates: + - "ghcr.io/kubefirst/metrics-client:{{ .Tag }}-amd64" + - "ghcr.io/kubefirst/metrics-client:{{ .Tag }}-arm64" + - name_template: "ghcr.io/kubefirst/metrics-client:latest" + image_templates: + - "ghcr.io/kubefirst/metrics-client:{{ .Tag }}-amd64" + - "ghcr.io/kubefirst/metrics-client:{{ .Tag }}-arm64" From 4d24392e465a08da4e20a85ca65ba2cabf1cab35 Mon Sep 17 00:00:00 2001 From: mrrishi Date: Thu, 19 Dec 2024 19:46:54 +0530 Subject: [PATCH 2/4] add test goreleaser --- .github/workflows/test-goreleaser.yaml | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/test-goreleaser.yaml diff --git a/.github/workflows/test-goreleaser.yaml b/.github/workflows/test-goreleaser.yaml new file mode 100644 index 0000000..3e42050 --- /dev/null +++ b/.github/workflows/test-goreleaser.yaml @@ -0,0 +1,31 @@ +name: Testing +on: + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + test-app: + name: Test Application + runs-on: ubuntu-24.04 + steps: + - name: Clone repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - name: Test application + run: go test ./... + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Dry-run goreleaser application + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser + version: ~> v2 + args: release --snapshot --skip=publish --clean From 32cc2e627184d07831fe30bba25c5b50340d8012 Mon Sep 17 00:00:00 2001 From: mrrishi Date: Thu, 19 Dec 2024 19:51:36 +0530 Subject: [PATCH 3/4] fix Dockerfile --- Dockerfile | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/Dockerfile b/Dockerfile index e2235ba..dae18d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,5 @@ -FROM golang:alpine AS builder - -ENV GO111MODULE=on \ - CGO_ENABLED=0 \ - GOOS=linux \ - GOARCH=amd64 - -WORKDIR /build - -# Download go dependencies -COPY go.mod . -COPY go.sum . -RUN go mod download - -# Copy into the container -COPY . . - -# Build the application -RUN go build -o metrics-client . - -# Build final image using nothing but the binary FROM alpine:3.17.2 -COPY --from=builder /build/metrics-client / +COPY metrics-client /usr/bin/ -# Command to run -ENTRYPOINT ["/metrics-client"] \ No newline at end of file +ENTRYPOINT ["/usr/bin/metrics-client"] From 133bbf1bda8d7a5618e1903846c81cc4d40a8e9a Mon Sep 17 00:00:00 2001 From: mrrishi Date: Thu, 19 Dec 2024 20:02:42 +0530 Subject: [PATCH 4/4] fix goreleaser --- .goreleaser.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 5d1bd32..269e44c 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -3,12 +3,12 @@ version: 2 builds: - env: - CGO_ENABLED=0 - - goos: - - linux - - goarch: - - amd64 - - arm - - arm64 + goos: + - linux + goarch: + - amd64 + - arm + - arm64 tags: - netgo flags: