Skip to content

Conversation

@Pearl1594
Copy link
Collaborator

@Pearl1594 Pearl1594 commented Nov 3, 2025

Issue #, if available:

Description of changes:
Builds multi-arch docker images to enable running csi driver on both amd64 & arm64.

Testing performed:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@Pearl1594 Pearl1594 marked this pull request as ready for review November 4, 2025 11:01
@vishesh92 vishesh92 requested a review from Copilot November 4, 2025 11:30
Copy link
Member

@kiranchavala kiranchavala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tested with the docker images for arm and a arm cluster in cloudstack

Able to create PVC and pod were using the it for persistent storage

pearl1594/cloudstack-csi-driver:test

Able to deploy

Test manifest file

manifest-arm.yaml

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modernizes the Docker build process by implementing multi-stage builds with multi-architecture support. The changes enable building container images for both linux/amd64 and linux/arm64 platforms directly in the CI/CD pipeline without requiring pre-built binaries.

Key changes:

  • Dockerfiles now use multi-stage builds with Go compilation inside the builder stage
  • GitHub Actions workflow updated to use Docker Buildx for multi-platform builds
  • Build arguments (LDFLAGS, TARGETOS, TARGETARCH) are passed to Docker builds for cross-compilation

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
cmd/cloudstack-csi-driver/Dockerfile Added multi-stage build with builder stage for Go compilation and multi-arch support
cmd/cloudstack-csi-sc-syncer/Dockerfile Added multi-stage build with builder stage for Go compilation and multi-arch support
.github/workflows/release.yaml Updated to use Docker Buildx for multi-platform builds; removed make container step; added Go build step for syncer binary upload

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 86 to 96
- 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
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'Build syncer binary for upload' step attempts to run go build but there's no Go setup step in this workflow. This will fail because Go is not installed on the runner. Add a setup-go action before this step, similar to the PR check workflow which uses actions/setup-go@v5 with go-version: \"1.23\".

Copilot uses AI. Check for mistakes.
Comment on lines +3 to +4
ARG TARGETOS
ARG TARGETARCH
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build arguments TARGETOS and TARGETARCH are declared but Docker Buildx automatically provides these as built-in arguments when using --platform. You should add default values for these arguments to ensure the Dockerfile works correctly in non-buildx contexts. For example: ARG TARGETOS=linux and ARG TARGETARCH=amd64.

Suggested change
ARG TARGETOS
ARG TARGETARCH
ARG TARGETOS=linux
ARG TARGETARCH=amd64

Copilot uses AI. Check for mistakes.
Comment on lines +3 to +4
ARG TARGETOS
ARG TARGETARCH
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build arguments TARGETOS and TARGETARCH are declared but Docker Buildx automatically provides these as built-in arguments when using --platform. You should add default values for these arguments to ensure the Dockerfile works correctly in non-buildx contexts. For example: ARG TARGETOS=linux and ARG TARGETARCH=amd64.

Suggested change
ARG TARGETOS
ARG TARGETARCH
ARG TARGETOS=linux
ARG TARGETARCH=amd64

Copilot uses AI. Check for mistakes.
Comment on lines +47 to +51
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}"
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The LDFLAGS construction is duplicated across three separate steps (lines 47-51, 69-73, and 89-93). Consider extracting this logic into a reusable composite action or a separate script to reduce code duplication and ensure consistency.

Copilot uses AI. Check for mistakes.
- 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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move all these params to a single step? this will make the github actions cleaner.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this build binaries for all architectures?

Copy link

@weizhouapache weizhouapache left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Collaborator

@vishesh92 vishesh92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clgtm

@Pearl1594 Pearl1594 merged commit 701bc2f into main Nov 4, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants