diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 08a0c26..1bec2b1 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -16,8 +16,11 @@ jobs: steps: - uses: docker/setup-qemu-action@v3 with: - platforms: amd64,arm64 + platforms: ${{ env.PLATFORMS }} - uses: docker/setup-buildx-action@v3 + id: setup-buildx + with: + platforms: ${{ env.PLATFORMS }} - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: @@ -27,4 +30,6 @@ jobs: with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - run: make docker-build-push + - env: + DOCKER_BUILDER_NAME: ${{ steps.setup-buildx.outputs.name }} + run: make docker-build-push diff --git a/Dockerfile b/Dockerfile index 1bda4ff..f85febf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,11 +4,10 @@ # Refer to https://github.com/GoogleContainerTools/distroless for more details FROM gcr.io/distroless/static:nonroot -ARG BUILDPLATFORM ARG TARGETPLATFORM WORKDIR / -COPY build/bin/${TARGETPLATFORM}/manager manager +COPY build/bin/${TARGETPLATFORM}/manager /manager USER 65532:65532 ENTRYPOINT ["/manager"] diff --git a/Makefile b/Makefile index 84194e3..0e295bb 100644 --- a/Makefile +++ b/Makefile @@ -87,18 +87,18 @@ build/%: PLATFORM=$(*) build/%: GOARCH=$(notdir $(PLATFORM)) build/%: GOOS=$(subst /,,$(dir $(PLATFORM))) build/%: ## Build manager binary for a specific platform. - GOOS=${GOOS} GOARCH=${GOARCH} go build -o build/bin/$(PLATFORM)/manager main.go + CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o build/bin/$(PLATFORM)/manager main.go .PHONY: run run: install ## Run a controller from your host. go run ./main.go -DOCKER_BUILDER_NAME=kubegres +DOCKER_BUILDER_NAME?=kubegres .PHONY: run docker-buildx: docker buildx inspect $(DOCKER_BUILDER_NAME) || \ docker buildx create --name $(DOCKER_BUILDER_NAME) --driver docker-container --driver-opt network=host \ - --buildkitd-flags '--allow-insecure-entitlement network.host' --platform linux/amd64,linux/arm64 + --buildkitd-flags '--allow-insecure-entitlement network.host' --platform ${PLATFORMS} #docker-build: test ## Build docker image with the manager. .PHONY: docker-build-push @@ -114,9 +114,7 @@ docker-build/%: PLATFORM=$(*) docker-build/%: DOCKER_OS=$(subst /,,$(dir $(PLATFORM))) docker-build/%: DOCKER_ARCH=$(notdir $(PLATFORM)) docker-build/%: docker-buildx ## Build docker image with ARCH as image tag suffix. - docker buildx build --builder $(DOCKER_BUILDER_NAME) --platform ${PLATFORM} \ - --build-arg TARGETOS=$(DOCKER_OS) --build-arg TARGETARCH=$(DOCKER_ARCH) \ - -t ${IMG}-${DOCKER_ARCH} --load . + docker buildx build --builder $(DOCKER_BUILDER_NAME) --platform ${PLATFORM} -t ${IMG}-${DOCKER_ARCH} --load . .PHONY: scan-local scan-local: IMG=local/kubegres:scan-${LOCAL_ARCH}