forked from shapeblue/cloudstack-csi-driver
-
Notifications
You must be signed in to change notification settings - Fork 2
199 lines (169 loc) · 6.84 KB
/
release.yaml
File metadata and controls
199 lines (169 loc) · 6.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
name: Release
on:
push:
branches:
- main
tags:
- v*
env:
REGISTRY_NAME: ghcr.io/cloudstack
IMAGES: "cloudstack-csi-driver cloudstack-csi-sc-syncer"
jobs:
push:
name: Push images
runs-on: ubuntu-24.04
steps:
- 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:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- 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}"
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 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
if: startsWith(github.ref, 'refs/tags/v')
run: |
# Strip prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,' | sed -e 's/^v//')
for img in $IMAGES; do
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: 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-*
retention-days: 1
release:
name: Release
runs-on: ubuntu-24.04
# Run only if previous job has succeeded
needs: [push]
# Create a release only for tags v*
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create manifest
run: |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,' | sed -e 's/^v//')
printf "---\n" >> manifest.yaml
cat deploy/k8s/rbac.yaml >> manifest.yaml
printf "---\n" >> manifest.yaml
cat deploy/k8s/csidriver.yaml >> manifest.yaml
printf "---\n" >> manifest.yaml
sed -E "s|(image: +${REGISTRY_NAME}/cloudstack-csi-driver)(:[^ ]+)?|\\1:${VERSION}|" deploy/k8s/controller-deployment.yaml >> manifest.yaml
printf "---\n" >> manifest.yaml
sed -E "s|(image: +${REGISTRY_NAME}/cloudstack-csi-driver)(:[^ ]+)?|\\1:${VERSION}|" deploy/k8s/node-daemonset.yaml >> manifest.yaml
printf "---\n" >> manifest.yaml
cat deploy/k8s/volume-snapshot-class.yaml >> manifest.yaml
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
prerelease: false
- name: Upload Snapshot CRDs Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: deploy/k8s/00-snapshot-crds.yaml
asset_name: snapshot-crds.yaml
asset_content_type: application/x-yaml
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: manifest.yaml
asset_name: manifest.yaml
asset_content_type: application/x-yaml
- name: Download cloudstack-csi-sc-syncer artifacts
uses: actions/download-artifact@v4
with:
name: bin
path: bin
- 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 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-linux-arm64
asset_name: cloudstack-csi-sc-syncer-linux-arm64
asset_content_type: application/x-executable