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
0 commit comments