From 104d511a09a66d47709e1a8b894864f0382f87a7 Mon Sep 17 00:00:00 2001 From: Ciara Stacke <18287516+ciarams87@users.noreply.github.com> Date: Fri, 30 Jun 2023 10:54:43 +0100 Subject: [PATCH] Run conformance tests in the CI pipeline (#792) * Add conformance tests to the CI pipeline --- .github/workflows/ci.yml | 88 +++++++++++++++++++++++++++++++++++- Makefile | 3 +- conformance/Makefile | 27 ++++++++--- conformance/README.md | 32 ++++++++++--- conformance/tests/Dockerfile | 2 + 5 files changed, 137 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dba4ad7fd2..09dd6e7491 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -144,10 +144,96 @@ jobs: path: ${{ github.workspace }}/dist key: nginx-kubernetes-gateway-${{ github.run_id }}-${{ github.run_number }} + conformance-tests: + name: Gateway Conformance Tests + runs-on: ubuntu-22.04 + needs: vars + steps: + - name: Checkout Repository + uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + + - name: Setup Golang Environment + uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1 + with: + go-version-file: go.mod + + - name: Docker Buildx + uses: docker/setup-buildx-action@ecf95283f03858871ff00b787d79c419715afc34 # v2.7.0 + + - name: Docker meta + id: meta + uses: docker/metadata-action@818d4b7b91585d195f67373fd9cb0332e31a7175 # v4.6.0 + with: + images: | + name=ghcr.io/nginxinc/nginx-kubernetes-gateway + tags: | + type=semver,pattern={{version}} + type=edge + type=ref,event=pr + type=ref,event=branch,suffix=-rc,enable=${{ startsWith(github.ref, 'refs/heads/release') }} + + - name: Prepare NKG files + run: | + nkg_prefix=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 1) + nkg_tag=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 2) + make update-nkg-manifest NKG_PREFIX=${nkg_prefix} NKG_TAG=${nkg_tag} + working-directory: ./conformance + + - name: Build binary + uses: goreleaser/goreleaser-action@336e29918d653399e599bfca99fadc1d7ffbc9f7 # v4.3.0 + with: + version: latest + args: ${{ startsWith(github.ref, 'refs/tags/') && 'release' || 'build --snapshot' }} --clean + env: + GOPATH: ${{ needs.vars.outputs.go_path }} + + - name: Build Docker Image + uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4.1.1 + with: + file: build/Dockerfile + tags: ${{ steps.meta.outputs.tags }} + context: "." + target: goreleaser + load: true + cache-from: type=gha + cache-to: type=gha,mode=max + pull: true + + - name: Build Test Docker Image + uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4.1.1 + with: + file: conformance/tests/Dockerfile + tags: conformance-test-runner:${{ github.sha }} + context: "." + load: true + cache-from: type=gha + cache-to: type=gha,mode=max + pull: true + + - name: Deploy Kubernetes + id: k8s + run: | + make create-kind-cluster KIND_KUBE_CONFIG=kube-${{ github.run_id }} + echo "KUBECONFIG=kube-${{ github.run_id }}" >> "$GITHUB_ENV" + working-directory: ./conformance + + - name: Setup conformance tests + run: | + nkg_prefix=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 1) + nkg_tag=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 2) + make install-nkg-local-no-build NKG_PREFIX=${nkg_prefix} NKG_TAG=${nkg_tag} + working-directory: ./conformance + + - name: Run conformance tests + run: | + make run-conformance-tests TAG=${{ github.sha }} + working-directory: ./conformance + continue-on-error: true + build: name: Build Image runs-on: ubuntu-22.04 - needs: [vars, binary] + needs: [vars, binary, conformance-tests] steps: - name: Checkout Repository uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 diff --git a/Makefile b/Makefile index 9b893be60e..0571eb4711 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,8 @@ deps: ## Add missing and remove unused modules, verify deps and download them to .PHONY: create-kind-cluster create-kind-cluster: ## Create a kind cluster - kind create cluster --image kindest/node:v1.27.1 + $(eval KIND_IMAGE=$(shell grep -m1 'FROM kindest/node' NKG_TAG= to preferred values. + * Navigate to `deploy/manifests` and update values in `deployment.yaml` as specified in below code-block. + * Save the changes. + ``` + . + .. + containers: + - image: : + imagePullPolicy: Never + .. + . + ``` +#### *Option 3* Install Nginx Kubernetes Gateway from edge to configured kind cluster +You can also skip the build NKG image step and prepare the environment to instead use the `edge` image ```bash $ make install-nkg-edge diff --git a/conformance/tests/Dockerfile b/conformance/tests/Dockerfile index 672872bbdc..023907417d 100644 --- a/conformance/tests/Dockerfile +++ b/conformance/tests/Dockerfile @@ -1,4 +1,6 @@ # syntax=docker/dockerfile:1.5 +# this is here so we can grab the latest version of kind and have dependabot keep it up to date +FROM kindest/node:v1.27.3 FROM golang:1.20