diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 113e99f91a..900a13743a 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -43,6 +43,12 @@ jobs: - name: golangci-lint uses: reviewdog/action-golangci-lint@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + id: buildx + with: + install: true + - name: docker images build run: | make docker-build-all diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index cf8199d8d4..2e4cc0b466 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -53,9 +53,9 @@ jobs: - name: golangci-lint uses: reviewdog/action-golangci-lint@v1 - - name: docker images build + - name: docker images build (AMD64) run: | - make docker-build-all + make docker-build-all-amd64 - name : Create Kind Cluster and setup kustomize run: | diff --git a/.github/workflows/image.yaml b/.github/workflows/image.yaml index be6bed0367..911f17c0a6 100644 --- a/.github/workflows/image.yaml +++ b/.github/workflows/image.yaml @@ -21,6 +21,12 @@ jobs: - name: login to GitHub Container Registry run: echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + id: buildx + with: + install: true + - name: docker images publish run: | make docker-publish-all \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 3e1576e4ad..a93463d008 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -35,6 +35,12 @@ jobs: - name: login to GitHub Container Registry run: echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + id: buildx + with: + install: true + - name : docker images publish run: | make docker-publish-all diff --git a/Makefile b/Makefile index 1c9f8c2a68..90ad22fd95 100644 --- a/Makefile +++ b/Makefile @@ -31,24 +31,24 @@ INITC_IMAGE := kyvernopre initContainer: fmt vet GOOS=$(GOOS) go build -o $(PWD)/$(INITC_PATH)/kyvernopre -ldflags=$(LD_FLAGS) $(PWD)/$(INITC_PATH)/main.go -.PHONY: docker-build-initContainer docker-tag-repo-initContainer docker-push-initContainer +.PHONY: docker-build-initContainer docker-push-initContainer -docker-publish-initContainer: docker-build-initContainer docker-tag-repo-initContainer docker-push-initContainer +docker-publish-initContainer: docker-build-initContainer docker-push-initContainer docker-build-initContainer: - @docker build -f $(PWD)/$(INITC_PATH)/Dockerfile -t $(REPO)/$(INITC_IMAGE):$(IMAGE_TAG) . --build-arg LD_FLAGS=$(LD_FLAGS) + @docker buildx build --file $(PWD)/$(INITC_PATH)/Dockerfile --progress plane --platform linux/arm64,linux/amd64 --tag $(REPO)/$(INITC_IMAGE):$(IMAGE_TAG) . --build-arg LD_FLAGS=$(LD_FLAGS) -docker-tag-repo-initContainer: - @docker tag $(REPO)/$(INITC_IMAGE):$(IMAGE_TAG) $(REPO)/$(INITC_IMAGE):latest +docker-build-initContainer-amd64: + @docker build -f $(PWD)/$(INITC_PATH)/Dockerfile -t $(REPO)/$(INITC_IMAGE):$(IMAGE_TAG) . --build-arg LD_FLAGS=$(LD_FLAGS) --build-arg TARGETPLATFORM="linux/amd64" docker-push-initContainer: - @docker push $(REPO)/$(INITC_IMAGE):$(IMAGE_TAG) - @docker push $(REPO)/$(INITC_IMAGE):latest + @docker buildx build --file $(PWD)/$(INITC_PATH)/Dockerfile --progress plane --push --platform linux/arm64,linux/amd64 --tag $(REPO)/$(INITC_IMAGE):$(IMAGE_TAG) . + @docker buildx build --file $(PWD)/$(INITC_PATH)/Dockerfile --progress plane --push --platform linux/arm64,linux/amd64 --tag $(REPO)/$(INITC_IMAGE):latest . ################################## # KYVERNO CONTAINER ################################## -.PHONY: docker-build-kyverno docker-tag-repo-kyverno docker-push-kyverno +.PHONY: docker-build-kyverno docker-push-kyverno KYVERNO_PATH := cmd/kyverno KYVERNO_IMAGE := kyverno @@ -59,22 +59,21 @@ local: kyverno: fmt vet GOOS=$(GOOS) go build -o $(PWD)/$(KYVERNO_PATH)/kyverno -ldflags=$(LD_FLAGS) $(PWD)/$(KYVERNO_PATH)/main.go -docker-publish-kyverno: docker-build-kyverno docker-tag-repo-kyverno docker-push-kyverno +docker-publish-kyverno: docker-build-kyverno docker-push-kyverno docker-build-kyverno: - @docker build -f $(PWD)/$(KYVERNO_PATH)/Dockerfile -t $(REPO)/$(KYVERNO_IMAGE):$(IMAGE_TAG) . --build-arg LD_FLAGS=$(LD_FLAGS) + @docker buildx build --file $(PWD)/$(KYVERNO_PATH)/Dockerfile --progress plane --platform linux/arm64,linux/amd64 --tag $(REPO)/$(KYVERNO_IMAGE):$(IMAGE_TAG) . --build-arg LD_FLAGS=$(LD_FLAGS) docker-build-local-kyverno: CGO_ENABLED=0 GOOS=linux go build -o $(PWD)/$(KYVERNO_PATH)/kyverno -ldflags=$(LD_FLAGS) $(PWD)/$(KYVERNO_PATH)/main.go @docker build -f $(PWD)/$(KYVERNO_PATH)/localDockerfile -t $(REPO)/$(KYVERNO_IMAGE):$(IMAGE_TAG) $(PWD)/$(KYVERNO_PATH) -docker-tag-repo-kyverno: - @echo "docker tag $(REPO)/$(KYVERNO_IMAGE):$(IMAGE_TAG) $(REPO)/$(KYVERNO_IMAGE):latest" - @docker tag $(REPO)/$(KYVERNO_IMAGE):$(IMAGE_TAG) $(REPO)/$(KYVERNO_IMAGE):latest +docker-build-kyverno-amd64: + @docker build -f $(PWD)/$(KYVERNO_PATH)/Dockerfile -t $(REPO)/$(KYVERNO_IMAGE):$(IMAGE_TAG) . --build-arg LD_FLAGS=$(LD_FLAGS) --build-arg TARGETPLATFORM="linux/amd64" docker-push-kyverno: - @docker push $(REPO)/$(KYVERNO_IMAGE):$(IMAGE_TAG) - @docker push $(REPO)/$(KYVERNO_IMAGE):latest + @docker buildx build --file $(PWD)/$(KYVERNO_PATH)/Dockerfile --progress plane --push --platform linux/arm64,linux/amd64 --tag $(REPO)/$(KYVERNO_IMAGE):$(IMAGE_TAG) . + @docker buildx build --file $(PWD)/$(KYVERNO_PATH)/Dockerfile --progress plane --push --platform linux/arm64,linux/amd64 --tag $(REPO)/$(KYVERNO_IMAGE):latest . ################################## @@ -88,32 +87,31 @@ generate-api-docs: ################################## # CLI ################################## -.PHONY: docker-build-cli docker-tag-repo-cli docker-push-cli +.PHONY: docker-build-cli docker-push-cli CLI_PATH := cmd/cli/kubectl-kyverno KYVERNO_CLI_IMAGE := kyverno-cli cli: GOOS=$(GOOS) go build -o $(PWD)/$(CLI_PATH)/kyverno -ldflags=$(LD_FLAGS) $(PWD)/$(CLI_PATH)/main.go -docker-publish-cli: docker-build-cli docker-tag-repo-cli docker-push-cli +docker-publish-cli: docker-build-cli docker-push-cli docker-build-cli: - @docker build -f $(PWD)/$(CLI_PATH)/Dockerfile -t $(REPO)/$(KYVERNO_CLI_IMAGE):$(IMAGE_TAG) . --build-arg LD_FLAGS=$(LD_FLAGS) + @docker buildx build --file $(PWD)/$(CLI_PATH)/Dockerfile --progress plane --platform linux/arm64,linux/amd64 --tag $(REPO)/$(KYVERNO_CLI_IMAGE):$(IMAGE_TAG) . --build-arg LD_FLAGS=$(LD_FLAGS) -docker-tag-repo-cli: - @echo "docker tag $(REPO)/$(KYVERNO_CLI_IMAGE):$(IMAGE_TAG) $(REPO)/$(KYVERNO_CLI_IMAGE):latest" - @docker tag $(REPO)/$(KYVERNO_CLI_IMAGE):$(IMAGE_TAG) $(REPO)/$(KYVERNO_CLI_IMAGE):latest +docker-build-cli-amd64: + @docker build -f $(PWD)/$(CLI_PATH)/Dockerfile -t $(REPO)/$(KYVERNO_CLI_IMAGE):$(IMAGE_TAG) . --build-arg LD_FLAGS=$(LD_FLAGS) --build-arg TARGETPLATFORM="linux/amd64" docker-push-cli: - @docker push $(REPO)/$(KYVERNO_CLI_IMAGE):$(IMAGE_TAG) - @docker push $(REPO)/$(KYVERNO_CLI_IMAGE):latest + @docker buildx build --file $(PWD)/$(CLI_PATH)/Dockerfile --progress plane --push --platform linux/arm64,linux/amd64 --tag $(REPO)/$(KYVERNO_CLI_IMAGE):$(IMAGE_TAG) . + @docker buildx build --file $(PWD)/$(CLI_PATH)/Dockerfile --progress plane --push --platform linux/arm64,linux/amd64 --tag $(REPO)/$(KYVERNO_CLI_IMAGE):latest . ################################## docker-publish-all: docker-publish-initContainer docker-publish-kyverno docker-publish-cli docker-build-all: docker-build-initContainer docker-build-kyverno docker-build-cli -docker-tag-all: docker-tag-repo-initContainer docker-tag-repo-kyverno docker-tag-repo-cli +docker-build-all-amd64: docker-build-initContainer-amd64 docker-build-kyverno-amd64 docker-build-cli-amd64 ################################## # Create e2e Infrastruture diff --git a/cmd/cli/kubectl-kyverno/Dockerfile b/cmd/cli/kubectl-kyverno/Dockerfile index 4a1f4d6ffe..001153de57 100644 --- a/cmd/cli/kubectl-kyverno/Dockerfile +++ b/cmd/cli/kubectl-kyverno/Dockerfile @@ -6,11 +6,17 @@ LABEL maintainer="Kyverno" # LD_FLAGS is passed as argument from Makefile. It will be empty, if no argument passed ARG LD_FLAGS +ARG TARGETPLATFORM ADD . /kyverno WORKDIR /kyverno -RUN CGO_ENABLED=0 GOOS=linux go build -o /output/kyverno -ldflags="${LD_FLAGS}" -v ./cmd/cli/kubectl-kyverno/ +RUN export GOOS=$(echo ${TARGETPLATFORM} | cut -d / -f1) && \ + export GOARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) + +RUN go env + +RUN CGO_ENABLED=0 go build -o /output/kyverno -ldflags="${LD_FLAGS}" -v ./cmd/cli/kubectl-kyverno/ RUN useradd -u 10001 kyverno diff --git a/cmd/initContainer/Dockerfile b/cmd/initContainer/Dockerfile index 3c010fa686..8dde90a737 100644 --- a/cmd/initContainer/Dockerfile +++ b/cmd/initContainer/Dockerfile @@ -6,11 +6,17 @@ LABEL maintainer="Kyverno" # LD_FLAGS is passed as argument from Makefile. It will be empty, if no argument passed ARG LD_FLAGS +ARG TARGETPLATFORM ADD . /kyverno WORKDIR /kyverno -RUN CGO_ENABLED=0 GOOS=linux go build -o /output/kyvernopre -ldflags="${LD_FLAGS}" -v ./cmd/initContainer/ +RUN export GOOS=$(echo ${TARGETPLATFORM} | cut -d / -f1) && \ + export GOARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) + +RUN go env + +RUN CGO_ENABLED=0 go build -o /output/kyvernopre -ldflags="${LD_FLAGS}" -v ./cmd/initContainer/ RUN useradd -u 10001 kyverno diff --git a/cmd/kyverno/Dockerfile b/cmd/kyverno/Dockerfile index a0ba646730..e4f4f4bfc8 100644 --- a/cmd/kyverno/Dockerfile +++ b/cmd/kyverno/Dockerfile @@ -6,11 +6,17 @@ LABEL maintainer="Kyverno" # LD_FLAGS is passed as argument from Makefile. It will be empty, if no argument passed ARG LD_FLAGS +ARG TARGETPLATFORM ADD . /kyverno WORKDIR /kyverno -RUN CGO_ENABLED=0 GOOS=linux go build -o /output/kyverno -ldflags="${LD_FLAGS}" -v ./cmd/kyverno/ +RUN export GOOS=$(echo ${TARGETPLATFORM} | cut -d / -f1) && \ + export GOARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) + +RUN go env + +RUN CGO_ENABLED=0 go build -o /output/kyverno -ldflags="${LD_FLAGS}" -v ./cmd/kyverno/ RUN useradd -u 10001 kyverno