Skip to content

Commit 09e05b7

Browse files
committed
Automate functional test in the pipeline (nginx#1634)
Problem: As a user, I want to automate functional tests in the pipeline Solution: To run functional tests in the pipeline, we introduce a new github workflow that sets up the environment to run tests, and upload results Testing: Manual testing by pushing to the branch
1 parent 089a646 commit 09e05b7

File tree

3 files changed

+130
-1
lines changed

3 files changed

+130
-1
lines changed

.github/workflows/functional.yml

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal LoadBalancer service which will receive the test traffic.
1515
Directory structure is as follows:
1616

1717
- `framework`: contains utility functions for running the tests
18-
- `results`: contains the results files
18+
- `results`: contains the results files for the NFR tests
1919
- `scripts`: contain scripts used to set up the environment and run the tests
2020
- `suite`: contains the test files
2121

@@ -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)