Skip to content

Commit ab98587

Browse files
jentingroboquat
authored andcommitted
Change workspace integration test from core-dev to preview environment
Signed-off-by: JenTing Hsiao <[email protected]>
1 parent 2d40ac9 commit ab98587

File tree

2 files changed

+113
-190
lines changed

2 files changed

+113
-190
lines changed

.werft/workspace-integration-tests-startup-cron.yaml

Lines changed: 0 additions & 111 deletions
This file was deleted.
Lines changed: 113 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
args:
2-
- name: version
3-
desc: "The version of the integration tests to use"
4-
required: true
5-
- name: namespace
6-
desc: "The namespace to run the integration test against"
7-
required: true
8-
- name: testPattern
9-
desc: "The test file pattern to filter the tests to run"
10-
required: false
111
pod:
122
serviceAccount: werft
133
nodeSelector:
@@ -18,55 +8,18 @@ pod:
188
- name: gcp-sa
199
secret:
2010
secretName: gcp-sa-gitpod-dev-deployer
21-
- name: integration-test-user
22-
secret:
23-
secretName: integration-test-user
2411
- name: config
2512
emptyDir: {}
26-
initContainers:
13+
containers:
2714
- name: gcloud
2815
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:cw-werft-cred.0
2916
workingDir: /workspace
3017
imagePullPolicy: IfNotPresent
31-
volumeMounts:
32-
- name: gcp-sa
33-
mountPath: /mnt/secrets/gcp-sa
34-
readOnly: true
35-
- name: config
36-
mountPath: /config
37-
readOnly: false
38-
command:
39-
- bash
40-
- -c
41-
- |
42-
43-
echo "[prep] preparing config."
44-
45-
gcloud auth activate-service-account --key-file /mnt/secrets/gcp-sa/service-account.json
46-
cp -R /home/gitpod/.config/gcloud /config/gcloud
47-
cp /home/gitpod/.kube/config /config/kubeconfig
48-
49-
echo "[prep] copied config..."
50-
containers:
51-
- name: tests
52-
image: eu.gcr.io/gitpod-core-dev/build/integration-tests:{{ .Annotations.version }}
53-
workingDir: /workspace
54-
imagePullPolicy: IfNotPresent
55-
volumeMounts:
56-
- name: config
57-
mountPath: /config
58-
readOnly: true
5918
env:
60-
- name: USERNAME
19+
- name: NODENAME
6120
valueFrom:
62-
secretKeyRef:
63-
name: integration-test-user
64-
key: username
65-
- name: USER_TOKEN
66-
valueFrom:
67-
secretKeyRef:
68-
name: integration-test-user
69-
key: token
21+
fieldRef:
22+
fieldPath: spec.nodeName
7023
- name: ROBOQUAT_TOKEN
7124
valueFrom:
7225
secretKeyRef:
@@ -77,59 +30,140 @@ pod:
7730
secretKeyRef:
7831
name: slack-webhook-urls
7932
key: workspace_jobs
33+
- name: USERNAME
34+
valueFrom:
35+
secretKeyRef:
36+
name: integration-test-user
37+
key: username
38+
- name: USER_TOKEN
39+
valueFrom:
40+
secretKeyRef:
41+
name: integration-test-user
42+
key: token
43+
volumeMounts:
44+
- name: gcp-sa
45+
mountPath: /mnt/secrets/gcp-sa
46+
readOnly: true
47+
- name: config
48+
mountPath: /config
49+
readOnly: false
8050
command:
81-
- /bin/bash
51+
- bash
8252
- -c
8353
- |
8454
set -euo
8555
86-
printf '{{ toJson .Annotations }}' > context.json
56+
BRANCH="inte-test/"$(date +%Y%m%d%H%M%S)
57+
export WERFT_CREDENTIAL_HELPER=/workspace/dev/preview/werft-credential-helper.sh
8758
88-
echo "[prep] receiving config..."
89-
export GOOGLE_APPLICATION_CREDENTIALS="/config/gcloud/legacy_credentials/[email protected]/adc.json"
90-
echo "[prep] received config."
59+
function cleanup ()
60+
{
61+
werft log phase "clean up" "clean up"
62+
git push origin :$BRANCH | werft log slice "clean up"
63+
werft log slice "clean up" --done
64+
}
9165
92-
echo "[prep] using username: $USERNAME"
93-
94-
TEST_PATTERN="{{ .Annotations.testPattern }}"
95-
if [[ "$TEST_PATTERN" == "<no value>" ]]; then
96-
TEST_PATTERN=""
66+
echo "preparing config." | werft log slice prepare
67+
sudo chown -R gitpod:gitpod /workspace
68+
gcloud auth activate-service-account --key-file /mnt/secrets/gcp-sa/service-account.json
69+
export GOOGLE_APPLICATION_CREDENTIALS="/home/gitpod/.config/gcloud/legacy_credentials/[email protected]/adc.json"
70+
71+
git config --global user.name roboquat
72+
git config --global user.email [email protected]
73+
git remote set-url origin https://oauth2:[email protected]/gitpod-io/gitpod.git
74+
75+
echo "copied config..." | werft log slice prepare
76+
go install github.com/csweichel/oci-tool@latest 2>&1 | werft log slice prepare
77+
werft log slice prepare --done
78+
79+
werft log phase "build preview environment" "build preview environment"
80+
echo integration test >> README.md
81+
git checkout -B $BRANCH
82+
git add README.md
83+
git commit -m "integration test"
84+
git push --set-upstream origin $BRANCH
85+
trap cleanup SIGINT SIGTERM EXIT
86+
87+
BUILD_ID=$(werft job list repo.ref==refs/heads/${BRANCH} -o yaml | yq r - "result[0].name")
88+
until [ "$BUILD_ID" != "" ]
89+
do
90+
sleep 1
91+
BUILD_ID=$(werft job list repo.ref==refs/heads/${BRANCH} -o yaml | yq r - "result[0].name")
92+
done
93+
echo "start build preview environment, job name: ${BUILD_ID}, this will take long time" | werft log slice "build preview environment"
94+
werft log result -d "build job" url "https://werft.gitpod-dev.com/job/${BUILD_ID}"
95+
96+
if ! werft job logs ${BUILD_ID} | werft log slice "build preview environment";
97+
then
98+
echo "build failed" | werft log slice "build preview environment"
99+
exit 1
97100
fi
98-
echo "[prep] using testPattern: $TEST_PATTERN"
101+
echo "build success" | werft log slice "build preview environment"
102+
werft log slice "build preview environment" --done
99103
104+
werft log phase "kubectx" "kubectx"
105+
mkdir -p /home/gitpod/.ssh
106+
/workspace/dev/preview/util/download-and-merge-harvester-kubeconfig.sh | werft log slice "kubectx"
107+
/workspace/dev/preview/install-k3s-kubeconfig.sh | werft log slice "kubectx"
108+
werft log slice "kubectx" --done
109+
110+
werft log phase "integration test" "integration test"
100111
args=()
101-
[[ "$TEST_PATTERN" != "" ]] && args+=( "-testPattern=$TEST_PATTERN" )
102-
args+=( '-kubeconfig=/config/kubeconfig' )
103-
args+=( "-namespace={{ .Annotations.namespace }}" )
112+
args+=( "-kubeconfig=/home/gitpod/.kube/config" )
113+
args+=( "-namespace=default" )
104114
[[ "$USERNAME" != "" ]] && args+=( "-username=$USERNAME" )
105-
echo "[prep|DONE]"
106115
107-
/entrypoint.sh "${args[@]}" 2>&1 | tee entrypoint.sh.log | ts "[int-tests] "
116+
WK_TEST_LIST=(/workspace/test/tests/components/content-service /workspace/test/tests/components/image-builder /workspace/test/tests/components/ws-daemon /workspace/test/tests/components/ws-manager /workspace/test/tests/workspace)
117+
118+
FAILURE_COUNT=0
119+
declare -A FAILURE_TESTS
120+
for TEST_PATH in "${WK_TEST_LIST[@]}"
121+
do
122+
TEST_NAME=$(basename "${TEST_PATH}")
123+
echo "running integration for ${TEST_NAME}" | werft log slice "test-${TEST_NAME}"
108124
109-
RC=${PIPESTATUS[0]}
125+
cd "${TEST_PATH}"
126+
go test -v ./... "${args[@]}" 2>&1 | tee "${TEST_NAME}".log | werft log slice "test-${TEST_NAME}"
127+
128+
129+
if [ "${PIPESTATUS[0]}" -ne "0" ]; then
130+
FAILURE_COUNT=$((FAILURE_COUNT+1))
131+
FAILURE_TESTS["${TEST_NAME}"]=$(grep "\-\-\- FAIL: " "${TEST_PATH}"/"${TEST_NAME}".log)
132+
werft log slice "test-${TEST_NAME}" --fail "${PIPESTATUS[0]}"
133+
else
134+
werft log slice "test-${TEST_NAME}" --done
135+
fi
136+
done
137+
138+
werft log phase "slack notification" "slack notification"
110139
context_name={{ .Name }}
111140
context_repo={{ .Repository.Repo }}
112141
werftJobUrl="https://werft.gitpod-dev.com/job/${context_name}"
113142
114-
if [ $RC -eq 1 ]; then
143+
if [ "${FAILURE_COUNT}" -ne "0" ]; then
115144
title=":x: *Workspace integration test fail*"
116-
117-
title=$title"\n_Repo:_ ${context_repo}\n_Build:_ ${context_name}\n_TestPattern_: {{ .Annotations.testPattern }}"
118-
errors=$(grep "\-\-\- FAIL: " entrypoint.sh.log)
119-
BODY="{\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"${title}\"},\"accessory\":{\"type\":\"button\",\"text\":{\"type\":\"plain_text\",\"text\":\":werft: Go to Werft\",\"emoji\":true},\"value\":\"click_me_123\",\"url\":\"${werftJobUrl}\",\"action_id\":\"button-action\"}},{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"\`\`\`\\n${errors}\\n\`\`\`\"}}]}"
120-
121-
echo "[int-tests|FAIL]"
145+
title=$title"\n_Repo:_ ${context_repo}\n_Build:_ ${context_name}"
146+
147+
errs=""
148+
for TEST_NAME in ${!FAILURE_TESTS[*]}; do
149+
title=$title"\n_Tests_: ${TEST_NAME}"
150+
errs+="${FAILURE_TESTS["${TEST_NAME}"]}"
151+
done
152+
errs=$(echo "${errs}" | head)
153+
BODY="{\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"${title}\"},\"accessory\":{\"type\":\"button\",\"text\":{\"type\":\"plain_text\",\"text\":\":werft: Go to Werft\",\"emoji\":true},\"value\":\"click_me_123\",\"url\":\"${werftJobUrl}\",\"action_id\":\"button-action\"}},{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"\`\`\`\\n${errs}\\n\`\`\`\"}}]}"
122154
else
123155
title=":white_check_mark: *Workspace integration test pass*"
124156
125-
title=$title"\n_Repo:_ ${context_repo}\n_Build:_ ${context_name}\n_TestPattern_: {{ .Annotations.testPattern }}"
157+
title=$title"\n_Repo:_ ${context_repo}\n_Build:_ ${context_name}"
126158
BODY="{\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"${title}\"},\"accessory\":{\"type\":\"button\",\"text\":{\"type\":\"plain_text\",\"text\":\":werft: Go to Werft\",\"emoji\":true},\"value\":\"click_me_123\",\"url\":\"${werftJobUrl}\",\"action_id\":\"button-action\"}}]}"
127-
128-
echo "[int-tests|DONE]"
129159
fi
130160
131161
curl -X POST \
132162
-H 'Content-type: application/json' \
133163
-d "${BODY}" \
134164
"https://hooks.slack.com/${SLACK_NOTIFICATION_PATH}"
135-
exit $RC
165+
werft log result "slack notification" "${PIPESTATUS[0]}"
166+
167+
exit $FAILURE_COUNT
168+
plugins:
169+
cron: "@midnight"

0 commit comments

Comments
 (0)