-
Notifications
You must be signed in to change notification settings - Fork 1
Support multi-arch builds #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,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}" | ||
|
|
||
| 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) | ||
|
||
| 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 | ||
|
|
||
| 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
|
||||||||||
| ARG TARGETOS | |
| ARG TARGETARCH | |
| ARG TARGETOS=linux | |
| ARG TARGETARCH=amd64 |
| 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
|
||||||||||
| ARG TARGETOS | |
| ARG TARGETARCH | |
| ARG TARGETOS=linux | |
| ARG TARGETARCH=amd64 |
There was a problem hiding this comment.
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.