diff --git a/.github/workflows/docker-build-stage.yaml b/.github/workflows/docker-build-stage.yaml index 69d3a7ab..a9e3b68d 100644 --- a/.github/workflows/docker-build-stage.yaml +++ b/.github/workflows/docker-build-stage.yaml @@ -11,46 +11,28 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - name: Login to DockerHub uses: docker/login-action@v1 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Docker meta for Testkube operator - id: meta_testkube_operator - uses: docker/metadata-action@v3 - with: - images: kubeshop/testkube-operator - tags: | - type=sha - - - name: Build - uses: docker/bake-action@v1 - with: - files: | - docker-bake.hcl - ${{ steps.meta_testkube_operator.outputs.bake-file }} - targets: build - push: true - - name: Output commit sha id: github_sha run: echo "::set-output name=sha_short::${GITHUB_SHA::7}" - - name: Docker meta for Testkube certificate image - id: meta_testkube_certificate - uses: docker/metadata-action@v3 + - name: Build images with GoReleaser + uses: goreleaser/goreleaser-action@v4 with: - images: kubeshop/testkube-certificate - tags: | - type=sha + distribution: goreleaser + version: latest + args: release -f .goreleaser-stage.yaml --snapshot + env: + GITHUB_TOKEN: ${{ secrets.CI_BOT_TOKEN }} + + - name: Push Docker images + run: | + docker push kubeshop/testkube-operator:${{ steps.github_sha.outputs.sha_short }} #Trigger Helm repo workflow to deploy Dashboard to Stage cluster - name: Repository Dispatch @@ -59,4 +41,4 @@ jobs: token: ${{ secrets.CI_BOT_TOKEN }} repository: kubeshop/helm-charts event-type: trigger-workflow-operator - client-payload: '{"image_tag_operator": "sha-${{ steps.github_sha.outputs.sha_short }}"}' + client-payload: '{"image_tag_operator": "${{ steps.github_sha.outputs.sha_short }}"}' diff --git a/.github/workflows/docker-build.yaml b/.github/workflows/docker-build.yaml index ac86732d..d9b19808 100644 --- a/.github/workflows/docker-build.yaml +++ b/.github/workflows/docker-build.yaml @@ -1,4 +1,4 @@ -name: Docker images building and pushing +name: Docker images building and pushing with GoReleaser on: push: tags: @@ -11,48 +11,23 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 + with: + fetch-depth: 0 - name: Set up QEMU uses: docker/setup-qemu-action@v1 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - name: Login to DockerHub - uses: docker/login-action@v1 + uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Docker meta for Testkube operator - id: meta_testkube_operator - uses: docker/metadata-action@v3 - with: - images: kubeshop/testkube-operator - tags: | - type=ref,event=branch - type=ref,event=pr - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=sha - - - name: Build - uses: docker/bake-action@v1 - with: - files: | - docker-bake.hcl - ${{ steps.meta_testkube_operator.outputs.bake-file }} - targets: build - push: true - - - name: Docker meta for Testkube certificate - id: meta_testkube_certificate - uses: docker/metadata-action@v3 + - name: Release + uses: goreleaser/goreleaser-action@v4 with: - images: kubeshop/testkube-certificate - tags: | - type=ref,event=branch - type=ref,event=pr - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=sha + distribution: goreleaser + version: latest + args: release -f .goreleaser.yml + env: + GITHUB_TOKEN: ${{ secrets.CI_BOT_TOKEN }} \ No newline at end of file diff --git a/.goreleaser-stage.yaml b/.goreleaser-stage.yaml new file mode 100644 index 00000000..a5e38003 --- /dev/null +++ b/.goreleaser-stage.yaml @@ -0,0 +1,23 @@ +project_name: testkube-operator +builds: + - id: "linux" + env: [CGO_ENABLED=0] + goos: + - linux + goarch: + - amd64 + mod_timestamp: "{{ .CommitTimestamp }}" +dockers: + - dockerfile: Dockerfile + use: buildx + goos: linux + goarch: amd64 + image_templates: + - "kubeshop/testkube-operator:{{ .ShortCommit }}" + build_flag_templates: + - "--platform=linux/amd64" + - "--label=org.opencontainers.image.title={{ .ProjectName }}" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + + diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 00000000..2161d5a7 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,56 @@ +project_name: testkube-operator +builds: + - id: "linux" + env: [CGO_ENABLED=0] + goos: + - linux + goarch: + - amd64 + - arm64 + mod_timestamp: "{{ .CommitTimestamp }}" +dockers: + - dockerfile: Dockerfile + use: buildx + goos: linux + goarch: amd64 + image_templates: + - "kubeshop/testkube-operator:{{ .ShortCommit }}-amd64" + - "kubeshop/testkube-operator:{{ .Version }}-amd64" + - "kubeshop/testkube-operator:latest-amd64" + build_flag_templates: + - "--platform=linux/amd64" + - "--label=org.opencontainers.image.title={{ .ProjectName }}" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" + + - dockerfile: Dockerfile + use: buildx + goos: linux + goarch: arm64 + image_templates: + - "kubeshop/testkube-operator:{{ .ShortCommit }}-arm64v8" + - "kubeshop/testkube-operator:{{ .Version }}-arm64v8" + - "kubeshop/testkube-operator:latest-arm64v8" + build_flag_templates: + - "--platform=linux/arm64/v8" + - "--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: kubeshop/testkube-operator:{{ .ShortCommit }} + image_templates: + - kubeshop/testkube-operator:{{ .ShortCommit }}-amd64 + - kubeshop/testkube-operator:{{ .ShortCommit }}-arm64v8 + - name_template: kubeshop/testkube-operator:{{ .Version }} + image_templates: + - kubeshop/testkube-operator:{{ .Version }}-amd64 + - kubeshop/testkube-operator:{{ .Version }}-arm64v8 + - name_template: kubeshop/testkube-operator:latest + image_templates: + - kubeshop/testkube-operator:latest-amd64 + - kubeshop/testkube-operator:latest-arm64v8 + + diff --git a/Dockerfile b/Dockerfile index a27074c6..ffded64b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,33 +1,3 @@ -# Build the manager binary -FROM --platform=$BUILDPLATFORM golang:1.18 as builder - -ENV CGO_ENABLED=0 -ENV GOOS=linux - -WORKDIR /workspace -# Copy the Go Modules manifests -COPY go.mod go.mod -COPY go.sum go.sum -# cache deps before building and copying source so that we don't need to re-download as much -# and so that source changes don't invalidate our downloaded layer -RUN go mod download - -# Copy the go source -COPY main.go main.go -COPY apis/ apis/ -COPY controllers/ controllers/ -COPY pkg/ pkg/ -COPY utils/ utils/ - -ARG TARGETOS TARGETARCH -# Build -RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -a -o manager main.go - -# Use distroless as minimal base image to package the manager binary -# Refer to https://github.com/GoogleContainerTools/distroless for more details -FROM gcr.io/distroless/static:nonroot -WORKDIR / -COPY --from=builder /workspace/manager . -USER 65532:65532 - +FROM alpine +COPY testkube-operator /manager ENTRYPOINT ["/manager"] diff --git a/docker-bake.hcl b/docker-bake.hcl deleted file mode 100644 index de64d45e..00000000 --- a/docker-bake.hcl +++ /dev/null @@ -1,12 +0,0 @@ -// docker-bake.hcl -target "docker-metadata-action" {} - -target "build" { - inherits = ["docker-metadata-action"] - context = "./" - dockerfile = "Dockerfile" - platforms = [ - "linux/amd64", - "linux/arm64" - ] -}