Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make build static, fix release job #20

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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://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"]
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