diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4b245d5f..3eb14de5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ on: - '**.md' env: - DOCKER_BUILDKIT: 1 + platforms: "linux/amd64,linux/arm64,linux/ppc64le,linux/s390x" concurrency: group: ${{ github.ref_name }}-ci @@ -55,17 +55,21 @@ jobs: steps: - name: Checkout Repository uses: actions/checkout@v2 + - name: Cache Go build + uses: actions/cache@v2 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-local-build-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go-local-build- - name: Setup Golang Environment uses: actions/setup-go@v2 with: go-version: ${{ needs.vars.outputs.go_version }} - name: Build Binary run: make build - - name: Cache Artifacts - uses: actions/cache@v2 - with: - path: ${{ github.workspace }}/bin/manager - key: nginx-ingress-operator-${{ github.run_id }}-${{ github.run_number }} unit-tests: name: Unit Tests @@ -78,27 +82,59 @@ jobs: uses: actions/setup-go@v2 with: go-version: ${{ needs.vars.outputs.go_version }} + - name: Cache Go tests + uses: actions/cache@v2 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-tests-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go-tests- - name: Run Tests run: make test build: name: Build Image runs-on: ubuntu-20.04 - needs: [binary, unit-tests] + needs: [binary, vars, unit-tests] steps: - name: Checkout Repository uses: actions/checkout@v2 - - name: Fetch Cached Artifacts + with: + fetch-depth: 0 + - name: Cache Go build uses: actions/cache@v2 with: - path: ${{ github.workspace }}/bin/manager - key: nginx-ingress-operator-${{ github.run_id }}-${{ github.run_number }} + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go-build- + - name: Setup Golang Environment + uses: actions/setup-go@v2 + with: + go-version: ${{ needs.vars.outputs.go_version }} + - name: Build binaries + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: ${{ !startsWith(github.ref, 'refs/tags/') && 'build --snapshot' || 'release' }} ${{ github.event_name == 'pull_request' && '--single-target' || '' }} --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GOPATH: ${{ needs.check.outputs.go_path }} - name: DockerHub Login uses: docker/login-action@v1 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} if: github.event_name != 'pull_request' + - name: Setup QEMU + uses: docker/setup-qemu-action@v1 + with: + platforms: arm64,ppc64le,s390x + if: github.event_name != 'pull_request' - name: Docker Buildx uses: docker/setup-buildx-action@v1 - name: Docker meta @@ -120,8 +156,10 @@ jobs: context: '.' cache-from: type=gha cache-to: type=gha,mode=max + target: goreleaser tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + platforms: ${{ github.event_name != 'pull_request' && env.platforms || '' }} load: ${{ github.event_name == 'pull_request' }} push: ${{ github.event_name != 'pull_request' }} pull: true diff --git a/.gitignore b/.gitignore index ddaa1373..3069b206 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ - # Binaries for programs and plugins *.exe *.exe~ @@ -24,3 +23,5 @@ testbin/* *.swo *~ .vscode/ + +dist diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 00000000..ecc99447 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,23 @@ +env: + - CGO_ENABLED=0 +builds: + - id: nginx-ingress-operator + goos: + - linux + goarch: + - amd64 + - arm64 + - ppc64le + - s390x + flags: + - -trimpath + gcflags: + - all=-trimpath={{.Env.GOPATH}} + asmflags: + - all=-trimpath={{.Env.GOPATH}} + binary: manager + +archives: +- format: binary +changelog: + skip: true diff --git a/Dockerfile b/Dockerfile index 1795cd13..08e2b7d1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,10 +18,9 @@ COPY controllers/ controllers/ # Build RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X main.version=${VERSION}" -a -o manager main.go -FROM registry.access.redhat.com/ubi8/ubi-minimal:latest +FROM registry.access.redhat.com/ubi8/ubi-minimal:latest as base ARG VERSION WORKDIR / -COPY --from=builder /workspace/manager . COPY config/crd/kic ./config/crd/kic COPY LICENSE /licenses/ @@ -35,3 +34,17 @@ LABEL name="NGINX Ingress Operator" \ ENTRYPOINT ["/manager"] USER 1001 + +FROM base as goreleaser +ARG TARGETARCH +ARG TARGETVARIANT + +LABEL org.nginx.kic.image.build.version="goreleaser" + +COPY ./dist/nginx-ingress-operator_linux_$TARGETARCH/manager / + +FROM base as local + +LABEL org.nginx.kic.image.build.version="local" + +COPY --from=builder /workspace/manager . diff --git a/Makefile b/Makefile index 0efb8ef0..960aaeff 100644 --- a/Makefile +++ b/Makefile @@ -106,7 +106,7 @@ run: manifests generate fmt vet ## Run a controller from your host. go run -ldflags "-X main.version=${VERSION}" ./main.go $(ARGS) docker-build: test ## Build docker image with the manager. - docker build -t ${IMG} -f ${DOCKERFILE} . --build-arg VERSION=${VERSION} + docker build -t ${IMG} -f ${DOCKERFILE} . --build-arg VERSION=${VERSION} --target local docker-push: ## Push docker image with the manager. docker push ${IMG}