Skip to content

Commit 478d1ab

Browse files
committed
automate functional tests in pipeline
1 parent 15bab00 commit 478d1ab

File tree

3 files changed

+139
-0
lines changed

3 files changed

+139
-0
lines changed

.github/workflows/functional.yml

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
name: Functional Testing
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- release-*
8+
tags:
9+
- "v[0-9]+.[0-9]+.[0-9]+*"
10+
pull_request:
11+
12+
defaults:
13+
run:
14+
shell: bash
15+
16+
permissions:
17+
contents: read
18+
19+
jobs:
20+
functional-tests:
21+
name: Gateway Functional Tests
22+
runs-on: ubuntu-22.04
23+
strategy:
24+
matrix:
25+
k8s-version: ["1.23.17", "latest"]
26+
nginx-image: [nginx, nginx-plus]
27+
steps:
28+
- name: Checkout Repository
29+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
30+
31+
- name: Setup Golang Environment
32+
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
33+
with:
34+
go-version: stable
35+
36+
- name: Set GOPATH
37+
run: echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
38+
39+
- name: Docker Buildx
40+
uses: docker/setup-buildx-action@0d103c3126aa41d772a8362f6aa67afac040f80c # v3.1.0
41+
with:
42+
driver-opts: network=host
43+
44+
- name: Output Variables
45+
id: vars
46+
run: echo "go_path=$(go env GOPATH)" >> $GITHUB_OUTPUT
47+
48+
49+
- name: NGF Docker meta
50+
id: ngf-meta
51+
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
52+
with:
53+
images: |
54+
name=ghcr.io/nginxinc/nginx-gateway-fabric
55+
tags: |
56+
type=semver,pattern={{version}}
57+
type=edge
58+
type=ref,event=pr
59+
type=ref,event=branch,suffix=-rc,enable=${{ startsWith(github.ref, 'refs/heads/release') }}
60+
61+
- name: NGINX Docker meta
62+
id: nginx-meta
63+
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
64+
with:
65+
images: |
66+
name=ghcr.io/nginxinc/nginx-gateway-fabric/${{ matrix.nginx-image }}
67+
tags: |
68+
type=semver,pattern={{version}}
69+
type=edge
70+
type=ref,event=pr
71+
type=ref,event=branch,suffix=-rc,enable=${{ startsWith(github.ref, 'refs/heads/release') }}
72+
73+
74+
- name: Build binary
75+
uses: goreleaser/goreleaser-action@7ec5c2b0c6cdda6e8bbb49444bc797dd33d74dd8 # v5.0.0
76+
with:
77+
version: latest
78+
args: build --snapshot --clean
79+
80+
- name: Build NGF Docker Image
81+
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0
82+
with:
83+
file: build/Dockerfile
84+
tags: ${{ steps.ngf-meta.outputs.tags }}
85+
context: "."
86+
load: true
87+
cache-from: type=gha,scope=ngf
88+
cache-to: type=gha,scope=ngf,mode=max
89+
pull: true
90+
target: goreleaser
91+
92+
- name: Build NGINX Docker Image
93+
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0
94+
with:
95+
file: build/Dockerfile${{ matrix.nginx-image == 'nginx' && '.nginx' || '' }}${{ matrix.nginx-image == 'nginx-plus' && '.nginxplus' || ''}}
96+
tags: ${{ steps.nginx-meta.outputs.tags }}
97+
context: "."
98+
load: true
99+
cache-from: type=gha,scope=${{ matrix.nginx-image }}
100+
cache-to: type=gha,scope=${{ matrix.nginx-image }},mode=max
101+
pull: true
102+
build-args: |
103+
NJS_DIR=internal/mode/static/nginx/modules/src
104+
NGINX_CONF_DIR=internal/mode/static/nginx/conf
105+
BUILD_AGENT=gha
106+
107+
- name: Deploy Kubernetes
108+
id: k8s
109+
run: |
110+
k8s_version=${{ matrix.k8s-version }}
111+
make create-kind-cluster KIND_KUBE_CONFIG=${{ github.workspace }}/kube-${{ github.run_id }} ${{ ! contains(matrix.k8s-version, 'latest') && 'KIND_IMAGE=kindest/node:v${k8s_version}' || '' }}
112+
echo "KUBECONFIG=${{ github.workspace }}/kube-${{ github.run_id }}" >> "$GITHUB_ENV"
113+
114+
115+
- name: Wait for release to exist
116+
run: |
117+
REF=${{ github.ref_name }}
118+
until docker pull ghcr.io/nginxinc/nginx-gateway-fabric:${REF}; do sleep 5; done
119+
until docker pull ghcr.io/nginxinc/nginx-gateway-fabric/nginx:${REF}; do sleep 5; done
120+
121+
- name: Setup functional tests
122+
id: setup
123+
run: |
124+
ngf_prefix=ghcr.io/nginxinc/nginx-gateway-fabric
125+
ngf_tag=${{ steps.ngf-meta.outputs.version }}
126+
make load-images${{ matrix.nginx-image == 'nginx-plus' && '-with-plus' || ''}} PREFIX=${ngf_prefix} TAG=${ngf_tag}
127+
working-directory: ./tests
128+
129+
- name: Run functional tests
130+
run: |
131+
ngf_prefix=ghcr.io/nginxinc/nginx-gateway-fabric
132+
ngf_tag=${{ steps.ngf-meta.outputs.version }}
133+
make test${{ matrix.nginx-image == 'nginx-plus' && '-with-plus' || ''}} PREFIX=${ngf_prefix} TAG=${ngf_tag}
134+
working-directory: ./tests

tests/Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ test: ## Runs the functional tests on your default k8s cluster
106106
--pull-policy=$(PULL_POLICY) --k8s-version=$(K8S_VERSION) --service-type=$(GW_SERVICE_TYPE) \
107107
--is-gke-internal-lb=$(GW_SVC_GKE_INTERNAL)
108108

109+
.PHONY: test-with-plus
110+
test-with-plus: ## Runs the functional tests for NGF with NGINX Plus on your default k8s cluster
111+
make test PLUS_ENABLED=true
112+
109113
.PHONY: cleanup-gcp
110114
cleanup-gcp: cleanup-router cleanup-vm delete-gke-cluster ## Cleanup all GCP resources
111115

tests/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ start-longevity-test Start the longevity test to run for 4 days in GKE
6363
stop-longevity-test Stops the longevity test and collects results
6464
sync-files-to-vm Syncs your local NGF files with the NGF repo on the VM
6565
test Runs the functional tests on your default k8s cluster
66+
test-with-plus Runs the functional tests for NGF with NGINX Plus on your default k8s cluster
6667
```
6768

6869
**Note:** The following variables are configurable when running the below `make` commands:

0 commit comments

Comments
 (0)