Skip to content

Commit c726876

Browse files
committed
Add conformance tests to the CI pipeline
1 parent 1f8a416 commit c726876

File tree

3 files changed

+98
-1
lines changed

3 files changed

+98
-1
lines changed

.github/workflows/ci.yml

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,88 @@ jobs:
144144
path: ${{ github.workspace }}/dist
145145
key: nginx-kubernetes-gateway-${{ github.run_id }}-${{ github.run_number }}
146146

147+
conformance-tests:
148+
name: Gateway Conformance Tests
149+
runs-on: ubuntu-22.04
150+
needs: [vars, binary]
151+
steps:
152+
- name: Checkout Repository
153+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
154+
155+
- name: Fetch Cached Artifacts
156+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
157+
with:
158+
path: ${{ github.workspace }}/dist
159+
key: nginx-kubernetes-gateway-${{ github.run_id }}-${{ github.run_number }}
160+
161+
- name: Docker Buildx
162+
uses: docker/setup-buildx-action@ecf95283f03858871ff00b787d79c419715afc34 # v2.7.0
163+
164+
- name: Docker meta
165+
id: meta
166+
uses: docker/metadata-action@818d4b7b91585d195f67373fd9cb0332e31a7175 # v4.6.0
167+
with:
168+
images: |
169+
name=ghcr.io/nginxinc/nginx-kubernetes-gateway
170+
tags: |
171+
type=semver,pattern={{version}}
172+
type=edge
173+
type=ref,event=pr
174+
type=ref,event=branch,suffix=-rc,enable=${{ startsWith(github.ref, 'refs/heads/release') }}
175+
176+
- name: Prepare NKG files
177+
run: |
178+
nkg_prefix=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 1)
179+
nkg_tag=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 2)
180+
yq -i "with(.spec.template.spec.containers[0]; .image = \"${nkg_prefix}:${nkg_tag}\" | .imagePullPolicy = \"Never\")" deploy/manifests/deployment.yaml
181+
182+
- name: Build Docker Image
183+
uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4.1.1
184+
with:
185+
file: build/Dockerfile
186+
tags: ${{ steps.meta.outputs.tags }}
187+
context: "."
188+
target: goreleaser
189+
load: true
190+
cache-from: type=gha
191+
cache-to: type=gha,mode=max
192+
pull: true
193+
194+
- name: Build Test Docker Image
195+
uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4.1.1
196+
with:
197+
file: conformance/tests/Dockerfile
198+
tags: conformance-test-runner:${{ github.sha }}
199+
context: "."
200+
load: true
201+
cache-from: type=gha
202+
cache-to: type=gha,mode=max
203+
pull: true
204+
205+
- name: Deploy Kubernetes
206+
id: k8s
207+
run: |
208+
kind create cluster --image kindest/node:v1.27.1 --kubeconfig kube-${{ github.run_id }}
209+
echo "KUBECONFIG=kube-${{ github.run_id }}" >> "$GITHUB_ENV"
210+
working-directory: ./conformance
211+
212+
- name: Setup conformance tests
213+
run: |
214+
nkg_prefix=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 1)
215+
nkg_tag=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 2)
216+
make install-nkg-local-build NKG_PREFIX=${nkg_prefix} NKG_TAG=${nkg_tag} BUILD_NKG=false
217+
working-directory: ./conformance
218+
219+
- name: Run conformance tests
220+
run: |
221+
make run-conformance-tests TAG=${{ github.sha }}
222+
working-directory: ./conformance
223+
continue-on-error: true
224+
147225
build:
148226
name: Build Image
149227
runs-on: ubuntu-22.04
150-
needs: [vars, binary]
228+
needs: [vars, binary, conformance-tests]
151229
steps:
152230
- name: Checkout Repository
153231
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

conformance/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ GATEWAY_CLASS = nginx
44
SUPPORTED_FEATURES = HTTPRoute,HTTPRouteQueryParamMatching,HTTPRouteMethodMatching,HTTPRoutePortRedirect,HTTPRouteSchemeRedirect
55
KIND_KUBE_CONFIG_FOLDER = $${HOME}/.kube/kind
66
TAG = latest
7+
BUILD_NKG = true
78
PREFIX = conformance-test-runner
89
NKG_DEPLOYMENT_MANIFEST=../deploy/manifests/deployment.yaml
910
NGINX_IMAGE=$(shell yq '.spec.template.spec.containers[1].image as $$nginx_ver | $$nginx_ver' $(NKG_DEPLOYMENT_MANIFEST))
@@ -29,8 +30,10 @@ preload-nginx-container: ## Preload NGINX container on configured kind cluster
2930

3031
.PHONY: build-and-load-images
3132
build-and-load-images: preload-nginx-container ## Build NKG container and load it and NGINX container on configured kind cluster
33+
ifeq ($(BUILD_NKG),true)
3234
yq -i 'with(.spec.template.spec.containers[0]; .image = "$(NKG_PREFIX):$(NKG_TAG)" | .imagePullPolicy = "Never")' $(NKG_DEPLOYMENT_MANIFEST)
3335
cd .. && make PREFIX=$(NKG_PREFIX) TAG=$(NKG_TAG) container
36+
endif
3437
kind load docker-image $(NKG_PREFIX):$(NKG_TAG)
3538

3639
.PHONY: prepare-nkg-dependencies

conformance/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ uninstall-nkg Uninstall NKG on configured kind cluster
3535
| ------------- | ------------- | ------------- |
3636
| TAG | latest | The tag for the conformance test image |
3737
| PREFIX | conformance-test-runner | The prefix for the conformance test image |
38+
| BUILD_NKG | true | Flag to indicate if the local NKG image needs to be built |
3839
| NKG_TAG | edge | The tag for the locally built NKG image |
3940
| NKG_PREFIX | nginx-kubernetes-gateway | The prefix for the locally built NKG image |
4041
| KIND_KUBE_CONFIG_FOLDER | ~/.kube/kind | The location of the kubeconfig folder |
@@ -56,6 +57,21 @@ $ make create-kind-cluster
5657
$ make install-nkg-local-build
5758
```
5859

60+
**Note:** You can optionally skip the actual *build* step by setting the BUILD_NKG flag to "false". However, if choosing
61+
this option, the following step *must* be completed manually *before* the build step:
62+
* Set NKG_PREFIX=<nkg_repo_name> NKG_TAG=<nkg_image_tag> to preferred values.
63+
* Navigate to `deploy/manifests` and update values in `deployment.yaml` as specified in below code-block.
64+
* Save the changes.
65+
```
66+
.
67+
..
68+
containers:
69+
- image: <nkg_repo_name>:<nkg_image_tag>
70+
imagePullPolicy: Never
71+
..
72+
.
73+
```
74+
5975
#### *Option 2* Install Nginx Kubernetes Gateway from edge to configured kind cluster
6076
Instead of the above command, you can skip the build NKG image step and prepare the environment to instead
6177
use the `edge` image

0 commit comments

Comments
 (0)