Skip to content

Commit 4623bb4

Browse files
committed
BUILD: ci: speed up ci with parallel start e2e stages
1 parent 48e9e92 commit 4623bb4

File tree

3 files changed

+65
-11
lines changed

3 files changed

+65
-11
lines changed

.gitlab-ci.yml

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ stages:
22
- diff
33
- lint
44
- unit-tests
5+
- build
56
- e2e-tests
67
variables:
78
KUBECTL: v1.24.3
@@ -25,6 +26,7 @@ diff:
2526
- branches
2627
tidy:
2728
stage: lint
29+
needs: []
2830
image:
2931
name: $CI_REGISTRY_GO/golang:1.19
3032
entrypoint: [""]
@@ -38,6 +40,7 @@ tidy:
3840
- branches
3941
golangci_lint:
4042
stage: lint
43+
needs: []
4144
image:
4245
name: $CI_REGISTRY_GO/lint:1.33
4346
entrypoint: [""]
@@ -50,6 +53,7 @@ golangci_lint:
5053
- branches
5154
lint-commit-msg:
5255
stage: lint
56+
needs: []
5357
image:
5458
name: $CI_REGISTRY_GO/check-commit:v2.1.0
5559
entrypoint: [""]
@@ -60,6 +64,7 @@ lint-commit-msg:
6064
only:
6165
- merge_requests
6266
unit-tests:
67+
needs: ["diff", "tidy"]
6368
stage: unit-tests
6469
image:
6570
name: $CI_REGISTRY_GO/haproxy-alpine:2.5-go1.19
@@ -72,8 +77,9 @@ unit-tests:
7277
only:
7378
- merge_requests
7479
- branches
75-
.kind_deployment:
76-
stage: e2e-tests
80+
docker-build:
81+
stage: build
82+
needs: []
7783
image: $CI_REGISTRY_GO/docker:stable-go1.19
7884
services:
7985
- name: $CI_REGISTRY_GO/docker:18.09.7-dind
@@ -82,12 +88,46 @@ unit-tests:
8288
- go
8389
before_script:
8490
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY_GO
85-
script:
8691
- go version
87-
- docker pull $CI_REGISTRY_GO/alpine:3
92+
- docker pull -q $CI_REGISTRY_GO/alpine:3
8893
- docker image tag $CI_REGISTRY_GO/alpine:3 alpine:3
89-
- docker pull $CI_REGISTRY_GO/golang:1.19-alpine
94+
- docker pull -q $CI_REGISTRY_GO/golang:1.19-alpine
9095
- docker image tag $CI_REGISTRY_GO/golang:1.19-alpine golang:1.19-alpine
96+
- sed -i "s~FROM golang~FROM $CI_REGISTRY_GO/golang~g" "build/Dockerfile"
97+
- sed -i "s~FROM haproxytech/haproxy-alpine~FROM $CI_REGISTRY_GO/haproxy-alpine~g" "build/Dockerfile"
98+
script:
99+
- mkdir -p tar
100+
- make build
101+
- docker save -o tar/k8sIC.tar haproxytech/kubernetes-ingress:latest
102+
artifacts:
103+
when: on_success
104+
paths:
105+
- tar
106+
expire_in: 15 minutes
107+
.kind_deployment:
108+
stage: e2e-tests
109+
needs: ["diff", "tidy", "docker-build"]
110+
image: $CI_REGISTRY_GO/docker:stable-go1.19
111+
services:
112+
- name: $CI_REGISTRY_GO/docker:18.09.7-dind
113+
alias: docker
114+
tags:
115+
- go
116+
artifacts:
117+
paths:
118+
- tar
119+
expire_in: 30 minutes
120+
before_script:
121+
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY_GO
122+
- docker load -i tar/k8sIC.tar
123+
- go version
124+
- go mod download &
125+
#- docker pull -q $CI_REGISTRY_GO/alpine:3
126+
#- docker image tag $CI_REGISTRY_GO/alpine:3 alpine:3
127+
#- docker pull -q $CI_REGISTRY_GO/golang:1.19-alpine
128+
#- docker image tag $CI_REGISTRY_GO/golang:1.19-alpine golang:1.19-alpine
129+
- docker pull -q $CI_REGISTRY_GO/haproxytech/http-echo:latest
130+
- docker image tag $CI_REGISTRY_GO/haproxytech/http-echo:latest haproxytech/http-echo:latest
91131
- wget -nv -O /usr/local/bin/kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND}/kind-linux-amd64
92132
- chmod +x /usr/local/bin/kind
93133
- wget -nv -O /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/${KUBECTL}/bin/linux/amd64/kubectl
@@ -102,16 +142,20 @@ unit-tests:
102142
- sed -i -E -e "s/localhost|0\.0\.0\.0|127\.0\.0\.1/docker/g" "deploy/tests/e2e/client.go"
103143
- until kubectl get nodes -o wide;do sleep 2; done
104144
- kubectl get pods -A
105-
- CI_ENV=gitlab deploy/tests/create.sh
106-
- kubectl get pods -A
107-
- KIND_URL=docker CGO_ENABLED=0 go test -v ./deploy/tests/e2e/... --tags=e2e_parallel
108-
- KIND_URL=docker CGO_ENABLED=0 go test -v -p 1 ./deploy/tests/e2e/... --tags=e2e_sequential
109145
after_script:
110146
- kubectl get pods -A
111147
- kind delete cluster --name=dev
112148
only:
113149
- merge_requests
114150
- branches
151+
parallel:
152+
matrix:
153+
- TEST_PART: [ "18#e2e_parallel", "1#e2e_sequential" ]
154+
VAR_DUMMY: "YES"
155+
script:
156+
- CI_ENV=gitlab deploy/tests/create.sh
157+
- kubectl get pods -A
158+
- IFS='#' read -r -a array <<< $TEST_PART; KIND_URL=docker CGO_ENABLED=0 go test -v -p ${array[0]} ./deploy/tests/e2e/... --tags=${array[1]}
115159
.kind_deployment_schedules:
116160
only:
117161
- schedules

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ test:
77

88
.PHONY: e2e
99
e2e:
10+
go clean -testcache
1011
go test ./... --tags=e2e_parallel
1112
go test ./... -p 1 --tags=e2e_sequential
1213

deploy/tests/create.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ if [ -n "${CI_ENV}" ]; then
99
echo "cluster was already created by $CI_ENV CI"
1010

1111
echo "building image for ingress controller"
12-
docker build --build-arg TARGETPLATFORM="linux/amd64" -t haproxytech/kubernetes-ingress -f build/Dockerfile .
12+
if [ -n "${GITLAB_CI}" ]; then
13+
echo "haproxytech/kubernetes-ingress image already available from previous stage"
14+
#docker build --build-arg TARGETPLATFORM="linux/amd64" -t haproxytech/kubernetes-ingress -f build/Dockerfile .
15+
else
16+
docker build --build-arg TARGETPLATFORM="linux/amd64" -t haproxytech/kubernetes-ingress -f build/Dockerfile .
17+
fi
1318

1419
echo "loading image of ingress controller in kind"
1520
kind load docker-image haproxytech/kubernetes-ingress:latest --name=$clustername
@@ -31,7 +36,11 @@ else
3136
kind load docker-image haproxytech/kubernetes-ingress:latest --name=$clustername
3237
fi
3338

34-
docker build --build-arg TARGETPLATFORM="linux/amd64" -t haproxytech/http-echo -f deploy/tests/images/http-echo/Dockerfile deploy/tests/images/http-echo
39+
if [ -n "${GITLAB_CI}" ]; then
40+
echo "haproxytech/http-echo:latest pulled from CI registry"
41+
else
42+
docker build --build-arg TARGETPLATFORM="linux/amd64" -t haproxytech/http-echo -f deploy/tests/images/http-echo/Dockerfile deploy/tests/images/http-echo
43+
fi
3544
echo "loading image http-echo in kind"
3645
kind load docker-image haproxytech/http-echo:latest --name=$clustername
3746

0 commit comments

Comments
 (0)