Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 45 additions & 7 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -41,22 +44,57 @@ 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}"
Comment on lines +47 to +51
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.

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
if: startsWith(github.ref, 'refs/tags/v')
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)
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.

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.
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?


- name: Upload cloudstack-csi-sc-syncer artifact
if: startsWith(github.ref, 'refs/tags/v')
uses: actions/upload-artifact@v4
Expand Down
21 changes: 20 additions & 1 deletion cmd/cloudstack-csi-driver/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
FROM --platform=$BUILDPLATFORM golang:1.23-alpine AS builder

ARG TARGETOS
ARG TARGETARCH
Comment on lines +3 to +4
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.
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 \
Expand All @@ -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"]
21 changes: 20 additions & 1 deletion cmd/cloudstack-csi-sc-syncer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
FROM --platform=$BUILDPLATFORM golang:1.23-alpine AS builder

ARG TARGETOS
ARG TARGETARCH
Comment on lines +3 to +4
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.
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 \
Expand All @@ -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"]
Loading