diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..f699e24 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,60 @@ +name: Release + +on: + push: + +permissions: + # For uploading artifacts + contents: write + # For publishing images to ghcr.io + packages: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - + if: ${{ !startsWith(github.ref, 'refs/tags/v') }} + run: echo "flags=--snapshot" >> $GITHUB_ENV + - + name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.21.3' + cache: true + - + name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - + name: Run GoReleaser + uses: goreleaser/goreleaser-action@v4 + with: + distribution: goreleaser + version: latest + args: release --clean ${{ env.flags }} + env: + REGISTRY: ghcr.io/chatwork + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - + name: Upload assets + if: ${{ !startsWith(github.ref, 'refs/tags/v') }} + uses: actions/upload-artifact@v3 + with: + name: kibertas + path: | + dist/kibertas*.tar.gz diff --git a/.gitignore b/.gitignore index a8539d3..e235044 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ kibertas manifests/credentials.yaml .bin/ .vscode +dist/ diff --git a/Dockerfile b/Dockerfile index bec80ee..7cdd89e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,9 @@ -FROM golang:1.21 AS builder - -ENV CGO_ENABLED=0 - -WORKDIR /app - -COPY go.mod /app -COPY go.sum /app - -RUN go mod download - -COPY . . - -RUN go build -o kibertas . - FROM gcr.io/distroless/static-debian12 #FROM amazon/aws-cli:latest ARG TARGETOS ARG TARGETARCH -COPY --from=builder /app/kibertas /usr/local/bin/kibertas +COPY kibertas /usr/local/bin/kibertas ENTRYPOINT ["/usr/local/bin/kibertas"] diff --git a/Makefile b/Makefile index 3250484..0bd25a1 100644 --- a/Makefile +++ b/Makefile @@ -32,9 +32,12 @@ lint: test: go test -timeout 6m -v ./... +# This will produce following images for testing locally: +# - examplecom/kibertas:canary-arm64 +# - examplecom/kibertas:canary-amd64 .PHONY: goreleaser-snapshot goreleaser-snapshot: - curl -sfL https://goreleaser.com/static/run | bash -s -- --release --clean --snapshot + curl -sfL https://goreleaser.com/static/run | REGISTRY=examplecom bash -s -- --clean --snapshot .PHONY: create-kind create-kind: diff --git a/goreleaser.yml b/goreleaser.yml new file mode 100644 index 0000000..808e1f1 --- /dev/null +++ b/goreleaser.yml @@ -0,0 +1,70 @@ +project_name: kibertas +env: +builds: + - id: kibertas + main: ./ + env: + - CGO_ENABLED=0 + ldflags: + - -s -w + goos: + - darwin + - linux + goarch: + - amd64 + - arm64 + - "386" +changelog: + use: github-native + +release: + prerelease: auto + +dockers: + # https://goreleaser.com/customization/docker/ + - use: buildx + goos: linux + goarch: amd64 + image_templates: + - "{{ .Env.REGISTRY }}/{{ .ProjectName }}:canary-amd64" + - "{{ .Env.REGISTRY }}/{{ .ProjectName }}:{{ .Version }}-amd64" + - "{{ .Env.REGISTRY }}/{{ .ProjectName }}:{{ .Major }}-amd64" + - "{{ .Env.REGISTRY }}/{{ .ProjectName }}:{{ .Major }}.{{ .Minor }}-amd64" + build_flag_templates: + - "--platform=linux/amd64" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.title={{.ProjectName}}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" + - use: buildx + goos: linux + goarch: arm64 + image_templates: + - "{{ .Env.REGISTRY }}/{{ .ProjectName }}:canary-arm64" + - "{{ .Env.REGISTRY }}/{{ .ProjectName }}:{{ .Version }}-arm64" + - "{{ .Env.REGISTRY }}/{{ .ProjectName }}:{{ .Major }}-arm64" + - "{{ .Env.REGISTRY }}/{{ .ProjectName }}:{{ .Major }}.{{ .Minor }}-arm64" + build_flag_templates: + - "--platform=linux/arm64" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.title={{.ProjectName}}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" + +docker_manifests: + - name_template: "{{ .Env.REGISTRY }}/{{ .ProjectName }}:canary" + image_templates: + - "{{ .Env.REGISTRY }}/{{ .ProjectName }}:canary-amd64" + - "{{ .Env.REGISTRY }}/{{ .ProjectName }}:canary-arm64" + - name_template: "{{ .Env.REGISTRY }}/{{ .ProjectName }}:{{ .Version }}" + image_templates: + - "{{ .Env.REGISTRY }}/{{ .ProjectName }}:{{ .Version }}-amd64" + - "{{ .Env.REGISTRY }}/{{ .ProjectName }}:{{ .Version }}-arm64" + - name_template: "{{ .Env.REGISTRY }}/{{ .ProjectName }}:{{ .Major }}" + image_templates: + - "{{ .Env.REGISTRY }}/{{ .ProjectName }}:{{ .Major }}-amd64" + - "{{ .Env.REGISTRY }}/{{ .ProjectName }}:{{ .Major }}-arm64" + - name_template: "{{ .Env.REGISTRY }}/{{ .ProjectName }}:{{ .Major }}.{{ .Minor }}" + image_templates: + - "{{ .Env.REGISTRY }}/{{ .ProjectName }}:{{ .Major }}.{{ .Minor }}-amd64" + - "{{ .Env.REGISTRY }}/{{ .ProjectName }}:{{ .Major }}.{{ .Minor }}-arm64"