Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
84 changes: 70 additions & 14 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,22 +34,39 @@ jobs:
restore-keys: |
${{ runner.os }}-go-

- name: Build container images
run: make container

- name: Log into registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}

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

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 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="${{ steps.build_vars.outputs.ldflags }}" \
--tag ${REGISTRY_NAME}/${img}:main \
--label org.opencontainers.image.revision=${{ steps.build_vars.outputs.git_commit }} \
--push \
.
done

- name: Push tagged release
Expand All @@ -53,16 +76,39 @@ jobs:
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,' | sed -e 's/^v//')

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="${{ steps.build_vars.outputs.ldflags }}" \
--tag ${REGISTRY_NAME}/${img}:${VERSION} \
--label org.opencontainers.image.revision=${{ steps.build_vars.outputs.git_commit }} \
--push \
.
done

- name: Upload cloudstack-csi-sc-syncer artifact
- 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: |
mkdir -p bin

# 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 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:
Expand Down Expand Up @@ -124,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
23 changes: 21 additions & 2 deletions cmd/cloudstack-csi-driver/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
FROM alpine:3.18
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.21

LABEL \
org.opencontainers.image.description="CloudStack CSI driver" \
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"]
23 changes: 21 additions & 2 deletions cmd/cloudstack-csi-sc-syncer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
FROM alpine:3.18
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.21

LABEL \
org.opencontainers.image.description="CloudStack disk offering to Kubernetes storage class syncer" \
org.opencontainers.image.source="https://github.com/cloudstack/cloudstack-csi-driver/"

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