Skip to content

Commit

Permalink
fix publish-via-docker for operator/cr (#685)
Browse files Browse the repository at this point in the history
* fix makefile for operator

* fix buildx builder
  • Loading branch information
Haleygo authored Jul 3, 2023
1 parent 44d20a7 commit c199848
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 54 deletions.
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ BINARY_NAME=vm-operator
REPO=github.com/VictoriaMetrics/operator
OPERATOR_BIN=operator-sdk
DOCKER_REPO=victoriametrics/operator
MANIFEST_BUILD_PLATFORM=linux/amd64,linux/arm,linux/arm64,linux/ppc64le,linux/386
TEST_ARGS=$(GOCMD) test -covermode=atomic -coverprofile=coverage.txt -v
APIS_BASE_PATH=api/v1beta1
YAML_DROP_PREF=spec.versions[0].schema.openAPIV3Schema.properties.spec.properties
Expand Down Expand Up @@ -380,25 +381,27 @@ package-arch:
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} $(GOBUILD) -o bin/manager-$(GOARCH) main.go


build-operator-crosscompile: build
build-operator-crosscompile: fmt vet
CGO_ENABLED=0 GOARCH=arm $(MAKE) package-arch
CGO_ENABLED=0 GOARCH=arm64 $(MAKE) package-arch
CGO_ENABLED=0 GOARCH=amd64 $(MAKE) package-arch
CGO_ENABLED=0 GOARCH=ppc64le $(MAKE) package-arch
CGO_ENABLED=0 GOARCH=386 $(MAKE) package-arch

docker-operator-crosscompile:
docker-operator-manifest-build-and-push:
export DOCKER_CLI_EXPERIMENTAL=enabled ;\
! ( docker buildx ls | grep operator-builder ) && docker buildx create --use --platform=$(MANIFEST_BUILD_PLATFORM) --name operator-builder ;\
docker buildx build \
--builder operator-builder \
-t $(DOCKER_REPO):$(TAG) \
-t $(DOCKER_REPO):latest \
--platform=linux/amd64,linux/arm,linux/arm64,linux/ppc64le,linux/386 \
--platform=$(MANIFEST_BUILD_PLATFORM) \
--build-arg base_image=$(ALPINE_IMAGE) \
-f Docker-multiarch \
--push \
.

publish-via-docker: build-operator-crosscompile
publish-via-docker: build-operator-crosscompile docker-operator-manifest-build-and-push


# builds image and loads it into kind.
Expand Down
4 changes: 2 additions & 2 deletions internal/config-reloader/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ ARG base_image
FROM ${base_image}
# src_binary arg must be in scope, after FROM

ARG ARCH
ARG TARGETARCH

ENV USER_UID=1001 \
USER_NAME=config-reloader

# install operator binary
COPY bin/config-reloader-${ARCH} /usr/local/bin/config-reloader
COPY bin/config-reloader-${TARGETARCH} /usr/local/bin/config-reloader

ENTRYPOINT ["/usr/local/bin/config-reloader"]

Expand Down
69 changes: 21 additions & 48 deletions internal/config-reloader/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
cr-docker-build-arch:
docker build -t $(DOCKER_REPO):config-reloader-$(TAG)-$(GOARCH) \
--build-arg ARCH=$(GOARCH) \
export DOCKER_CLI_EXPERIMENTAL=enabled ;\
docker buildx build -t $(DOCKER_REPO):config-reloader-$(TAG)-$(GOARCH) \
--platform=linux/$(GOARCH) \
--build-arg base_image=$(ALPINE_IMAGE) \
-f internal/config-reloader/Dockerfile .
-f internal/config-reloader/Dockerfile \
--load \
.

cr-package-arch:
GOOS=linux $(GOBUILD) -o bin/config-reloader-$(GOARCH) github.com/VictoriaMetrics/operator/internal/config-reloader/
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} $(GOBUILD) -o bin/config-reloader-$(GOARCH) github.com/VictoriaMetrics/operator/internal/config-reloader/


cr-build-operator-crosscompile:
Expand All @@ -15,50 +18,20 @@ cr-build-operator-crosscompile:
CGO_ENABLED=0 GOARCH=ppc64le $(MAKE) cr-package-arch
CGO_ENABLED=0 GOARCH=386 $(MAKE) cr-package-arch

docker-config-reloader-crosscompile: cr-build-operator-crosscompile
GOARCH=arm $(MAKE) cr-docker-build-arch
GOARCH=arm64 $(MAKE) cr-docker-build-arch
GOARCH=amd64 $(MAKE) cr-docker-build-arch
GOARCH=ppc64le $(MAKE) cr-docker-build-arch
GOARCH=386 $(MAKE) cr-docker-build-arch


docker-config-reloader-push-crosscompile: docker-config-reloader-crosscompile
docker push $(DOCKER_REPO):config-reloader-$(TAG)-arm
docker push $(DOCKER_REPO):config-reloader-$(TAG)-amd64
docker push $(DOCKER_REPO):config-reloader-$(TAG)-arm64
docker push $(DOCKER_REPO):config-reloader-$(TAG)-ppc64le
docker push $(DOCKER_REPO):config-reloader-$(TAG)-386

cr-package-manifest-annotate-goarch:
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest annotate $(DOCKER_REPO):config-reloader-$(TAG) \
$(DOCKER_REPO):config-reloader-$(TAG)-$(GOARCH) --os linux --arch $(GOARCH)


cr-docker-manifest: docker-config-reloader-push-crosscompile
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create --amend $(DOCKER_REPO):config-reloader-$(TAG) \
$(DOCKER_REPO):config-reloader-$(TAG)-amd64 \
$(DOCKER_REPO):config-reloader-$(TAG)-arm \
$(DOCKER_REPO):config-reloader-$(TAG)-arm64 \
$(DOCKER_REPO):config-reloader-$(TAG)-ppc64le \
$(DOCKER_REPO):config-reloader-$(TAG)-386
GOARCH=amd64 $(MAKE) cr-package-manifest-annotate-goarch
GOARCH=arm $(MAKE) cr-package-manifest-annotate-goarch
GOARCH=arm64 $(MAKE) cr-package-manifest-annotate-goarch
GOARCH=ppc64le $(MAKE) cr-package-manifest-annotate-goarch
GOARCH=386 $(MAKE) cr-package-manifest-annotate-goarch


publish-via-docker-config-reloader: cr-docker-manifest
docker tag $(DOCKER_REPO):config-reloader-$(TAG)-arm64 $(DOCKER_REPO):config-reloader-latest-arm64
docker tag $(DOCKER_REPO):config-reloader-$(TAG)-arm $(DOCKER_REPO):config-reloader-latest-arm
docker tag $(DOCKER_REPO):config-reloader-$(TAG)-386 $(DOCKER_REPO):config-reloader-latest-386
docker tag $(DOCKER_REPO):config-reloader-$(TAG)-ppc64le $(DOCKER_REPO):config-reloader-latest-ppc64le
docker tag $(DOCKER_REPO):config-reloader-$(TAG)-amd64 $(DOCKER_REPO):config-reloader-latest-amd64
TAG=latest $(MAKE) cr-docker-manifest
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push --purge $(DOCKER_REPO):config-reloader-$(TAG)
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push --purge $(DOCKER_REPO):config-reloader-latest

docker-config-reloader-manifest-build-and-push:
export DOCKER_CLI_EXPERIMENTAL=enabled ;\
! ( docker buildx ls | grep config-reloader-builder ) && docker buildx create --use --platform=$(MANIFEST_BUILD_PLATFORM) --name config-reloader-builder ;\
docker buildx build \
--builder config-reloader-builder \
-t $(DOCKER_REPO):config-reloader-$(TAG) \
-t $(DOCKER_REPO):config-reloader-latest \
--platform=$(MANIFEST_BUILD_PLATFORM) \
--build-arg base_image=$(ALPINE_IMAGE) \
-f internal/config-reloader/Dockerfile \
--push \
.

publish-via-docker-config-reloader: cr-build-operator-crosscompile docker-config-reloader-manifest-build-and-push

config-reloader-local:
GOARCH=amd64 CGO_ENABLED=0 $(MAKE) cr-package-arch
Expand Down

0 comments on commit c199848

Please sign in to comment.