-
Notifications
You must be signed in to change notification settings - Fork 4
257 lines (249 loc) · 10.5 KB
/
e2e.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
name: E2E tests
on:
push:
branches:
- "main"
paths:
- "**"
- "!docs/**"
pull_request:
branches:
- "main"
concurrency:
group: ${{ github.workflow }} # Bottleneck in ngrok tunnel, only one tunnel can exist for specific token -${{ github.ref }}
# cancel-in-progress: true
permissions:
contents: read
jobs:
gitlab-e2e-env:
env:
GITLAB_LICENSE: ${{ secrets.GITLAB_LICENSE }}
name: Gitlab E2E Tests (on development)
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v3
- uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host
- uses: actions/setup-go@v4
with:
go-version: "1.20"
cache: true
- name: Install kind
run: |
curl -sSLo kind "https://github.com/kubernetes-sigs/kind/releases/download/v0.19.0/kind-linux-amd64"
chmod +x kind
sudo mv kind /usr/local/bin/kind
kind version
- name: Install Kubectl
run: |
curl -sSLO "https://storage.googleapis.com/kubernetes-release/release/v1.26.1/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/kubectl
kubectl version --client --output=yaml
- name: Kubernetes KinD Cluster
run: |
make init-kind
- name: install workflows
run: |
make init-argo-workflows
- name: install gitlab
run: |
tokens=$(make init-gitlab | tail -n1)
GROUP_TOKEN=$(echo "$tokens" | grep -oP "(?<=GROUP_TOKEN )\S+")
echo "GITLAB_TOKEN=$GROUP_TOKEN" >> $GITHUB_ENV
- name: Build Docker Image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: localhost:5001/piper:latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Check tunnel existence
run: |
echo "NGROK_URL=$(cat ~/ngrok.log | grep -o 'url=https://.*' | cut -d '=' -f 2)" >> $GITHUB_ENV
cat ~/ngrok.log | grep -o 'url=https://.*' | cut -d '=' -f 2
- name: init piper
run: |
helm upgrade --install piper ./helm-chart \
-f ./examples/template.values.dev.yaml \
--set piper.gitProvider.name="gitlab" \
--set piper.gitProvider.token="${{ env.GITLAB_TOKEN }}" \
--set piper.gitProvider.url="http://gitlab-webservice-default.gitlab:8080" \
--set piper.gitProvider.webhook.url="http://piper.default/webhook" \
--set piper.gitProvider.webhook.repoList="piper-e2e-test" \
--set piper.gitProvider.organization.name="pied-pipers" \
--set image.repository=localhost:5001 \
--set piper.argoWorkflows.server.address="${{ env.NGROK_URL }}/argo" \
--set-string env\[0\].name=GIT_WEBHOOK_AUTO_CLEANUP,env\[0\].value="true" && \
sleep 20 && kubectl logs deployment/piper
kubectl wait \
--for=condition=ready pod \
--selector=app=piper \
--timeout=60s
- uses: actions/checkout@v3
with:
repository: "quickube/piper-e2e-test"
path: piper-e2e-test
ref: "main"
- name: inject some changes to piper-e2e-test repo
run: |
mkdir ./gitlab
cd ./gitlab
git clone http://oauth2:${{ env.GITLAB_TOKEN }}@localhost:8080/pied-pipers/piper-e2e-test.git
cp -r ../piper-e2e-test/.workflows ./piper-e2e-test/
cd ./piper-e2e-test
git config user.name 'piper-user'
git config user.email 'piper@example.com'
git add -A
git commit -m "add stuff"
git push
git checkout -b ${{ github.ref_name }}-test
rm ./.workflows/triggers.yaml
cat <<EOF > ./.workflows/triggers.yaml
- events:
- merge_request
- merge_request.open
branches: ["*"]
onStart: ["main.yaml"]
onExit: ["exit.yaml"]
templates: ["templates.yaml"]
EOF
git add -A
git commit -m "${{ github.ref_name }}-test"
git push --set-upstream origin ${{ github.ref_name }}-test -o merge_request.create
- name: Wait for workflow creation
run: |
sleep 10
- name: Check Result
run: |
kubectl logs deployment/piper
kubectl get workflows.argoproj.io -n workflows
BRANCH_VALID_STRING=$(echo ${{ github.ref_name }}-test | tr '[:upper:]' '[:lower:]' | tr '_' '-' | tr -cd 'a-z0-9.\-')
## check if created
RESULT=$(kubectl get workflows.argoproj.io -n workflows --selector=branch=$BRANCH_VALID_STRING --no-headers | grep piper-e2e-test)
[ ! -z "$RESULT" ] && echo "CRD created $RESULT" || { echo "Workflow not exists, existing..."; exit 1; }
## check if status phase not Failed, if yes, show message
RESULT=$(kubectl get workflows.argoproj.io -n workflows --selector=branch=$BRANCH_VALID_STRING --no-headers -o custom-columns="Status:status.phase")
MESSAGE=$(kubectl get workflows.argoproj.io -n workflows --selector=branch=$BRANCH_VALID_STRING --no-headers -o custom-columns="Status:status.message")
[ ! "$RESULT" == "Failed" ] && echo "CRD created $MESSAGE" || { echo "Workflow Failed $MESSAGE, existing..."; exit 1; }
github-e2e-env:
name: Github E2E Tests (on development)
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v3
- uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host
- uses: actions/setup-go@v4
with:
go-version: "1.20"
cache: true
- name: Install Ngrok Tunnel
run: |
curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc | sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null && \
echo "deb https://ngrok-agent.s3.amazonaws.com buster main" | sudo tee /etc/apt/sources.list.d/ngrok.list && \
sudo apt update && \
sudo apt install ngrok
touch ~/ngrok.log
(timeout 30m ngrok http 80 --authtoken ${{ secrets.NGROK_AUTHTOKEN }} --log ~/ngrok.log) &
echo $?
- name: Install kind
run: |
curl -sSLo kind "https://github.com/kubernetes-sigs/kind/releases/download/v0.19.0/kind-linux-amd64"
chmod +x kind
sudo mv kind /usr/local/bin/kind
kind version
- name: Install Kubectl
run: |
curl -sSLO "https://storage.googleapis.com/kubernetes-release/release/v1.26.1/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/kubectl
kubectl version --client --output=yaml
- name: Kubernetes KinD Cluster
run: |
make init-kind
- name: install nginx
run: |
make init-nginx
- name: install workflows
run: |
make init-argo-workflows
- name: Build Docker Image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: localhost:5001/piper:latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Check tunnel existence
run: |
echo "NGROK_URL=$(cat ~/ngrok.log | grep -o 'url=https://.*' | cut -d '=' -f 2)" >> $GITHUB_ENV
cat ~/ngrok.log | grep -o 'url=https://.*' | cut -d '=' -f 2
- name: init piper
run: |
helm upgrade --install piper ./helm-chart \
-f ./examples/template.values.dev.yaml \
--set piper.gitProvider.name="github" \
--set piper.gitProvider.token="${{ secrets.GIT_TOKEN }}" \
--set piper.gitProvider.webhook.url="${{ env.NGROK_URL }}/piper/webhook" \
--set piper.gitProvider.webhook.repoList={piper-e2e-test} \
--set piper.gitProvider.organization.name="quickube" \
--set image.repository=localhost:5001 \
--set piper.argoWorkflows.server.address="${{ env.NGROK_URL }}/argo" \
--set-string env\[0\].name=GIT_WEBHOOK_AUTO_CLEANUP,env\[0\].value="true" && \
sleep 20 && kubectl logs deployment/piper
kubectl wait \
--for=condition=ready pod \
--selector=app=piper \
--timeout=60s
- uses: actions/checkout@v3
with:
repository: "quickube/piper-e2e-test"
path: piper-e2e-test
ref: "main"
- name: inject some changes to piper-e2e-test repo
run: |
cd ./piper-e2e-test
echo "" >> .workflows/triggers.yaml
git config user.name 'e2e-test'
git config user.email 'goshatoo@gmail.com'
git commit -am "trigger e2e test"
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GIT_TOKEN }}
path: piper-e2e-test
branch: ${{ github.ref_name }}-test
title: ${{ github.ref_name }}-test
delete-branch: true
- name: Wait for workflow creation
run: |
sleep 10
- name: Close Pull Request
uses: peter-evans/close-pull@v3
with:
token: ${{ secrets.GIT_TOKEN }}
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
repository: "quickube/piper-e2e-test"
comment: Auto-closing pull request
delete-branch: true
- name: Check Result
run: |
kubectl logs deployment/piper
kubectl get workflows.argoproj.io -n workflows
BRANCH_VALID_STRING=$(echo ${{ github.ref_name }}-test | tr '[:upper:]' '[:lower:]' | tr '_' '-' | tr -cd 'a-z0-9.\-')
## check if created
RESULT=$(kubectl get workflows.argoproj.io -n workflows --selector=branch=$BRANCH_VALID_STRING --no-headers | grep piper-e2e-test)
[ ! -z "$RESULT" ] && echo "CRD created $RESULT" || { echo "Workflow not exists, existing..."; exit 1; }
## check if status phase not Failed, if yes, show message
RESULT=$(kubectl get workflows.argoproj.io -n workflows --selector=branch=$BRANCH_VALID_STRING --no-headers -o custom-columns="Status:status.phase")
MESSAGE=$(kubectl get workflows.argoproj.io -n workflows --selector=branch=$BRANCH_VALID_STRING --no-headers -o custom-columns="Status:status.message")
[ ! "$RESULT" == "Failed" ] && echo "CRD created $MESSAGE" || { echo "Workflow Failed $MESSAGE, existing..."; exit 1; }