From d20b232aeb71032e060fa062af39f801e1ce3c6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=BCchinger=20Dominic?= Date: Mon, 6 Jan 2025 13:22:05 +0100 Subject: [PATCH] build: Add smoke test to CI test action and added new release action --- .github/workflows/release.yml | 36 +++++++++++++++ .github/workflows/tests.yml | 44 +++++++++++++++++++ Makefile | 6 +-- _build/images/kong-smoke-test/Dockerfile | 12 ++--- .../kong-smoke-test/Dockerfile.dockerignore | 8 ++++ _build/images/kong-tooling/Dockerfile | 16 ++++--- kong-plugin.rockspec | 4 +- 7 files changed, 109 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 _build/images/kong-smoke-test/Dockerfile.dockerignore diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..91ccd60 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,36 @@ +name: Release Rock + +on: + push: + tags: + - 'v*' # Trigger for version tags + +jobs: + build_and_release: + runs-on: ubuntu-24.04 + steps: + - name: Check out code + uses: actions/checkout@main + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Set up Lua and Luarocks + uses: leafo/gh-actions-lua@v10 + with: + luaVersion: '5.4.7' + - uses: leafo/gh-actions-luarocks@v4 + with: + luarocksVersion: "3.11.1" + - name: Build rockspec files + run: | + make pack # Generates *.rock and *.scm.rock + git config user.name github-actions + git config user.email github-actions@github.com + git add *.rockspec *.rock + git commit -m "Add rockspec files for release ${GITHUB_REF##*/}" + git push + + - name: Publish to LuaRocks + env: + LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }} + run: | + luarocks upload --temp-key="${LUAROCKS_API_KEY}" *.rock *.src.rock diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e17a7d6..cc833ba 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -34,3 +34,47 @@ jobs: artifact-name: code-coverage-report github-token: ${{ secrets.GITHUB_TOKEN }} update-comment: true + smoke-tests: + timeout-minutes: ${{ fromJSON(vars.GHA_DEFAULT_TIMEOUT || 10) }} + name: Smoke Tests + + runs-on: ubuntu-24.04 + + services: + # Define the container service to run for testing + kong-smoke-test-service: + # Reference the local tag you’ll create after building + image: kong.localhost/kong-plugin-kong-authz-openfga-dev-kong-smoke-test:0.1.0 + ports: + - 8000:8000 + - 8001:8001 + # Add any other ports your container exposes + options: > + -e KONG_ANONYMOUS_REPORTS=off + -e KONG_LOG_LEVEL=debug + -e KONG_PLUGINS='bundled,kong-authz-openfga' + -e KONG_DATABASE=off + -e KONG_VITALS=off + -e KONG_NGINX_HTTP_INCLUDE=/kong/smoke-test.nginx.conf + -e KONG_DECLARATIVE_CONFIG=/kong/kong.yaml + -e KONG_ADMIN_LISTEN=0.0.0.0:8001 + -e KONG_ADMIN_GUI_URL=http://localhost:8002/ + -v '$(PWD)/_build/deployment/kong-smoke-test/kong/smoke-test.nginx.conf:/kong/smoke-test.nginx.conf' + -v '$(PWD)/_build/deployment/kong-smoke-test/kong/kong.local.yaml:/kong/kong.yaml' + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Build “smoke test” container image + run: | + # Build the image using your Makefile target + make container-ci-kong-smoke-test + - name: Wait for service to be ready + run: | + # Give the container a moment to come up + sleep 15 + + - name: Run smoke tests + run: | + make smoke-test-run-test diff --git a/Makefile b/Makefile index a652584..acaeebc 100644 --- a/Makefile +++ b/Makefile @@ -144,9 +144,7 @@ CONTAINER_CI_KONG_SMOKE_TEST_BUILD = DOCKER_BUILDKIT=1 BUILDKIT_PROGRESS=$(BUILD --build-arg KONG_IMAGE_NAME='$(KONG_IMAGE_NAME)' \ --build-arg KONG_IMAGE_TAG='$(KONG_IMAGE_TAG)' \ --build-arg KONG_PLUGIN_NAME='$(KONG_PLUGIN_NAME)' \ - --build-arg KONG_PLUGIN_VERSION='$(KONG_PLUGIN_VERSION)' \ - --build-arg KONG_PLUGIN_REVISION='$(KONG_PLUGIN_REVISION)' \ - --build-arg KONG_PLUGIN_ROCK_FILE='$(ROCK_FILE)' \ + --build-arg KONG_PLUGIN_ROCKSPEC_FILE='$(ROCKSPEC_FILE)' \ . CONTAINER_CI_KONG_TOOLING_RUN := MSYS_NO_PATHCONV=1 $(DOCKER) run $(DOCKER_RUN_FLAGS) \ @@ -235,7 +233,7 @@ container-ci-kong-tooling-debug: DOCKER_NO_CACHE = '--no-cache' container-ci-kong-tooling-debug: container-ci-kong-tooling .PHONY: container-ci-kong-smoke-test -container-ci-kong-smoke-test: $(ROCK_FILE) container-network-ci +container-ci-kong-smoke-test: container-network-ci $(CONTAINER_CI_KONG_SMOKE_TEST_BUILD) .PHONY: container-ci-kong-smoke-test-debug diff --git a/_build/images/kong-smoke-test/Dockerfile b/_build/images/kong-smoke-test/Dockerfile index 4810931..7560916 100644 --- a/_build/images/kong-smoke-test/Dockerfile +++ b/_build/images/kong-smoke-test/Dockerfile @@ -5,21 +5,23 @@ FROM ${KONG_IMAGE_NAME}:${KONG_IMAGE_TAG} AS builder USER root ARG KONG_PLUGIN_NAME -ARG KONG_PLUGIN_VERSION -ARG KONG_PLUGIN_REVISION -ARG KONG_PLUGIN_ROCK_FILE +ARG KONG_PLUGIN_ROCKSPEC_FILE RUN dnf install -y gcc m4 --setopt=install_weak_deps=False \ && dnf clean all -COPY ${KONG_PLUGIN_ROCK_FILE} /${KONG_PLUGIN_ROCK_FILE} +WORKDIR /plugin +COPY . . -RUN luarocks install /${KONG_PLUGIN_ROCK_FILE} +# Install from .rockspec +RUN luarocks make ${KONG_PLUGIN_ROCKSPEC_FILE} FROM ${KONG_IMAGE_NAME}:${KONG_IMAGE_TAG} ENV KONG_LOG_LEVEL=debug +ENV KONG_NGINX_WORKER_PROCESSES=1 + # Add the Lua files (.lua) COPY --from=builder /usr/local/share/lua/5.1 /usr/local/share/lua/5.1 diff --git a/_build/images/kong-smoke-test/Dockerfile.dockerignore b/_build/images/kong-smoke-test/Dockerfile.dockerignore new file mode 100644 index 0000000..72da638 --- /dev/null +++ b/_build/images/kong-smoke-test/Dockerfile.dockerignore @@ -0,0 +1,8 @@ +# Ignore all files +* + +# Exclude the following files +!/kong/ +!/README.md +!/LICENSE +!/kong-plugin-kong-authz-openfga-*.rockspec diff --git a/_build/images/kong-tooling/Dockerfile b/_build/images/kong-tooling/Dockerfile index ddcd602..afa7afd 100644 --- a/_build/images/kong-tooling/Dockerfile +++ b/_build/images/kong-tooling/Dockerfile @@ -15,10 +15,8 @@ ARG PONGO_ARCHIVE ARG STYLUA_VERSION ARG EMMY_LUA_DEBUGGER_VERSION -COPY kong-plugin-${KONG_PLUGIN_NAME}-${KONG_PLUGIN_VERSION}-${KONG_PLUGIN_REVISION}.rockspec /kong-plugin-${KONG_PLUGIN_NAME}-${KONG_PLUGIN_VERSION}-${KONG_PLUGIN_REVISION}.rockspec -COPY _build/images/kong-plugin-testing-0.1.0-0.rockspec /kong-plugin-testing-0.1.0-0.rockspec - SHELL ["/bin/bash", "-o", "pipefail", "-c"] + RUN dnf install -y cmake gcc m4 git --setopt=install_weak_deps=False \ && curl -sSf -L https://github.com/Kong/kong-pongo/archive/refs/heads/master.tar.gz | tar xfvz - -C / --strip-components 3 kong-pongo-master/kong-versions/"${PONGO_KONG_VERSION}" \ && echo 'database = off' >> /kong/spec/kong_tests.conf \ @@ -31,14 +29,18 @@ RUN dnf install -y cmake gcc m4 git --setopt=install_weak_deps=False \ && cd /tmp/EmmyLuaDebugger-${EMMY_LUA_DEBUGGER_VERSION}/build \ && cmake .. -DCMAKE_BUILD_TYPE=Release -DEMMY_CORE_VERSION=${EMMY_LUA_DEBUGGER_VERSION} \ && cmake --build . --config Release \ - # Install package dependencies defined in the plugin rockspec file. - && luarocks build /kong-plugin-${KONG_PLUGIN_NAME}-${KONG_PLUGIN_VERSION}-${KONG_PLUGIN_REVISION}.rockspec --only-deps OPENSSL_DIR=/usr/local/kong CRYPTO_DIR=/usr/local/kong \ - # Install package dependencies used for unit and integration tests. - && luarocks build /kong-plugin-testing-0.1.0-0.rockspec --only-deps OPENSSL_DIR=/usr/local/kong CRYPTO_DIR=/usr/local/kong \ && unzip /tmp/stylua-linux-x86_64.zip -d /usr/local/bin \ && cp /tmp/EmmyLuaDebugger-${EMMY_LUA_DEBUGGER_VERSION}/build/emmy_core/emmy_core.so /usr/local/lib/lua/5.1 \ && rm -rf /var/tmp/* +COPY _build/images/kong-plugin-testing-0.1.0-0.rockspec /kong-plugin-testing-0.1.0-0.rockspec +# Install package dependencies used for unit and integration tests. +RUN luarocks build /kong-plugin-testing-0.1.0-0.rockspec --only-deps OPENSSL_DIR=/usr/local/kong CRYPTO_DIR=/usr/local/kong + +COPY kong-plugin-${KONG_PLUGIN_NAME}-${KONG_PLUGIN_VERSION}-${KONG_PLUGIN_REVISION}.rockspec /kong-plugin-${KONG_PLUGIN_NAME}-${KONG_PLUGIN_VERSION}-${KONG_PLUGIN_REVISION}.rockspec +# Install package dependencies defined in the plugin rockspec file. +RUN luarocks build /kong-plugin-${KONG_PLUGIN_NAME}-${KONG_PLUGIN_VERSION}-${KONG_PLUGIN_REVISION}.rockspec --only-deps OPENSSL_DIR=/usr/local/kong CRYPTO_DIR=/usr/local/kong + FROM ${KONG_IMAGE_NAME}:${KONG_IMAGE_TAG} ENV LUA_PATH="/kong-plugin/?.lua;/kong-plugin/?/init.lua;;" diff --git a/kong-plugin.rockspec b/kong-plugin.rockspec index 5d1c925..9b2466d 100644 --- a/kong-plugin.rockspec +++ b/kong-plugin.rockspec @@ -10,15 +10,17 @@ version = package_version .. "-" .. rockspec_revision source = { url = "git+https://github.com/dol/kong-authz-openfga.git", + tag = "v" .. version, } description = { summary = "Kong plugin for kong-authz-openfga integration", homepage = "https://github.com/dol/kong-authz-openfga", - license = "proprietary", + license = "MIT", } dependencies = { + "lua ~> 5.1", } build = {