Skip to content

Commit 701bc2f

Browse files
authored
Merge pull request #3 from cloudstack/multi-arch-support
Support multi-arch builds
2 parents bdbe093 + 9be27d7 commit 701bc2f

File tree

3 files changed

+112
-18
lines changed

3 files changed

+112
-18
lines changed

.github/workflows/release.yaml

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ jobs:
2020
- name: Check out code
2121
uses: actions/checkout@v4
2222

23+
- name: Set up QEMU
24+
uses: docker/setup-qemu-action@v3
25+
26+
- name: Set up Docker Buildx
27+
uses: docker/setup-buildx-action@v3
28+
2329
- name: Cache
2430
uses: actions/cache@v4
2531
with:
@@ -28,22 +34,39 @@ jobs:
2834
restore-keys: |
2935
${{ runner.os }}-go-
3036
31-
- name: Build container images
32-
run: make container
33-
3437
- name: Log into registry
3538
uses: docker/login-action@v3
3639
with:
3740
registry: ghcr.io
3841
username: ${{github.actor}}
3942
password: ${{secrets.GITHUB_TOKEN}}
4043

44+
- name: Set build variables
45+
id: build_vars
46+
run: |
47+
REV=$(git describe --long --tags --match='v*' --dirty 2>/dev/null || git rev-list -n1 HEAD)
48+
GIT_COMMIT=$(git rev-parse HEAD)
49+
BUILD_DATE=$(date -u -Iseconds)
50+
PKG=github.com/cloudstack/cloudstack-csi-driver
51+
LDFLAGS="-s -w -X ${PKG}/pkg/driver.driverVersion=${REV} -X ${PKG}/pkg/driver.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/driver.buildDate=${BUILD_DATE}"
52+
53+
echo "rev=${REV}" >> $GITHUB_OUTPUT
54+
echo "git_commit=${GIT_COMMIT}" >> $GITHUB_OUTPUT
55+
echo "build_date=${BUILD_DATE}" >> $GITHUB_OUTPUT
56+
echo "ldflags=${LDFLAGS}" >> $GITHUB_OUTPUT
57+
4158
- name: Push main
4259
if: github.ref == 'refs/heads/main'
4360
run: |
4461
for img in $IMAGES; do
45-
docker tag ${img} ${REGISTRY_NAME}/${img}:main
46-
docker push ${REGISTRY_NAME}/${img}:main
62+
docker buildx build \
63+
--platform linux/amd64,linux/arm64 \
64+
--file ./cmd/${img}/Dockerfile \
65+
--build-arg LDFLAGS="${{ steps.build_vars.outputs.ldflags }}" \
66+
--tag ${REGISTRY_NAME}/${img}:main \
67+
--label org.opencontainers.image.revision=${{ steps.build_vars.outputs.git_commit }} \
68+
--push \
69+
.
4770
done
4871
4972
- name: Push tagged release
@@ -53,16 +76,39 @@ jobs:
5376
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,' | sed -e 's/^v//')
5477
5578
for img in $IMAGES; do
56-
docker tag ${img} ${REGISTRY_NAME}/${img}:${VERSION}
57-
docker push ${REGISTRY_NAME}/${img}:${VERSION}
79+
docker buildx build \
80+
--platform linux/amd64,linux/arm64 \
81+
--file ./cmd/${img}/Dockerfile \
82+
--build-arg LDFLAGS="${{ steps.build_vars.outputs.ldflags }}" \
83+
--tag ${REGISTRY_NAME}/${img}:${VERSION} \
84+
--label org.opencontainers.image.revision=${{ steps.build_vars.outputs.git_commit }} \
85+
--push \
86+
.
5887
done
5988
60-
- name: Upload cloudstack-csi-sc-syncer artifact
89+
- name: Set up Go
90+
if: startsWith(github.ref, 'refs/tags/v')
91+
uses: actions/setup-go@v5
92+
with:
93+
go-version: "1.23"
94+
95+
- name: Build syncer binaries for upload
96+
if: startsWith(github.ref, 'refs/tags/v')
97+
run: |
98+
mkdir -p bin
99+
100+
# Build for AMD64
101+
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
102+
103+
# Build for ARM64
104+
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
105+
106+
- name: Upload cloudstack-csi-sc-syncer artifacts
61107
if: startsWith(github.ref, 'refs/tags/v')
62108
uses: actions/upload-artifact@v4
63109
with:
64110
name: bin
65-
path: bin/cloudstack-csi-sc-syncer
111+
path: bin/cloudstack-csi-sc-syncer-*
66112
retention-days: 1
67113

68114
release:
@@ -124,20 +170,30 @@ jobs:
124170
asset_name: manifest.yaml
125171
asset_content_type: application/x-yaml
126172

127-
- name: Download cloudstack-csi-sc-syncer artifact
173+
- name: Download cloudstack-csi-sc-syncer artifacts
128174
uses: actions/download-artifact@v4
129175
with:
130176
name: bin
131177
path: bin
132178

133-
- run: ls -l
179+
- run: ls -l bin
180+
181+
- name: Upload cloudstack-csi-sc-syncer AMD64 asset
182+
uses: actions/upload-release-asset@v1
183+
env:
184+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
185+
with:
186+
upload_url: ${{ steps.create_release.outputs.upload_url }}
187+
asset_path: bin/cloudstack-csi-sc-syncer-linux-amd64
188+
asset_name: cloudstack-csi-sc-syncer-linux-amd64
189+
asset_content_type: application/x-executable
134190

135-
- name: Upload cloudstack-csi-sc-syncer asset
191+
- name: Upload cloudstack-csi-sc-syncer ARM64 asset
136192
uses: actions/upload-release-asset@v1
137193
env:
138194
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
139195
with:
140196
upload_url: ${{ steps.create_release.outputs.upload_url }}
141-
asset_path: bin/cloudstack-csi-sc-syncer
142-
asset_name: cloudstack-csi-sc-syncer
197+
asset_path: bin/cloudstack-csi-sc-syncer-linux-arm64
198+
asset_name: cloudstack-csi-sc-syncer-linux-arm64
143199
asset_content_type: application/x-executable

cmd/cloudstack-csi-driver/Dockerfile

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
1-
FROM alpine:3.18
1+
FROM --platform=$BUILDPLATFORM golang:1.23-alpine AS builder
2+
3+
ARG TARGETOS
4+
ARG TARGETARCH
5+
ARG LDFLAGS
6+
7+
WORKDIR /workspace
8+
9+
# Copy go mod files
10+
COPY go.mod go.sum ./
11+
RUN go mod download
12+
13+
# Copy source code
14+
COPY . .
15+
16+
# Build
17+
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
18+
go build -ldflags "${LDFLAGS}" -o cloudstack-csi-driver ./cmd/cloudstack-csi-driver
19+
20+
FROM alpine:3.21
221

322
LABEL \
423
org.opencontainers.image.description="CloudStack CSI driver" \
@@ -18,5 +37,5 @@ RUN apk add --no-cache \
1837
# Provides udevadm for device path detection \
1938
udev
2039

21-
COPY ./bin/cloudstack-csi-driver /cloudstack-csi-driver
40+
COPY --from=builder /workspace/cloudstack-csi-driver /cloudstack-csi-driver
2241
ENTRYPOINT ["/cloudstack-csi-driver"]
Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
1-
FROM alpine:3.18
1+
FROM --platform=$BUILDPLATFORM golang:1.23-alpine AS builder
2+
3+
ARG TARGETOS
4+
ARG TARGETARCH
5+
ARG LDFLAGS
6+
7+
WORKDIR /workspace
8+
9+
# Copy go mod files
10+
COPY go.mod go.sum ./
11+
RUN go mod download
12+
13+
# Copy source code
14+
COPY . .
15+
16+
# Build
17+
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
18+
go build -ldflags "${LDFLAGS}" -o cloudstack-csi-sc-syncer ./cmd/cloudstack-csi-sc-syncer
19+
20+
FROM alpine:3.21
221

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

726
RUN apk add --no-cache ca-certificates
827

9-
COPY ./bin/cloudstack-csi-sc-syncer /cloudstack-csi-sc-syncer
28+
COPY --from=builder /workspace/cloudstack-csi-sc-syncer /cloudstack-csi-sc-syncer
1029
ENTRYPOINT ["/cloudstack-csi-sc-syncer"]

0 commit comments

Comments
 (0)