Skip to content

Commit 1d798c5

Browse files
committed
feat: add e2e tests
1 parent 7f61c61 commit 1d798c5

File tree

13 files changed

+600
-26
lines changed

13 files changed

+600
-26
lines changed

.github/workflows/e2e.yaml

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
name: e2e
2+
on:
3+
issue_comment:
4+
types: [created]
5+
6+
env:
7+
E2E_CHECK_NAME: e2e tests
8+
9+
jobs:
10+
triage:
11+
runs-on: ubuntu-latest
12+
name: Comment evaluate
13+
outputs:
14+
run-e2e: ${{ startsWith(github.event.comment.body,'/run-e2e') && steps.checkUserMember.outputs.isTeamMember == 'true' }}
15+
pr_num: ${{ steps.parser.outputs.pr_num }}
16+
image_tag: "pr-${{ steps.parser.outputs.pr_num }}-${{ steps.parser.outputs.commit_sha }}"
17+
commit_sha: ${{ steps.parser.outputs.commit_sha }}
18+
version_buildflags: ${{ steps.parser.outputs.version_buildflags }}
19+
image_build_hash: ${{ steps.parser.outputs.image_build_hash }}
20+
21+
steps:
22+
- uses: actions/checkout@v3
23+
24+
- uses: tspascoal/get-user-teams-membership@v2
25+
id: checkUserMember
26+
with:
27+
username: ${{ github.actor }}
28+
team: 'dev'
29+
GITHUB_TOKEN: ${{ secrets.GH_CHECKING_USER_AUTH }}
30+
31+
- name: Update comment with the execution url
32+
if: ${{ startsWith(github.event.comment.body,'/run-e2e') && steps.checkUserMember.outputs.isTeamMember == 'true' }}
33+
uses: peter-evans/create-or-update-comment@v2
34+
with:
35+
comment-id: ${{ github.event.comment.id }}
36+
body: |
37+
**Update:** You can check the progress [here](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}})
38+
reactions: rocket
39+
40+
- name: Parse git info
41+
if: ${{ startsWith(github.event.comment.body,'/run-e2e') && steps.checkUserMember.outputs.isTeamMember == 'true' }}
42+
id: parser
43+
env:
44+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
run: |
46+
# Get PR number
47+
PR_URL="${{ github.event.issue.pull_request.url }}"
48+
PR_NUM=${PR_URL##*/}
49+
echo "Checking out from PR #$PR_NUM based on URL: $PR_URL"
50+
echo "::set-output name=pr_num::$PR_NUM"
51+
# Get commit SHA
52+
git config --global --add safe.directory "$GITHUB_WORKSPACE"
53+
gh pr checkout $PR_NUM
54+
SHA=$(git log -n 1 --pretty=format:"%H")
55+
echo "::set-output name=commit_sha::$SHA"
56+
GIT_COMMIT=$(git describe --match=NeVeRmAtCh --tags --always --dirty | cut -c 1-7)
57+
BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)
58+
VERSION=$(git describe --tags `git rev-list --tags --max-count=1` | sed 's/v\(\)/\1/')
59+
PKG=github.com/bentoml/yatai-image-builder
60+
VERSION_BUILDFLAGS="-X '${PKG}/version.GitCommit=${GIT_COMMIT}' -X '${PKG}/version.Version=${VERSION}' -X '${PKG}/version.BuildDate=${BUILD_DATE}'"
61+
echo "::set-output name=version_buildflags::$VERSION_BUILDFLAGS"
62+
echo "::set-output name=image_build_hash::${{ hashFiles('Dockerfile', 'main.go', './apis/**', './controllers/**', './utils/**', './version/**', './yatai-client/**', '**/go.sum', '**go.mod') }}"
63+
64+
build-test-images:
65+
needs: triage
66+
if: needs.triage.outputs.run-e2e == 'true'
67+
runs-on: ubuntu-latest
68+
steps:
69+
- name: Set status in-progress
70+
uses: LouisBrunner/[email protected]
71+
with:
72+
token: ${{ secrets.GITHUB_TOKEN }}
73+
sha: ${{ needs.triage.outputs.commit_sha }}
74+
name: ${{ env.E2E_CHECK_NAME }}
75+
status: in_progress
76+
details_url: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
77+
78+
- uses: actions/checkout@v3
79+
80+
- name: Register workspace path
81+
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
82+
83+
- name: Checkout Pull Request
84+
env:
85+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86+
id: checkout
87+
run: |
88+
gh pr checkout ${{ needs.triage.outputs.pr_num }}
89+
90+
- name: Set up Docker Buildx
91+
id: buildx
92+
# Use the action from the master, as we've seen some inconsistencies with @v1
93+
# Issue: https://github.com/docker/build-push-action/issues/286
94+
uses: docker/setup-buildx-action@master
95+
with:
96+
install: true
97+
98+
- name: Login to Quay.io
99+
uses: docker/login-action@v1
100+
with:
101+
registry: quay.io
102+
username: ${{ secrets.QUAY_USERNAME }}
103+
password: ${{ secrets.QUAY_ROBOT_TOKEN }}
104+
105+
- name: Cache Docker layers
106+
uses: actions/cache@v2
107+
with:
108+
path: /tmp/.buildx-cache
109+
# Key is named differently to avoid collision
110+
key: ${{ runner.os }}-multi-buildx-${{ needs.triage.outputs.image_build_hash }}
111+
restore-keys: |
112+
${{ runner.os }}-multi-buildx
113+
114+
- name: Build test image
115+
uses: docker/build-push-action@v2
116+
with:
117+
build-args: 'VERSION_BUILDFLAGS=${{ needs.triage.outputs.version_buildflags }}'
118+
context: .
119+
push: true
120+
tags: quay.io/bentoml/test-yatai-image-builder:${{ needs.triage.outputs.image_tag }}
121+
cache-from: type=local,src=/tmp/.buildx-cache
122+
# Note the mode=max here
123+
# More: https://github.com/moby/buildkit#--export-cache-options
124+
# And: https://github.com/docker/buildx#--cache-tonametypetypekeyvalue
125+
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
126+
127+
- name: Move cache
128+
run: |
129+
rm -rf /tmp/.buildx-cache
130+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
131+
132+
run-test:
133+
needs: [triage, build-test-images]
134+
if: needs.triage.outputs.run-e2e == 'true'
135+
runs-on: ubuntu-latest
136+
steps:
137+
- name: Set status in-progress
138+
uses: LouisBrunner/[email protected]
139+
with:
140+
token: ${{ secrets.GITHUB_TOKEN }}
141+
sha: ${{ needs.triage.outputs.commit_sha }}
142+
name: ${{ env.E2E_CHECK_NAME }}
143+
status: in_progress
144+
details_url: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
145+
146+
- name: Checkout
147+
uses: actions/checkout@v3
148+
149+
- name: Register workspace path
150+
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
151+
152+
- name: Checkout Pull Request
153+
env:
154+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
155+
id: checkout
156+
run: |
157+
gh pr checkout ${{ needs.triage.outputs.pr_num }}
158+
159+
- name: Install KinD
160+
run: ./tests/gh-actions/install_kind.sh
161+
162+
- name: Install Helm
163+
run: ./tests/gh-actions/install_helm.sh
164+
165+
- name: Create KinD Cluster
166+
run: kind create cluster --config tests/gh-actions/kind-cluster-1-24.yaml
167+
168+
- uses: oNaiPs/secrets-to-env-action@v1
169+
with:
170+
secrets: ${{ toJSON(secrets) }}
171+
172+
- name: Run e2e test
173+
continue-on-error: true
174+
id: test
175+
env:
176+
YATAI_DEPLOYMENT_IMG_REPO: test-yatai-image-builder
177+
YATAI_DEPLOYMENT_IMG_TAG: ${{ needs.triage.outputs.image_tag }}
178+
run: |
179+
./tests/e2e/installation_test.sh
180+
make test-e2e
181+
182+
- name: Set status success
183+
uses: LouisBrunner/[email protected]
184+
if: steps.test.outcome == 'success'
185+
with:
186+
token: ${{ secrets.GITHUB_TOKEN }}
187+
sha: ${{ needs.triage.outputs.commit_sha }}
188+
name: ${{ env.E2E_CHECK_NAME }}
189+
conclusion: success
190+
details_url: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
191+
192+
- name: React to comment with success
193+
uses: dkershner6/reaction-action@v1
194+
if: steps.test.outcome == 'success'
195+
with:
196+
token: ${{ secrets.GITHUB_TOKEN }}
197+
commentId: ${{ github.event.comment.id }}
198+
reaction: "hooray"
199+
200+
- name: React to comment with failure
201+
uses: dkershner6/reaction-action@v1
202+
if: steps.test.outcome != 'success'
203+
with:
204+
token: ${{ secrets.GITHUB_TOKEN }}
205+
commentId: ${{ github.event.comment.id }}
206+
reaction: "confused"
207+
208+
- name: Set status failure
209+
uses: LouisBrunner/[email protected]
210+
if: steps.test.outcome != 'success'
211+
with:
212+
token: ${{ secrets.GITHUB_TOKEN }}
213+
sha: ${{ needs.triage.outputs.commit_sha }}
214+
name: ${{ env.E2E_CHECK_NAME }}
215+
conclusion: failure
216+
details_url: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ vet: ## Run go vet against code.
112112
test: manifests generate fmt vet envtest ## Run tests.
113113
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
114114

115+
.PHONY: test-e2e # You will need to have a Kind cluster up in running to run this target
116+
test-e2e:
117+
go test ./tests/e2e/ -v -ginkgo.v -timeout 20m
118+
115119
##@ Build
116120

117121
.PHONY: build

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/huandu/xstrings v1.3.2
1010
github.com/iancoleman/strcase v0.2.0
1111
github.com/onsi/ginkgo v1.16.5
12+
github.com/onsi/ginkgo/v2 v2.1.4
1213
github.com/onsi/gomega v1.19.0
1314
github.com/pkg/errors v0.9.1
1415
github.com/sirupsen/logrus v1.8.1

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108
317317
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
318318
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
319319
github.com/onsi/ginkgo/v2 v2.1.4 h1:GNapqRSid3zijZ9H77KrgVG4/8KqiyRsxcSxe+7ApXY=
320+
github.com/onsi/ginkgo/v2 v2.1.4/go.mod h1:um6tUpWM/cxCK3/FK8BXqEiUMUwRgSM4JXG47RKZmLU=
320321
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
321322
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
322323
github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw=

scripts/quick-install-yatai-image-builder.sh

Lines changed: 60 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,9 @@ DOCKER_REGISTRY_PASSWORD=''
194194
DOCKER_REGISTRY_SECURE=false
195195
DOCKER_REGISTRY_BENTO_REPOSITORY_NAME=yatai-bentos
196196

197-
helm_repo_name=bentoml
198-
helm_repo_url=https://bentoml.github.io/helm-charts
199-
200-
# check if DEVEL_HELM_REPO is true
201-
if [ "${DEVEL_HELM_REPO}" = "true" ]; then
202-
helm_repo_name=bentoml-devel
203-
helm_repo_url=https://bentoml.github.io/helm-charts-devel
197+
YATAI_ENDPOINT=${YATAI_ENDPOINT:-http://yatai.yatai-system.svc.cluster.local}
198+
if [ "${YATAI_ENDPOINT}" = "empty" ]; then
199+
YATAI_ENDPOINT=""
204200
fi
205201

206202
UPGRADE_CRDS=${UPGRADE_CRDS:-false}
@@ -216,27 +212,65 @@ if [ "${UPGRADE_CRDS}" = "true" ]; then
216212
echo "✅ Bento CRD are established"
217213
fi
218214

219-
helm repo remove ${helm_repo_name} 2> /dev/null || true
220-
helm repo add ${helm_repo_name} ${helm_repo_url}
221-
helm repo update ${helm_repo_name}
215+
USE_LOCAL_HELM_CHART=${USE_LOCAL_HELM_CHART:-false}
222216

223-
# if $VERSION is not set, use the latest version
224-
if [ -z "$VERSION" ]; then
225-
VERSION=$(helm search repo ${helm_repo_name} --devel="$DEVEL" -l | grep "${helm_repo_name}/yatai-image-builder " | awk '{print $2}' | head -n 1)
226-
fi
217+
if [ "${USE_LOCAL_HELM_CHART}" = "true" ]; then
218+
YATAI_IMAGE_BUILDER_IMG_REGISTRY=${YATAI_IMAGE_BUILDER_IMG_REGISTRY:-quay.io/bentoml}
219+
YATAI_IMAGE_BUILDER_IMG_REPO=${YATAI_IMAGE_BUILDER_IMG_REPO:-yatai-image-builder}
220+
YATAI_IMAGE_BUILDER_IMG_TAG=${YATAI_IMAGE_BUILDER_IMG_TAG:-0.0.1}
221+
222+
echo "🤖 installing yatai-image-builder from local helm chart..."
223+
helm upgrade --install yatai-image-builder ./helm/yatai-image-builder -n ${namespace} \
224+
--set registry=${YATAI_IMAGE_BUILDER_IMG_REGISTRY} \
225+
--set image.repository=${YATAI_IMAGE_BUILDER_IMG_REPO} \
226+
--set image.tag=${YATAI_IMAGE_BUILDER_IMG_TAG} \
227+
--set yatai.endpoint=${YATAI_ENDPOINT} \
228+
--set dockerRegistry.server=${DOCKER_REGISTRY_SERVER} \
229+
--set dockerRegistry.inClusterServer=${DOCKER_REGISTRY_IN_CLUSTER_SERVER} \
230+
--set dockerRegistry.username=${DOCKER_REGISTRY_USERNAME} \
231+
--set dockerRegistry.password=${DOCKER_REGISTRY_PASSWORD} \
232+
--set dockerRegistry.secure=${DOCKER_REGISTRY_SECURE} \
233+
--set dockerRegistry.bentoRepositoryName=${DOCKER_REGISTRY_BENTO_REPOSITORY_NAME} \
234+
--set aws.accessKeyID=${AWS_ACCESS_KEY_ID} \
235+
--set aws.secretAccessKeyExistingSecretName=${AWS_SECRET_ACCESS_KEY_EXISTING_SECRET_NAME} \
236+
--set aws.secretAccessKeyExistingSecretKey=${AWS_SECRET_ACCESS_KEY_EXISTING_SECRET_KEY} \
237+
--skip-crds=${UPGRADE_CRDS}
238+
else
239+
helm_repo_name=bentoml
240+
helm_repo_url=https://bentoml.github.io/helm-charts
227241

228-
echo "🤖 installing yatai-image-builder ${VERSION} from helm repo ${helm_repo_name}..."
229-
helm upgrade --install yatai-image-builder ${helm_repo_name}/yatai-image-builder -n ${namespace} \
230-
--set dockerRegistry.server=${DOCKER_REGISTRY_SERVER} \
231-
--set dockerRegistry.inClusterServer=${DOCKER_REGISTRY_IN_CLUSTER_SERVER} \
232-
--set dockerRegistry.username=${DOCKER_REGISTRY_USERNAME} \
233-
--set dockerRegistry.password=${DOCKER_REGISTRY_PASSWORD} \
234-
--set dockerRegistry.secure=${DOCKER_REGISTRY_SECURE} \
235-
--set dockerRegistry.bentoRepositoryName=${DOCKER_REGISTRY_BENTO_REPOSITORY_NAME} \
236-
--set yatai.endpoint=${YATAI_ENDPOINT} \
237-
--skip-crds=${UPGRADE_CRDS} \
238-
--version=${VERSION} \
239-
--devel=${DEVEL}
242+
# check if DEVEL_HELM_REPO is true
243+
if [ "${DEVEL_HELM_REPO}" = "true" ]; then
244+
helm_repo_name=bentoml-devel
245+
helm_repo_url=https://bentoml.github.io/helm-charts-devel
246+
fi
247+
248+
helm repo remove ${helm_repo_name} 2> /dev/null || true
249+
helm repo add ${helm_repo_name} ${helm_repo_url}
250+
helm repo update ${helm_repo_name}
251+
252+
# if $VERSION is not set, use the latest version
253+
if [ -z "$VERSION" ]; then
254+
VERSION=$(helm search repo ${helm_repo_name} --devel="$DEVEL" -l | grep "${helm_repo_name}/yatai-image-builder " | awk '{print $2}' | head -n 1)
255+
fi
256+
257+
echo "🤖 installing yatai-image-builder ${VERSION} from helm repo ${helm_repo_name}..."
258+
helm upgrade --install yatai-image-builder ${helm_repo_name}/yatai-image-builder -n ${namespace} \
259+
--set yatai.endpoint=${YATAI_ENDPOINT} \
260+
--set dockerRegistry.server=${DOCKER_REGISTRY_SERVER} \
261+
--set dockerRegistry.inClusterServer=${DOCKER_REGISTRY_IN_CLUSTER_SERVER} \
262+
--set dockerRegistry.username=${DOCKER_REGISTRY_USERNAME} \
263+
--set dockerRegistry.password=${DOCKER_REGISTRY_PASSWORD} \
264+
--set dockerRegistry.secure=${DOCKER_REGISTRY_SECURE} \
265+
--set dockerRegistry.bentoRepositoryName=${DOCKER_REGISTRY_BENTO_REPOSITORY_NAME} \
266+
--set yatai.endpoint=${YATAI_ENDPOINT} \
267+
--set aws.accessKeyID=${AWS_ACCESS_KEY_ID} \
268+
--set aws.secretAccessKeyExistingSecretName=${AWS_SECRET_ACCESS_KEY_EXISTING_SECRET_NAME} \
269+
--set aws.secretAccessKeyExistingSecretKey=${AWS_SECRET_ACCESS_KEY_EXISTING_SECRET_KEY} \
270+
--skip-crds=${UPGRADE_CRDS} \
271+
--version=${VERSION} \
272+
--devel=${DEVEL}
273+
fi
240274

241275
kubectl -n ${namespace} rollout restart deploy/yatai-image-builder
242276

tests/e2e/e2e_suite_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package e2e
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
. "github.com/onsi/ginkgo/v2"
8+
. "github.com/onsi/gomega"
9+
)
10+
11+
// Run e2e tests using the Ginkgo runner.
12+
func TestE2E(t *testing.T) {
13+
RegisterFailHandler(Fail)
14+
fmt.Fprintf(GinkgoWriter, "Starting yatai-image-builder e2e suite\n")
15+
RunSpecs(t, "yatai-image-builder e2e suite")
16+
}

0 commit comments

Comments
 (0)