Skip to content

Commit

Permalink
Make build static, fix release job
Browse files Browse the repository at this point in the history
  • Loading branch information
sergicastro committed Aug 12, 2024
1 parent 881f1f6 commit 34b58b5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
# Refer to https:/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"]
10 changes: 4 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand Down

0 comments on commit 34b58b5

Please sign in to comment.