From 54dfc3cb2c1806855c977522938156c8ac56ab5a Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Mon, 3 Nov 2025 15:50:17 -0500 Subject: [PATCH 1/3] Support multi-arch builds --- .github/workflows/release.yaml | 52 +++++++++++++++++++++---- cmd/cloudstack-csi-driver/Dockerfile | 21 +++++++++- cmd/cloudstack-csi-sc-syncer/Dockerfile | 21 +++++++++- 3 files changed, 85 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index bfb3ac2..cdbf9ea 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -20,6 +20,12 @@ jobs: - name: Check out code uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Cache uses: actions/cache@v4 with: @@ -28,9 +34,6 @@ jobs: restore-keys: | ${{ runner.os }}-go- - - name: Build container images - run: make container - - name: Log into registry uses: docker/login-action@v3 with: @@ -41,9 +44,21 @@ jobs: - name: Push main if: github.ref == 'refs/heads/main' run: | + REV=$(git describe --long --tags --match='v*' --dirty 2>/dev/null || git rev-list -n1 HEAD) + GIT_COMMIT=$(git rev-parse HEAD) + BUILD_DATE=$(date -u -Iseconds) + PKG=github.com/cloudstack/cloudstack-csi-driver + LDFLAGS="-s -w -X ${PKG}/pkg/driver.driverVersion=${REV} -X ${PKG}/pkg/driver.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/driver.buildDate=${BUILD_DATE}" + for img in $IMAGES; do - docker tag ${img} ${REGISTRY_NAME}/${img}:main - docker push ${REGISTRY_NAME}/${img}:main + docker buildx build \ + --platform linux/amd64,linux/arm64 \ + --file ./cmd/${img}/Dockerfile \ + --build-arg LDFLAGS="${LDFLAGS}" \ + --tag ${REGISTRY_NAME}/${img}:main \ + --label org.opencontainers.image.revision=${GIT_COMMIT} \ + --push \ + . done - name: Push tagged release @@ -51,12 +66,35 @@ jobs: run: | # Strip prefix from version VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,' | sed -e 's/^v//') + REV=$(git describe --long --tags --match='v*' --dirty 2>/dev/null || git rev-list -n1 HEAD) + GIT_COMMIT=$(git rev-parse HEAD) + BUILD_DATE=$(date -u -Iseconds) + PKG=github.com/cloudstack/cloudstack-csi-driver + LDFLAGS="-s -w -X ${PKG}/pkg/driver.driverVersion=${REV} -X ${PKG}/pkg/driver.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/driver.buildDate=${BUILD_DATE}" for img in $IMAGES; do - docker tag ${img} ${REGISTRY_NAME}/${img}:${VERSION} - docker push ${REGISTRY_NAME}/${img}:${VERSION} + docker buildx build \ + --platform linux/amd64,linux/arm64 \ + --file ./cmd/${img}/Dockerfile \ + --build-arg LDFLAGS="${LDFLAGS}" \ + --tag ${REGISTRY_NAME}/${img}:${VERSION} \ + --label org.opencontainers.image.revision=${GIT_COMMIT} \ + --push \ + . done + - name: Build syncer binary for upload + if: startsWith(github.ref, 'refs/tags/v') + run: | + REV=$(git describe --long --tags --match='v*' --dirty 2>/dev/null || git rev-list -n1 HEAD) + GIT_COMMIT=$(git rev-parse HEAD) + BUILD_DATE=$(date -u -Iseconds) + PKG=github.com/cloudstack/cloudstack-csi-driver + LDFLAGS="-s -w -X ${PKG}/pkg/driver.driverVersion=${REV} -X ${PKG}/pkg/driver.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/driver.buildDate=${BUILD_DATE}" + + mkdir -p bin + CGO_ENABLED=0 go build -ldflags "${LDFLAGS}" -o ./bin/cloudstack-csi-sc-syncer ./cmd/cloudstack-csi-sc-syncer + - name: Upload cloudstack-csi-sc-syncer artifact if: startsWith(github.ref, 'refs/tags/v') uses: actions/upload-artifact@v4 diff --git a/cmd/cloudstack-csi-driver/Dockerfile b/cmd/cloudstack-csi-driver/Dockerfile index 97ee99f..06c3aac 100644 --- a/cmd/cloudstack-csi-driver/Dockerfile +++ b/cmd/cloudstack-csi-driver/Dockerfile @@ -1,3 +1,22 @@ +FROM --platform=$BUILDPLATFORM golang:1.23-alpine AS builder + +ARG TARGETOS +ARG TARGETARCH +ARG LDFLAGS + +WORKDIR /workspace + +# Copy go mod files +COPY go.mod go.sum ./ +RUN go mod download + +# Copy source code +COPY . . + +# Build +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ + go build -ldflags "${LDFLAGS}" -o cloudstack-csi-driver ./cmd/cloudstack-csi-driver + FROM alpine:3.18 LABEL \ @@ -18,5 +37,5 @@ RUN apk add --no-cache \ # Provides udevadm for device path detection \ udev -COPY ./bin/cloudstack-csi-driver /cloudstack-csi-driver +COPY --from=builder /workspace/cloudstack-csi-driver /cloudstack-csi-driver ENTRYPOINT ["/cloudstack-csi-driver"] diff --git a/cmd/cloudstack-csi-sc-syncer/Dockerfile b/cmd/cloudstack-csi-sc-syncer/Dockerfile index 9965717..17e8d77 100644 --- a/cmd/cloudstack-csi-sc-syncer/Dockerfile +++ b/cmd/cloudstack-csi-sc-syncer/Dockerfile @@ -1,3 +1,22 @@ +FROM --platform=$BUILDPLATFORM golang:1.23-alpine AS builder + +ARG TARGETOS +ARG TARGETARCH +ARG LDFLAGS + +WORKDIR /workspace + +# Copy go mod files +COPY go.mod go.sum ./ +RUN go mod download + +# Copy source code +COPY . . + +# Build +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ + go build -ldflags "${LDFLAGS}" -o cloudstack-csi-sc-syncer ./cmd/cloudstack-csi-sc-syncer + FROM alpine:3.18 LABEL \ @@ -6,5 +25,5 @@ LABEL \ RUN apk add --no-cache ca-certificates -COPY ./bin/cloudstack-csi-sc-syncer /cloudstack-csi-sc-syncer +COPY --from=builder /workspace/cloudstack-csi-sc-syncer /cloudstack-csi-sc-syncer ENTRYPOINT ["/cloudstack-csi-sc-syncer"] \ No newline at end of file From e32c051b95170f729ad8bb01502d01e4e4300fd2 Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Tue, 4 Nov 2025 06:52:23 -0500 Subject: [PATCH 2/3] extract common bits and build arm / amd syncer binaries --- .github/workflows/release.yaml | 70 +++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index cdbf9ea..c1125b0 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -41,8 +41,8 @@ jobs: username: ${{github.actor}} password: ${{secrets.GITHUB_TOKEN}} - - name: Push main - if: github.ref == 'refs/heads/main' + - name: Set build variables + id: build_vars run: | REV=$(git describe --long --tags --match='v*' --dirty 2>/dev/null || git rev-list -n1 HEAD) GIT_COMMIT=$(git rev-parse HEAD) @@ -50,13 +50,21 @@ jobs: PKG=github.com/cloudstack/cloudstack-csi-driver LDFLAGS="-s -w -X ${PKG}/pkg/driver.driverVersion=${REV} -X ${PKG}/pkg/driver.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/driver.buildDate=${BUILD_DATE}" + echo "rev=${REV}" >> $GITHUB_OUTPUT + echo "git_commit=${GIT_COMMIT}" >> $GITHUB_OUTPUT + echo "build_date=${BUILD_DATE}" >> $GITHUB_OUTPUT + echo "ldflags=${LDFLAGS}" >> $GITHUB_OUTPUT + + - name: Push main + if: github.ref == 'refs/heads/main' + run: | for img in $IMAGES; do docker buildx build \ --platform linux/amd64,linux/arm64 \ --file ./cmd/${img}/Dockerfile \ - --build-arg LDFLAGS="${LDFLAGS}" \ + --build-arg LDFLAGS="${{ steps.build_vars.outputs.ldflags }}" \ --tag ${REGISTRY_NAME}/${img}:main \ - --label org.opencontainers.image.revision=${GIT_COMMIT} \ + --label org.opencontainers.image.revision=${{ steps.build_vars.outputs.git_commit }} \ --push \ . done @@ -66,41 +74,41 @@ jobs: run: | # Strip prefix from version VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,' | sed -e 's/^v//') - REV=$(git describe --long --tags --match='v*' --dirty 2>/dev/null || git rev-list -n1 HEAD) - GIT_COMMIT=$(git rev-parse HEAD) - BUILD_DATE=$(date -u -Iseconds) - PKG=github.com/cloudstack/cloudstack-csi-driver - LDFLAGS="-s -w -X ${PKG}/pkg/driver.driverVersion=${REV} -X ${PKG}/pkg/driver.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/driver.buildDate=${BUILD_DATE}" for img in $IMAGES; do docker buildx build \ --platform linux/amd64,linux/arm64 \ --file ./cmd/${img}/Dockerfile \ - --build-arg LDFLAGS="${LDFLAGS}" \ + --build-arg LDFLAGS="${{ steps.build_vars.outputs.ldflags }}" \ --tag ${REGISTRY_NAME}/${img}:${VERSION} \ - --label org.opencontainers.image.revision=${GIT_COMMIT} \ + --label org.opencontainers.image.revision=${{ steps.build_vars.outputs.git_commit }} \ --push \ . done - - name: Build syncer binary for upload + - name: Set up Go + if: startsWith(github.ref, 'refs/tags/v') + uses: actions/setup-go@v5 + with: + go-version: "1.23" + + - name: Build syncer binaries for upload if: startsWith(github.ref, 'refs/tags/v') run: | - REV=$(git describe --long --tags --match='v*' --dirty 2>/dev/null || git rev-list -n1 HEAD) - GIT_COMMIT=$(git rev-parse HEAD) - BUILD_DATE=$(date -u -Iseconds) - PKG=github.com/cloudstack/cloudstack-csi-driver - LDFLAGS="-s -w -X ${PKG}/pkg/driver.driverVersion=${REV} -X ${PKG}/pkg/driver.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/driver.buildDate=${BUILD_DATE}" - mkdir -p bin - CGO_ENABLED=0 go build -ldflags "${LDFLAGS}" -o ./bin/cloudstack-csi-sc-syncer ./cmd/cloudstack-csi-sc-syncer + + # Build for AMD64 + GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "${{ steps.build_vars.outputs.ldflags }}" -o ./bin/cloudstack-csi-sc-syncer-linux-amd64 ./cmd/cloudstack-csi-sc-syncer + + # Build for ARM64 + GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -ldflags "${{ steps.build_vars.outputs.ldflags }}" -o ./bin/cloudstack-csi-sc-syncer-linux-arm64 ./cmd/cloudstack-csi-sc-syncer - - name: Upload cloudstack-csi-sc-syncer artifact + - name: Upload cloudstack-csi-sc-syncer artifacts if: startsWith(github.ref, 'refs/tags/v') uses: actions/upload-artifact@v4 with: name: bin - path: bin/cloudstack-csi-sc-syncer + path: bin/cloudstack-csi-sc-syncer-* retention-days: 1 release: @@ -162,20 +170,30 @@ jobs: asset_name: manifest.yaml asset_content_type: application/x-yaml - - name: Download cloudstack-csi-sc-syncer artifact + - name: Download cloudstack-csi-sc-syncer artifacts uses: actions/download-artifact@v4 with: name: bin path: bin - - run: ls -l + - run: ls -l bin + + - name: Upload cloudstack-csi-sc-syncer AMD64 asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: bin/cloudstack-csi-sc-syncer-linux-amd64 + asset_name: cloudstack-csi-sc-syncer-linux-amd64 + asset_content_type: application/x-executable - - name: Upload cloudstack-csi-sc-syncer asset + - name: Upload cloudstack-csi-sc-syncer ARM64 asset uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: bin/cloudstack-csi-sc-syncer - asset_name: cloudstack-csi-sc-syncer + asset_path: bin/cloudstack-csi-sc-syncer-linux-arm64 + asset_name: cloudstack-csi-sc-syncer-linux-arm64 asset_content_type: application/x-executable From 9be27d73eeb3b312fd6a28e49490421a7269315a Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Tue, 4 Nov 2025 07:21:13 -0500 Subject: [PATCH 3/3] update alpine version used --- cmd/cloudstack-csi-driver/Dockerfile | 2 +- cmd/cloudstack-csi-sc-syncer/Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/cloudstack-csi-driver/Dockerfile b/cmd/cloudstack-csi-driver/Dockerfile index 06c3aac..00ef7a3 100644 --- a/cmd/cloudstack-csi-driver/Dockerfile +++ b/cmd/cloudstack-csi-driver/Dockerfile @@ -17,7 +17,7 @@ COPY . . RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ go build -ldflags "${LDFLAGS}" -o cloudstack-csi-driver ./cmd/cloudstack-csi-driver -FROM alpine:3.18 +FROM alpine:3.21 LABEL \ org.opencontainers.image.description="CloudStack CSI driver" \ diff --git a/cmd/cloudstack-csi-sc-syncer/Dockerfile b/cmd/cloudstack-csi-sc-syncer/Dockerfile index 17e8d77..f825ddc 100644 --- a/cmd/cloudstack-csi-sc-syncer/Dockerfile +++ b/cmd/cloudstack-csi-sc-syncer/Dockerfile @@ -17,7 +17,7 @@ COPY . . RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ go build -ldflags "${LDFLAGS}" -o cloudstack-csi-sc-syncer ./cmd/cloudstack-csi-sc-syncer -FROM alpine:3.18 +FROM alpine:3.21 LABEL \ org.opencontainers.image.description="CloudStack disk offering to Kubernetes storage class syncer" \