-
-
Notifications
You must be signed in to change notification settings - Fork 229
258 lines (224 loc) · 7.44 KB
/
ci.yaml
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
name: CI
on:
pull_request:
branches:
- master
push:
branches:
- master
permissions:
contents: read
env:
GOLANG_VERSION: 1.22
APPLICATION_NAME: redis-operator
DockerImagName: docker.io/opstree/redis-operator
BuildDocs: true
AppVersion: "v0.15.2"
DOCKERFILE_PATH: "**/Dockerfile"
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GOLANG_VERSION }}
cache: false
- name: Run GolangCI-Lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.54.0
gotest:
needs:
- lint
name: Go Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GOLANG_VERSION }}
- name: Install integration test dependencies
run: make integration-test-setup
- name: Run Go Tests with coverage
run: go test ./... -coverprofile=coverage.txt -covermode=atomic
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
file: ./coverage.txt
fail_ci_if_error: false
verbose: true
helm_docs_test:
needs: [lint]
name: Helm Docs Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Ensure documentation is updated
uses: docker://jnorwood/helm-docs:latest
- name: Check for changes
run: |
if git diff --exit-code; then
echo -e "\n####### Helm docs are up-to-date! #######\n"
else
git status
echo -e "\n####### Helm docs are not up-to-date! Please run generate helm docs locally and push the changes #######\n"
exit 1
fi
validate_examples:
needs: [gotest, helm_docs_test]
name: Validate Examples
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install yamllint
run: sudo apt-get install -y yamllint
- name: Lint YAML files
run: yamllint --strict ./example
- name: Install kubectl
run: |
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
- name: Create k8s Kind Cluster
uses: helm/[email protected]
with:
cluster_name: kind
- name: Apply CRD
run: |
for crd in $(find ./config/crd/bases -type f -name '*.yaml'); do
kubectl create -f $crd
done
- name: Validate CRD Installation
run: |
CRDs=("redis" "redissentinels" "redisclusters" "redisreplications")
for crd in "${CRDs[@]}"; do
kubectl get crd $crd.redis.redis.opstreelabs.in || exit 1
done
- name: Validate CR
run: |
for example in $(find ./example -type f -name '*.yaml'); do
kubectl apply --dry-run=server -f $example
done
validate_yaml:
needs: [validate_examples]
name: Validate YAML
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install yamllint
run: sudo apt-get install -y yamllint
- name: Lint YAML files
run: yamllint --strict ./tests/
container_quality_dockerfile_lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Execute dockerlinter
uses: hadolint/[email protected]
with:
dockerfile: Dockerfile
ignore: DL3007,DL3018
build_go_binary:
needs: [lint]
runs-on: ubuntu-latest
strategy:
matrix:
arch: ["amd64", "arm64"]
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup Go Environment
uses: actions/setup-go@v5
with:
go-version: ${{ env.GOLANG_VERSION }}
- name: Set GOARCH
run: echo "GOARCH=${{ matrix.arch }}" >> $GITHUB_ENV
- name: Build Go Binary
run: go build -o ${{ github.workspace }}/${{ env.APPLICATION_NAME }}
- name: Archive Binary
run: |
mkdir -p ${{ github.workspace }}/compiled/${{ matrix.arch }}
zip ${{ github.workspace }}/compiled/${{ matrix.arch }}/${{ env.APPLICATION_NAME }}-${{ matrix.arch }}.zip ${{ github.workspace }}/${{ env.APPLICATION_NAME }}
build_scan_container_image:
needs: [container_quality_dockerfile_lint]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build multi-arch image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/arm64,linux/amd64
push: false
tags: ${{ env.DockerImagName }}:latest
gosec_scan:
needs: [build_go_binary]
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Gosec Scan
uses: securego/gosec@master
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOSEC_OUTPUT: "junit-xml:/github/workspace/gosec-results.xml"
e2e_test:
needs: [validate_yaml]
name: E2E Test
runs-on: ubuntu-latest
strategy:
matrix:
redis-version: ["v7.0.15"]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Build Dockerfile
run: docker build . --file Dockerfile --tag redis-operator:e2e
- name: Install Cosign
uses: sigstore/[email protected]
- name: Install chainsaw
uses: kyverno/[email protected]
with:
verify: true
- name: Check install
run: chainsaw version
- name: Install kubectl
run: |
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
# - name: Install Redis
# uses: shogo82148/actions-setup-redis@v1
- name: Create k8s Kind Cluster
uses: helm/[email protected]
with:
config: tests/_config/kind-config.yaml
cluster_name: kind
- name: Load Docker image into Kind
run: |
kubectl cluster-info --context kind-kind
kind load docker-image redis-operator:e2e --name kind
- name: Install Redis Operator
run: |
make deploy IMG=redis-operator:e2e
- name: Wait for Redis Operator to be ready
run: |
kubectl wait --for=condition=available --timeout=300s deployment/redis-operator-redis-operator -n redis-operator-system
- name: Replace Redis Image Version
run: |
find ./tests/e2e-chainsaw/v1beta2/ -type f -exec sed -i 's/quay.io\/opstree\/redis:latest/quay.io\/opstree\/redis:${{ matrix.redis-version }}/g' {} \;
find ./tests/e2e-chainsaw/v1beta2/ -type f -exec sed -i 's/quay.io\/opstree\/redis-sentinel:latest/quay.io\/opstree\/redis-sentinel:${{ matrix.redis-version }}/g' {} \;
- name: Run chainsaw test
run: chainsaw test --test-dir ./tests/e2e-chainsaw/v1beta2/ --config tests/_config/chainsaw-configuration.yaml