Skip to content

Commit e32c051

Browse files
committed
extract common bits and build arm / amd syncer binaries
1 parent 54dfc3c commit e32c051

File tree

1 file changed

+44
-26
lines changed

1 file changed

+44
-26
lines changed

.github/workflows/release.yaml

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,30 @@ jobs:
4141
username: ${{github.actor}}
4242
password: ${{secrets.GITHUB_TOKEN}}
4343

44-
- name: Push main
45-
if: github.ref == 'refs/heads/main'
44+
- name: Set build variables
45+
id: build_vars
4646
run: |
4747
REV=$(git describe --long --tags --match='v*' --dirty 2>/dev/null || git rev-list -n1 HEAD)
4848
GIT_COMMIT=$(git rev-parse HEAD)
4949
BUILD_DATE=$(date -u -Iseconds)
5050
PKG=github.com/cloudstack/cloudstack-csi-driver
5151
LDFLAGS="-s -w -X ${PKG}/pkg/driver.driverVersion=${REV} -X ${PKG}/pkg/driver.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/driver.buildDate=${BUILD_DATE}"
5252
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+
58+
- name: Push main
59+
if: github.ref == 'refs/heads/main'
60+
run: |
5361
for img in $IMAGES; do
5462
docker buildx build \
5563
--platform linux/amd64,linux/arm64 \
5664
--file ./cmd/${img}/Dockerfile \
57-
--build-arg LDFLAGS="${LDFLAGS}" \
65+
--build-arg LDFLAGS="${{ steps.build_vars.outputs.ldflags }}" \
5866
--tag ${REGISTRY_NAME}/${img}:main \
59-
--label org.opencontainers.image.revision=${GIT_COMMIT} \
67+
--label org.opencontainers.image.revision=${{ steps.build_vars.outputs.git_commit }} \
6068
--push \
6169
.
6270
done
@@ -66,41 +74,41 @@ jobs:
6674
run: |
6775
# Strip prefix from version
6876
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,' | sed -e 's/^v//')
69-
REV=$(git describe --long --tags --match='v*' --dirty 2>/dev/null || git rev-list -n1 HEAD)
70-
GIT_COMMIT=$(git rev-parse HEAD)
71-
BUILD_DATE=$(date -u -Iseconds)
72-
PKG=github.com/cloudstack/cloudstack-csi-driver
73-
LDFLAGS="-s -w -X ${PKG}/pkg/driver.driverVersion=${REV} -X ${PKG}/pkg/driver.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/driver.buildDate=${BUILD_DATE}"
7477
7578
for img in $IMAGES; do
7679
docker buildx build \
7780
--platform linux/amd64,linux/arm64 \
7881
--file ./cmd/${img}/Dockerfile \
79-
--build-arg LDFLAGS="${LDFLAGS}" \
82+
--build-arg LDFLAGS="${{ steps.build_vars.outputs.ldflags }}" \
8083
--tag ${REGISTRY_NAME}/${img}:${VERSION} \
81-
--label org.opencontainers.image.revision=${GIT_COMMIT} \
84+
--label org.opencontainers.image.revision=${{ steps.build_vars.outputs.git_commit }} \
8285
--push \
8386
.
8487
done
8588
86-
- name: Build syncer binary for upload
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
8796
if: startsWith(github.ref, 'refs/tags/v')
8897
run: |
89-
REV=$(git describe --long --tags --match='v*' --dirty 2>/dev/null || git rev-list -n1 HEAD)
90-
GIT_COMMIT=$(git rev-parse HEAD)
91-
BUILD_DATE=$(date -u -Iseconds)
92-
PKG=github.com/cloudstack/cloudstack-csi-driver
93-
LDFLAGS="-s -w -X ${PKG}/pkg/driver.driverVersion=${REV} -X ${PKG}/pkg/driver.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/driver.buildDate=${BUILD_DATE}"
94-
9598
mkdir -p bin
96-
CGO_ENABLED=0 go build -ldflags "${LDFLAGS}" -o ./bin/cloudstack-csi-sc-syncer ./cmd/cloudstack-csi-sc-syncer
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
97105
98-
- name: Upload cloudstack-csi-sc-syncer artifact
106+
- name: Upload cloudstack-csi-sc-syncer artifacts
99107
if: startsWith(github.ref, 'refs/tags/v')
100108
uses: actions/upload-artifact@v4
101109
with:
102110
name: bin
103-
path: bin/cloudstack-csi-sc-syncer
111+
path: bin/cloudstack-csi-sc-syncer-*
104112
retention-days: 1
105113

106114
release:
@@ -162,20 +170,30 @@ jobs:
162170
asset_name: manifest.yaml
163171
asset_content_type: application/x-yaml
164172

165-
- name: Download cloudstack-csi-sc-syncer artifact
173+
- name: Download cloudstack-csi-sc-syncer artifacts
166174
uses: actions/download-artifact@v4
167175
with:
168176
name: bin
169177
path: bin
170178

171-
- 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
172190

173-
- name: Upload cloudstack-csi-sc-syncer asset
191+
- name: Upload cloudstack-csi-sc-syncer ARM64 asset
174192
uses: actions/upload-release-asset@v1
175193
env:
176194
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
177195
with:
178196
upload_url: ${{ steps.create_release.outputs.upload_url }}
179-
asset_path: bin/cloudstack-csi-sc-syncer
180-
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
181199
asset_content_type: application/x-executable

0 commit comments

Comments
 (0)