From 31d2a111b9cd1942faab13a853168adb45739302 Mon Sep 17 00:00:00 2001 From: mrrishi Date: Thu, 5 Dec 2024 14:08:25 +0530 Subject: [PATCH] add goreleaser --- .github/workflows/publish-ecr.yaml | 34 --------------- .github/workflows/release-image.yaml | 35 +++++++++++++++ .goreleaser.yaml | 64 ++++++++++++++++++++++++++++ Dockerfile | 26 +---------- cmd/createSecret.go | 2 +- cmd/syncEcrToken.go | 2 +- cmd/waitFor.go | 2 +- go.mod | 2 +- internal/kubernetes/config.go | 2 +- internal/kubernetes/ecr.go | 2 +- main.go | 2 +- 11 files changed, 108 insertions(+), 65 deletions(-) delete mode 100644 .github/workflows/publish-ecr.yaml create mode 100644 .github/workflows/release-image.yaml create mode 100644 .goreleaser.yaml diff --git a/.github/workflows/publish-ecr.yaml b/.github/workflows/publish-ecr.yaml deleted file mode 100644 index feed677..0000000 --- a/.github/workflows/publish-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/kubernetes-toolkit:${{ github.ref_name }} diff --git a/.github/workflows/release-image.yaml b/.github/workflows/release-image.yaml new file mode 100644 index 0000000..eef65f8 --- /dev/null +++ b/.github/workflows/release-image.yaml @@ -0,0 +1,35 @@ +name: release container image +on: + push: + tags: + - '*' +permissions: + packages: write + +jobs: + gorelease: + name: build and push kubernetes-toolkit + runs-on: ubuntu-latest + 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..b5cf786 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,64 @@ +version: 2 +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - darwin + goarch: + - amd64 + - arm + - arm64 + tags: + - netgo + flags: + - -trimpath + ldflags: + - -s -w -extldflags "-static" + - -X github.com/konstructio/kubernetes-toolkit/internal/common.Version={{.Version}} + +dockers: + - image_templates: + - "ghcr.io/konstructio/kubernetes-toolkit:{{ .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/patrickdappollonio/{{ .ProjectName }}/releases/tag/v{{ .RawVersion }}" + - "--label=org.opencontainers.image.url=https://github.com/konstructio/{{ .ProjectName }}" + - "--label=org.opencontainers.image.source=https://github.com/konstructio/{{ .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/konstructio/kubernetes-toolkit:{{ .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/patrickdappollonio/{{ .ProjectName }}/releases/tag/v{{ .RawVersion }}" + - "--label=org.opencontainers.image.url=https://github.com/konstructio/{{ .ProjectName }}" + - "--label=org.opencontainers.image.source=https://github.com/konstructio/{{ .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/konstructio/kubernetes-toolkit:v{{ .RawVersion }}" + image_templates: + - "ghcr.io/konstructio/kubernetes-toolkit:{{ .Tag }}-amd64" + - "ghcr.io/konstructio/kubernetes-toolkit:{{ .Tag }}-arm64" + - name_template: "ghcr.io/konstructio/kubernetes-toolkit:v{{ .Major }}" + image_templates: + - "ghcr.io/konstructio/kubernetes-toolkit:{{ .Tag }}-amd64" + - "ghcr.io/konstructio/kubernetes-toolkit:{{ .Tag }}-arm64" + - name_template: "ghcr.io/konstructio/kubernetes-toolkit:latest" + image_templates: + - "ghcr.io/konstructio/kubernetes-toolkit:{{ .Tag }}-amd64" + - "ghcr.io/konstructio/kubernetes-toolkit:{{ .Tag }}-arm64" + diff --git a/Dockerfile b/Dockerfile index a0aa189..48adeb0 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 kubernetes-toolkit . - -# Build final image using nothing but the binary FROM alpine:3.17.2 -COPY --from=builder /build/kubernetes-toolkit / +COPY kubernetes-toolkit /usr/bin/ -# Command to run -ENTRYPOINT ["/kubernetes-toolkit"] \ No newline at end of file +ENTRYPOINT ["/usr/bin/kubernetes-toolkit"] diff --git a/cmd/createSecret.go b/cmd/createSecret.go index dbada27..2c9bdc3 100644 --- a/cmd/createSecret.go +++ b/cmd/createSecret.go @@ -1,7 +1,7 @@ package cmd import ( - "github.com/kubefirst/kubernetes-toolkit/internal/kubernetes" + "github.com/konstructio/kubernetes-toolkit/internal/kubernetes" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cmd/syncEcrToken.go b/cmd/syncEcrToken.go index 57e810b..c428f38 100644 --- a/cmd/syncEcrToken.go +++ b/cmd/syncEcrToken.go @@ -1,7 +1,7 @@ package cmd import ( - "github.com/kubefirst/kubernetes-toolkit/internal/kubernetes" + "github.com/konstructio/kubernetes-toolkit/internal/kubernetes" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cmd/waitFor.go b/cmd/waitFor.go index ce69669..694a9c4 100644 --- a/cmd/waitFor.go +++ b/cmd/waitFor.go @@ -10,7 +10,7 @@ import ( "time" "github.com/hashicorp/vault/api" - "github.com/kubefirst/kubernetes-toolkit/internal/kubernetes" + "github.com/konstructio/kubernetes-toolkit/internal/kubernetes" "github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7/pkg/credentials" log "github.com/sirupsen/logrus" diff --git a/go.mod b/go.mod index 909bad0..2dfb2e3 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/kubefirst/kubernetes-toolkit +module github.com/konstructio/kubernetes-toolkit go 1.20 diff --git a/internal/kubernetes/config.go b/internal/kubernetes/config.go index e071240..8043668 100644 --- a/internal/kubernetes/config.go +++ b/internal/kubernetes/config.go @@ -4,7 +4,7 @@ import ( "os" "path/filepath" - "github.com/kubefirst/kubernetes-toolkit/internal/common" + "github.com/konstructio/kubernetes-toolkit/internal/common" log "github.com/sirupsen/logrus" "github.com/spf13/afero" "k8s.io/client-go/kubernetes" diff --git a/internal/kubernetes/ecr.go b/internal/kubernetes/ecr.go index f4e81a4..2dd4bda 100644 --- a/internal/kubernetes/ecr.go +++ b/internal/kubernetes/ecr.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - awsinternal "github.com/kubefirst/kubernetes-toolkit/internal/aws" + awsinternal "github.com/konstructio/kubernetes-toolkit/internal/aws" log "github.com/sirupsen/logrus" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/main.go b/main.go index a9b5405..f378017 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,6 @@ package main -import "github.com/kubefirst/kubernetes-toolkit/cmd" +import "github.com/konstructio/kubernetes-toolkit/cmd" func main() { cmd.Execute()