Skip to content

Commit 2c1dd07

Browse files
committed
fix: change docker push
Signed-off-by: harlee-x <hailin097@sina.com>
1 parent 21f7d8e commit 2c1dd07

File tree

3 files changed

+42
-19
lines changed

3 files changed

+42
-19
lines changed

.github/workflows/ci-infra-build.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ jobs:
9393
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
9494
with:
9595
submodules: true
96-
9796
- name: Setup Go
9897
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7
9998
with:
@@ -105,6 +104,10 @@ jobs:
105104
path: .work/pkg
106105
key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
107106
restore-keys: ${{ runner.os }}-pkg-
107+
- name: Set up QEMU
108+
uses: docker/setup-qemu-action@5927c834f5b4fdf503fca6f4c7eccda82949e1ee # v3.1.0
109+
- name: Set up Docker Buildx
110+
uses: docker/setup-buildx-action@4fd812986e6c8c2a69e18311145f9371337f27d4 # v3.4.0
108111

109112
- uses: actions/checkout@v4
110113
- name: Docker Login
@@ -114,7 +117,9 @@ jobs:
114117
password: ${{ secrets.REG_PASSWD }}
115118

116119
- name: Run Build Images
117-
run: make kdp-infra-build IMG_REGISTRY=${{ secrets.CONTAINER_REGISTRY }}
120+
run: |
121+
make multi-arch-builder IMG_REGISTRY=${{ secrets.CONTAINER_REGISTRY }}
122+
make publish IMG_REGISTRY=${{ secrets.CONTAINER_REGISTRY }}
118123
119124
- name: Cleanup binary
120125
run: make kdp-cli-clean

kdp.Dockerfile

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
ARG ARCH=amd64
2-
FROM --platform=${ARCH} ghcr.io/flant/shell-operator:latest as builder
1+
ARG TARGETARCH
2+
FROM --platform=linux/${TARGETARCH} ghcr.io/flant/shell-operator:latest AS builder
33
RUN apk --no-cache add python3 \
44
&& python3 -m venv --copies /venv
55

6-
FROM builder as pip-package
6+
FROM builder AS pip-package
77
ENV PATH="/venv/bin:$PATH"
88

9-
109
RUN pip install --no-cache --upgrade pip kubernetes==26.1.0 jsonpath==0.82.2 deepdiff==7.0.1
1110

1211

13-
FROM builder as image
14-
12+
FROM builder AS image
13+
ARG TARGETARCH
1514
ARG VERSION
16-
ARG ARCH
1715
ENV KDP_ROOT_DIR=${KDP_ROOT_DIR:-.kdp}
1816
ENV PATH="/venv/bin:$PATH"
1917

2018
ADD hooks/* /hooks
21-
ADD cmd/output/${VERSION}/kdp-linux-${ARCH} /usr/local/bin/kdp
19+
ADD cmd/output/${VERSION}/kdp-linux-$TARGETARCH /usr/local/bin/kdp
2220

2321
COPY --from=pip-package /venv /venv
2422

makefiles/build.mk

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
##@ Docker image info
22
IMG ?= linktimecloud/kubernetes-data-platform:$(VERSION)
3+
KDP_IMG ?= linktimecloud/kdp:$(VERSION)
34
IMG_REGISTRY ?= ""
5+
OUTPUT_TYPE := registry
6+
TARGETARCHS := amd64 arm64
7+
ALL_OS_ARCH := linux-arm64 linux-amd64
48

59
##@ Build docker image
610
.PHONY: docker-build
@@ -46,13 +50,29 @@ kdp-cli-clean:
4650
##@ Build infra image
4751
.PHONY: kdp-infra-build
4852
kdp-infra-build:
49-
for arch in amd64 arm64; do \
50-
env GOOS=linux GOARCH=$$arch \
51-
go build -ldflags "-X kdp/cmd.CliVersion=$(VERSION) -X kdp/cmd.CliGoVersion=$(GO_VERSION) -X kdp/cmd.CliGitCommit=$(GIT_COMMIT) -X \"kdp/cmd.CliBuiltAt=$(BUILD_DATE)\" -X \"kdp/cmd.CliOSArch=$$arch\"" -o ./cmd/output/$(VERSION)/kdp-linux-$$arch; \
52-
if [ -n "$(IMG_REGISTRY)" ]; then \
53-
docker buildx build --platform linux/$$arch --build-arg VERSION="$(VERSION)" --output=type=image,name=$(IMG_REGISTRY)/kdp:$(VERSION),push=true -f kdp.Dockerfile . ; \
54-
else \
55-
docker buildx build --platform linux/$$arch --build-arg VERSION="$(VERSION)" --output=type=docker,name=kdp-$$arch:$(VERSION) -f kdp.Dockerfile . ; \
56-
fi \
57-
done
53+
go build -ldflags "-X kdp/cmd.CliVersion=$(VERSION) -X kdp/cmd.CliGoVersion=$(GO_VERSION) -X kdp/cmd.CliGitCommit=$(GIT_COMMIT) -X \"kdp/cmd.CliBuiltAt=$(BUILD_DATE)\" -X \"kdp/cmd.CliOSArch=$$arch\"" -o ./cmd/output/$(VERSION)/kdp-linux-$(TARGETARCH); \
54+
docker buildx build \
55+
--output=type=$(OUTPUT_TYPE) \
56+
--platform linux/$(TARGETARCH) \
57+
--provenance false \
58+
--build-arg VERSION=$(VERSION) \
59+
--build-arg TARGETARCH=$(TARGETARCH) \
60+
-t $(IMG_REGISTRY)/$(KDP_IMG)-linux-$(TARGETARCH) \
61+
-f kdp.Dockerfile .
62+
@$(OK)
63+
64+
65+
##@ push infra image
66+
.PHONY: publish
67+
publish:
68+
docker manifest create --amend $(IMG_REGISTRY)/$(KDP_IMG) $(foreach osarch, $(ALL_OS_ARCH), $(IMG_REGISTRY)/$(KDP_IMG)-${osarch})
69+
docker manifest push --purge $(IMG_REGISTRY)/$(KDP_IMG)
70+
docker manifest inspect $(IMG_REGISTRY)/$(KDP_IMG)
71+
5872

73+
##@ Build multi-arch image
74+
.PHONY: multi-arch-builder
75+
multi-arch-builder:
76+
for arch in $(TARGETARCHS); do \
77+
TARGETARCH=$${arch} $(MAKE) kdp-infra-build;\
78+
done

0 commit comments

Comments
 (0)