Code Monkey home page Code Monkey logo

kong-pongo's Introduction

Unix Tests Docker Tests Lint SemVer

pongo

Pongo provides a simple way of testing Kong plugins. For a complete walkthrough check this blogpost on the Kong website.

                /~\
  ______       C oo
  | ___ \      _( ^)
  | |_/ /__  _/__ ~\ __   ___
  |  __/ _ \| '_ \ / _ `|/ _ \
  | | | (_) | | | | (_| | (_) |
  \_|  \___/|_| |_|\__, |\___/
                    __/ |
                   |___/  v2.12.0

Usage: pongo action [options...] [--] [action options...]

Options (can also be added to '.pongo/pongorc'):
  --no-postgres      do not start postgres db
  --cassandra        do start cassandra db
  --grpcbin          do start grpcbin (see readme for info)
  --redis            do start redis db (see readme for info)
  --squid            do start squid forward-proxy (see readme for info)

Project actions:
  init          initializes the current plugin directory with some default
                configuration files if not already there (not required)

  lint          will run the LuaCheck linter

  pack          will pack all '*.rockspec' files into '*.rock' files for
                distribution (see LuaRocks package manager docs)

  run           run spec files, accepts Busted options and spec files/folders
                as arguments, see: 'pongo run -- --help'

  shell         get a shell directly on a kong container

  tail          starts a tail on the specified file. Default file is
                ./servroot/logs/error.log, an alternate file can be specified

Environment actions:
  build         build the Kong test image, add '--force' to rebuild images

  clean / nuke  removes the dependency containers and deletes all test images

  docs          will generate and open the test-helper documentation

  down          remove all dependency containers

  expose        expose the internal ports for access from the host

  logs          show docker-compose logs of the Pongo environment

  restart       shortcut, a combination of; down + up

  status        show status of the Pongo network, images, and containers

  up            start required dependency containers for testing

Maintenance actions:
  update        update embedded artifacts for building test images


Environment variables:
  KONG_VERSION  the specific Kong version to use when building the test image
                (note that the patch-version can be 'x' to use latest)

  KONG_IMAGE    the base Kong Docker image to use when building the test image

  KONG_LICENSE_DATA
                set this variable with the Kong Enterprise license data

  POSTGRES      the version of the Postgres dependency to use (default 9.5)
  CASSANDRA     the version of the Cassandra dependency to use (default 3.11)
  REDIS         the version of the Redis dependency to use (default 6.2.6)

Example usage:
  pongo run
  KONG_VERSION=3.3.x pongo run -v -o gtest ./spec/02-access_spec.lua
  POSTGRES=10 KONG_IMAGE=kong-ee pongo run
  pongo down

Table of contents

Requirements

Tools Pongo needs to run:

  • docker-compose (and hence docker)
  • curl
  • realpath, for older MacOS versions you need the coreutils to be installed. This is easiest via the Homebrew package manager by doing:
    brew install coreutils
    
  • depending on your environment you should set some environment variables.

Back to ToC

Installation

Clone the repository and install Pongo:

PATH=$PATH:~/.local/bin
git clone https://github.com/Kong/kong-pongo.git
mkdir -p ~/.local/bin
ln -s $(realpath kong-pongo/pongo.sh) ~/.local/bin/pongo

Proxies

When Pongo builds images, it might fail when it is behind proxies and cannot verify the certificates. See configuration on how to disable verification.

Update

Since the Pongo script is symbolic linked to ~/.local/bin/pongo, in order to update Pongo, all you have to do is to fetch latest changes from the Pongo repo:

cd <cloned Pongo repo>
git pull

# checkout the latest version tag (checkout 'master' for bleeding edge)
git checkout $(git tag | sort --version-sort | tail -n 1)

Back to ToC

Configuration

Several environment variables are available for configuration:

  • Docker credentials; DOCKER_USERNAME and DOCKER_PASSWORD to prevent rate- limits when pulling images.
  • Kong license; set KONG_LICENSE_DATA with the Enterprise license to enable Enterprise features.
  • Specify a custom image; set the image name/tag in KONG_IMAGE and make sure the image is locally available
  • When the variable PONGO_INSECURE is set to anything else than 'false', it will configure curl and git (during the build) to switch off ssl verification. Please ensure you understand the security consequences when using this option! See also pongo build --help.

For Kong-internal use there are some additional variables:

  • GITHUB_TOKEN the Github token to get access to the Kong Enterprise source code. This is only required for development builds, not for released versions of Kong.

Back to ToC

Do a test run

Get a shell into your plugin repository, and run pongo, for example:

git clone https://github.com/Kong/kong-plugin.git
cd kong-plugin

# auto pull and build the test images
pongo run

Some more elaborate examples:

# Run against a specific version of Kong and pass
# a number of Busted options
KONG_VERSION=3.2.2 pongo run -- -v -o gtest ./spec

# Run against the latest patch version of a Kong release using '.x'
KONG_VERSION=3.4.x pongo run

# Run against the latest stable version, using special label 'stable'
# (available labels are: 'stable', 'stable-ee', 'dev', and 'dev-ee')
KONG_VERSION=stable pongo run

# Run against a local image of Kong
KONG_IMAGE=kong-ee pongo run ./spec

The above command (pongo run) will automatically build the test image and start the test environment. When done, the test environment can be torn down by:

pongo down

Back to ToC

Pongo on Windows

Pongo should run in Git-BASH if you have Git for Windows installed (and Docker for Windows).

using WSL2

An alternative to run Pongo on Windows is WSL2 (Windows Subsystem for Linux).

  • install WSL2

  • install Docker for Windows

  • from the Microsoft Store install Debian (search for Debian)

  • start Debian (should be in your start menu)

  • now from the prompt install Pongo and some dependencies;

    sudo apt update
    sudo apt install git curl coreutils
    
    cd ~
    git clone https://github.com/Kong/kong-pongo.git
    mkdir -p ~/.local/bin
    ln -s $(realpath kong-pongo/pongo.sh) ~/.local/bin/pongo
    PATH=$PATH:~/.local/bin
    
  • Open Docker for Windows and open the settings

  • under "General" enable using the WSL2 engine

  • under "Resources - WSL integration" enable integration with the Debian package

You can now edit your code with your favorite Windows IDE or editor and then run the tests with Pongo.

To give this a try using the template plugin;

  • download or clone https://github.com/Kong/kong-plugin.git (assuming this to land in C:\users\tieske\code\kong-plugin)

  • start Debian and at the prompt do:

    cd /mnt/c/users/tieske/code/kong-plugin
    pongo run
    

Back to ToC

Test dependencies

Pongo can use a set of test dependencies that can be used to test against. Each can be enabled/disabled by respectively specifying --[dependency_name] or --no-[dependency-name] as options for the pongo up, pongo restart, and pongo run commands. The alternate way of specifying the dependencies is by adding them to the .pongo/pongorc file (see below).

The available dependencies are:

  • Postgres Kong datastore (started by default)

    • Disable it with --no-postgres
    • The Postgres version is controlled by the POSTGRES environment variable
  • Cassandra Kong datastore

    • Enable it with --cassandra
    • The Cassandra version is controlled by the CASSANDRA environment variable
  • grpcbin mock grpc backend

    • Enable it with --grpcbin
    • The engine is moul/grpcbin
    • From within the environment it is available at:
      • grpcbin:9000 grpc over http
      • grpcbin:9001 grpc over http+tls
  • Redis key-value store

    • Enable it with --redis
    • The Redis version is controlled by the REDIS environment variable
    • From within the environment the Redis instance is available at redis:6379, but from the test specs it should be accessed by using the helpers.redis_host field, and port 6379, to keep it portable to other test environments. Example:
      local helpers = require "spec.helpers"
      local redis_host = helpers.redis_host
      local redis_port = 6379
  • Squid (forward-proxy)

    • Enable it with --squid

    • The Squid version is controlled by the SQUID environment variable

    • From within the environment the Squid instance is available at squid:3128. Essentially it would be configured as these standard environment variables:

      • http_proxy=http://squid:3128/
      • https_proxy=http://squid:3128/

      The configuration comes with basic-auth configuration, and a single user:

      • username: kong
      • password: king

      All access is to be authenticated by the proxy, except for the domain .mockbin.org, which is white-listed.

      Some test instructions to play with the proxy:

      # clean environment, start with squid and create a shell
      pongo down
      pongo up --squid --no-postgres
      pongo shell
      
      # connect to httpbin (http), while authenticating
      http --proxy=http:http://kong:king@squid:3128 --proxy=https:http://kong:king@squid:3128 http://httpbin.org/anything
      
      # https also works
      http --proxy=http:http://kong:king@squid:3128 --proxy=https:http://kong:king@squid:3128 https://httpbin.org/anything
      
      # connect unauthenticated to the whitelisted mockbin.org (http)
      http --proxy=http:http://squid:3128 --proxy=https:http://squid:3128 http://mockbin.org/request
      
      # and here https also works
      http --proxy=http:http://squid:3128 --proxy=https:http://squid:3128 https://mockbin.org/request

Back to ToC

Dependency defaults

The defaults do not make sense for every type of plugin and some dependencies (Cassandra for example) can slow down the tests. So to override the defaults on a per project/plugin basis, a .pongo/pongorc file can be added to the project.

The format of the file is very simple; each line contains 1 commandline option, eg. a .pongo/pongorc file for a plugin that only needs Postgres and Redis:

--no-cassandra
--redis

Back to ToC

Disable Service Health Checks

When unable to leverage container health checks, they can be disabled setting the environment variable HEALTH_TIMEOUT=0. This will set the variable SERVICE_DISABLE_HEALTHCHECK=true, which can be used to disable the service health checks for the Pongo services in the docker composer files.

For example:

    healthcheck:
      test:
      - CMD
      - pg_isready
      - --dbname=kong_tests
      - --username=kong
      disable: ${SERVICE_DISABLE_HEALTHCHECK:-false}

To wait for the environment and run the tests one could run

export HEALTH_TIMEOUT=0
pongo up && sleep 10 && pongo run

Dependency troubleshooting

When dependency containers are causing trouble, the logs can be accessed using the pongo logs command. This command is the same as docker-compose logs except that it operates on the Pongo environment specifically. Any additional options specified to the command will be passed to the underlying docker-compose logs command.

Some examples:

# show latest logs
pongo logs

# tail latest logs
pongo logs -f

# tail latest logs for the postgres dependency
pongo logs -f postgres

Back to ToC

Custom local dependencies

If the included dependencies are not enough for testing a plugin, then Pongo allows you to specify your own dependencies. To create a custom local dependency you must add its name to the .pongo/pongorc file An example defining 2 extra dependencies; zipkin, and myservice:

--no-cassandra
--redis
--zipkin
--no-myservice

This defines both services, with zipkin being started by default and myservice only when specifying it like this;

pongo up --myservice

This only defines the dependency, but it also needs a configuration. The configuration is a docker-compose file specific for each dependency. So taking the above zipkin example we create a file named .pongo/zipkin.yml.

version: '3.5'

services:
  zipkin:
    image: openzipkin/zipkin:${ZIPKIN:-2.19}
    healthcheck:
      interval: 5s
      retries: 10
      test:
      - CMD
      - wget
      - localhost:9411/health
      timeout: 10s
      disable: ${SERVICE_DISABLE_HEALTHCHECK:-false}
    restart: on-failure
    stop_signal: SIGKILL
    networks:
      - ${NETWORK_NAME}

The components of the file:

  • file name: based on the dependency name; ./pongo/<dep-name>.yml
  • service name: this must be the dependency name as defined, in this case zipkin
  • image is required, the environment variable ZIPKIN to override the default version 2.19 is optional
  • healthcheck if available then Pongo uses the health-status to determine whether a dependency is ready and the test run can be started.
  • networks should be included and left as-is to include the dependency in the network with the other containers.

Some helpfull examples:

Back to ToC

Debugging

This section is about debugging plugin code. If you have trouble with the Pongo environment then check Dependency troubleshooting.

Accessing the logs

When running the tests, the Kong prefix (or working directory) will be set to ./servroot.

To track the error log (where any print or ngx.log statements will go) you can use the tail command

pongo tail

The above would be identical to:

tail -F ./servroot/logs/error.log

The above does not work in a CI environment. So how to get access to the logs in that case?

From the default .travis.yml (see chapter on CI), change the basic lines to run the commands as follows, from;

script:
- "../kong-pongo/pongo.sh lint"
- "../kong-pongo/pongo.sh run"

to;

script:
- "../kong-pongo/pongo.sh lint"
- "KONG_TEST_DONT_CLEAN=true ../kong-pongo/pongo.sh run"
- "cat servroot/logs/error.log"

Setting the KONG_TEST_DONT_CLEAN variable will instruct Kong to not clean up the working directory in between tests. And the final cat command will output the log to the Travis console.

Back to ToC

Direct access to service ports

To directly access Kong from the host, or the datastores, the pongo expose command can be used to expose the internal ports to the host.

This allows for example to connect to Postgres on port 5432 to validate the contents of the database. Or when running pongo shell to manually start Kong, you can access all the regular Kong ports from the host, including the GUI's.

This has been implemented as a separate container that opens all those ports and relays them on the docker network to the actual service containers (the reason for this is that regular Pongo runs do not interfere with ports already in use on the host, only if expose is used there is a risk of failure because ports are already in use on the host)

Since it is technically a "dependency" it can be specified as a dependency as well.

so

pongo up
pongo expose

is equivalent to

pongo up --expose

See pongo expose --help for the ports.

Back to ToC

Test initialization

By default when the test container is started, it will look for a .rockspec file, if it finds one, then it will install that rockspec file with the --deps-only flag. Meaning it will not install that rock itself, but if it depends on any external libraries, those rocks will be installed. If the rock is already installed in the image, it will be uninstalled first.

For example; the Kong plugin session relies on the lua-resty-session rock. So by default it will install that dependency before starting the tests.

To modify the default behaviour there are 2 scripts that can be hooked up:

  • .pongo/pongo-setup-host.sh this script will be executed (not sourced) right before the Kong test container is started. Hence this script runs on the host. The interpreter can be set using the regular shebang.

  • .pongo/pongo-setup.sh is ran upon container start inside the Kong container. It will not be executed but sourced, and will run on /bin/bash as interpreter.

Both scripts will have an environment variable PONGO_COMMAND that will have the current command being executed, for example shell or run.

Below an example using both files. On the host it clones a dependency if it isn't available already. This prevents pulling it on each run, but makes sure it is available in CI. Then on each run it will install the dependency in the container first and then it will do the default action of installing all rockspecs found.

Example .pongo/pongo-setup-host.sh:

#!/usr/bin/env bash

# this runs on the host, before the Kong container is started
if [ ! -d "my_dependency" ]; then
  git clone https://github.com/memyselfandi/my_dependency.git
fi

Example .pongo/pongo-setup.sh:

#!/usr/bin/env bash

# this runs in the test container upon starting it
cd /kong-plugin/my_dependency
make install

# additionally run the default action of installing rockspec dependencies
/pongo/default-pongo-setup.sh

Back to ToC

Test coverage

Pongo has support for the LuaCov code coverage tool. But this is rather limited. LuaCov is not able to run in OpenResty, hence it will not report on integration tests, only on unit tests.

To enable LuaCov, run pongo init to create the .luacov configuration file, and then run the tests using the Busted --coverage option like this:

pongo run -- --coverage

After the test run the output files luacov.*.out files should be available.

Back to ToC

Setting up CI

Pongo is easily added to a CI setup. The examples below will assume Github Actions, but can be easily converted to other engines.

  • For Github the best option is to use the Pongo Github Action
  • if your engine of preference runs itself in Docker, then checkout Pongo in Docker.
  • to test against development images add a job with KONG_VERSION=dev,

Note: there is also a "dev-ee" for Kong Enterprise. But this requires a GitHub access token to fetch the Kong Enterprise source code, and must be specified as a GITHUB_TOKEN environment variable.

Here's a base setup for a plugin that will test against multiple Kong versions:

# .github/workflows/test.yml

name: "Test"

concurrency:
  group: ${{ github.workflow }} ${{ github.ref }}
  cancel-in-progress: ${{ github.event_name == 'pull_request' }}

on:
  pull_request: {}
  push:
    branches:
    - master
  schedule:
  - cron: '0 0 * * *'  # every day at midnight, to test against development

jobs:
  test:
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        kongVersion:
        - "2.8.x"
        - "3.5.x"
        - "dev"
        - "3.5.x.x"
        #- "dev-ee"    # Kong internal only, requires access to source code

    steps:
    - uses: actions/checkout@v3

    - uses: Kong/kong-pongo-action@v1
      with:
        pongo_version: master
        kong_version: ${{ matrix.kongVersion }}
        # Kong internal users can use the Kong/kong-license action to get the license
        license: ${{ secrets.KONG_LICENSE_DATA }}

    - run: pongo run

Back to ToC

Running Pongo in Docker

Pongo relies on Docker and Docker-compose to recreate environments and test setups. So what if your environment is running Pongo itself in a Docker container?

Docker-in-Docker has some serious issues when used in CI (as it was intended for Docker development only). The proposed solution in that blog post actually works with Pongo. By starting the container running Pongo with the

-v /var/run/docker.sock:/var/run/docker.sock

option, the container will get control over the Docker deamon on the host. The means that the test environment spun up by Pongo will not run inside the Pongo container (as children) but along side the Pongo container (as siblings). To share the plugin code and tests with the (sibling) test container Pongo will need a shared working directory on the host. This working directory must be mapped to /pongo_wd on the container running Pongo.

Additionally the container id must be made available to the Pongo container. It must be in a file .containerid in the same working directory.

WARNING: make sure to read up on the security consequences of sharing docker.sock! You are allowing a Docker container to control the Docker deamon on the host!

For a working example see the Pongo repo.

Back to ToC

Releasing (new Kong versions)

When new Kong versions are released, the test artifacts contained within this Pongo repository must be updated.

To do so there are some pre-requisites;

  • have gh installed and configured
  • have access to the kong-pongo (push) and kong-ee (read/clone) repositories on Github

Update the version as follows:

# The code-base (1st argument) is either "EE" (Enterprise) or "CE" (Opensource)
# 2nd argument is the version to add.
# 3rd argument makes it a test run if given

assets/add_version.sh "EE" "1.2.3" "test"

Here's an all-in-one command, edit the parameters as needed;

git clone --single-branch https://github.com/Kong/kong-pongo $TMPDIR/kong-pongo && $TMPDIR/kong-pongo/assets/add_version.sh "EE" "1.2.3" "test"; rm -rf $TMPDIR/kong-pongo

The result should be a new PR on the Pongo repo.

Back to ToC

kong-pongo's People

Contributors

aboudreault avatar add-sp avatar andyzhang0707 avatar apxdono avatar c13490888 avatar curiositycasualty avatar eskerda avatar fffonion avatar git-hulk avatar gszr avatar hanshuebner avatar hishamhm avatar hutchic avatar junior-alves avatar kidd avatar kikito avatar kongifysolinc avatar locao avatar mashapedeployment avatar mikefero avatar outsinre avatar pintsized avatar piyushpgupta avatar pravynandas avatar robserafini avatar samugi avatar team-eng-enablement avatar tieske avatar tyler-ball avatar yzyyi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kong-pongo's Issues

Improve the docker login logic

  • Perform the docker login if the credentials are present and then docker logout after Pongo completes execution of the docker pull. This would allow for increased docker pull rate-limiting using certain docker user accounts.

  • if given we should log in, if not given we should try without. If it fails, we should retry with the private creds for EE images not publicly available (eg. 036-2 and the likes).

The coverage rate of handler.lua is not 100%?

I've tried the "--coverage" option, and get below result.
May I know why the coverage rate of handler.lua is not 100%, and how to make it 100%?

File                                           Hits Missed Coverage
-------------------------------------------------------------------
/kong-plugin/kong/plugins/myplugin/handler.lua 5    4      55.56%
/kong-plugin/kong/plugins/myplugin/schema.lua  24   0      100.00%
-------------------------------------------------------------------
Total                                          29   4      87.88%

Checking the luacov.report.out, only the function name (and imports) are "tested".

 1 function plugin:access(plugin_conf)

     -- your custom code here
*0   kong.log.inspect(plugin_conf)   -- check the logs for a pretty-printed config!
*0   kong.service.request.set_header(plugin_conf.request_header, "this is on a request")

   end --]]

How to create a consumer and connect to a service?

In kong-pongo, how to create a consumer, and connect to test service?
In my case, I use this code to create it:

local helpers = require "spec.helpers"
local bp = helpers.get_db_utils(strategy, nil, { PLUGIN_NAME }) 
bp.consumers.insert{
  username="nick",
}

the code is no error, but i'm not sure is this right, and when i use

consumer = kong.client.get_consumer()

i can only get a nil, so anybody can offer me a example to test my case, thanks a lot.

dbless setup available?

I tried the following, which just came back without doing anything?

rkazak@Rohintons-Mac-mini kong-api-version-plugin % pongo --no-cassandra --no-postgres up

CI runs hanging on container availability

seeing more and more of these:

Checking kong/plugins/session/header_filter.lua   OK
Checking kong/plugins/session/migrations/000_base_session.lua OK
Checking kong/plugins/session/migrations/001_add_ttl_index.lua OK
Checking kong/plugins/session/migrations/init.lua OK
Checking kong/plugins/session/schema.lua          OK
Checking kong/plugins/session/session.lua         OK
Checking kong/plugins/session/storage/kong.lua    OK
Checking spec/01-access_spec.lua                  OK
Checking spec/02-kong_storage_adapter_spec.lua    OK
Checking spec/03-session_spec.lua                 OK
Total: 0 warnings / 0 errors in 13 files
The command "../kong-pongo/pongo.sh lint" exited with 0.
$ ../kong-pongo/pongo.sh run
[pongo-INFO] Waiting for postgres
No output has been received in the last 10m0s, this potentially indicates a stalled build or something wrong with the build itself.
Check the details on how to adjust your build configuration on: https://docs.travis-ci.com/user/common-build-problems/#build-times-out-because-no-output-was-received
The build has been terminated

plugin not enabled

Hi,
first of all thanks for great tooling.

I got following error when running plugin tests:

Plugin: token-auth (access) setup
/kong-plugin/spec/token-auth/01-access_spec.lua:41: [postgres] schema violation (name: plugin 'token-auth' not enabled; add it to the 'plugins' configuration property)

If I enable plugin manually by editing kong_tests.conf inside docker, I am able to run tests.

sed -i '/plugins/ s/$/,token-auth/' spec/kong_tests.conf

Did I miss something in setup procedure?

Regards,

Jan

Too many CI failures; cache generated images

Most of the CI failures (false negatives) are errors while building the test image;

  • Pulling the Enterprise images from Bintray (95%)
  • downloading packages during the build (5%)

If the generated images were cached, we could circumvent that, and also reduce the docker pulls. (possibly even speed up the tests)

Issues:

  1. Caching is done based on test-matrix usually: since the Pongo version is not in the test matrix (Pongo is unversioned), we might end up running Pongo against an image build by an older version of Pongo.
  2. common test matrix is running a single version, and hence a single image, how about multiple images?
  3. How to make sure it works with multiple CI engines

Proposal:

  • to cater for 1 above; pongo generates a cache file-name based of; a) it's own commit-id, b) standard named extension
  • pongo load <dir>: if the filename exists in the cache-directory, the file is loaded (docker load?)
  • pongo save <dir>: exports all pongo images to the file (docker save?)
  • when saving, any other file in that dir with the pongo filename extension gets deleted (it would mean generated by a different Pongo version/commit-id), and since that is not covered by the CI matrix, Pongo should take care of this clean up

How to add my local plugin in my Docker-compose.yml

I have a custom plugin here created using Pongo at KongToTheRescue. I want to create a docker-compose file that users can use to directly test this custom plugin.

I have been able to set up a docker-compose to start a Kong with Postgres containers. However, i am unable to add my custom plugins. How can I do that? Any help would be great
My current Docker-compose consists of:

version: "3"

networks:
  kong-net:
    driver: bridge

services:
  # Postgres: The database used by Kong
  kong-database:
    image: postgres:9.6
    restart: on-failure
    networks:
      - kong-net
    environment:
      POSTGRES_PASSWORD: kong
      POSTGRES_USER: kong
      POSTGRES_DB: kong
    ports:
      - "5432:5432"
    healthcheck:
      test: [ "CMD", "pg_isready", "-U", "kong" ]
      interval: 5s
      timeout: 5s
      retries: 5

  # Kong DB migration
  kong-migration:
    image: kong:latest
    command: "kong migrations bootstrap"
    networks:
      - kong-net
    restart: on-failure
    environment:
      KONG_PG_HOST: kong-database
      KONG_DATABASE: postgres
      KONG_PG_PASSWORD: kong
    links:
      - kong-database
    depends_on:
      - kong-database

  # Kong CLI
  kong:
    image: kong:latest
    restart: on-failure
    networks:
      - kong-net
    environment:
      KONG_DATABASE: postgres
      KONG_PG_HOST: kong-database
      KONG_PG_USER: kong
      KONG_PG_PASSWORD: kong
      KONG_PROXY_LISTEN: 0.0.0.0:8000
      KONG_PROXY_LISTEN_SSL: 0.0.0.0:8443
      KONG_ADMIN_LISTEN: 0.0.0.0:8001
    depends_on:
      - kong-migration
      - kong-database
    healthcheck:
      test: [ "CMD", "curl", "-f", "http://kong:8001" ]
      interval: 5s
      timeout: 2s
      retries: 15
    ports:
      - "8001:8001"
      - "8000:8000"

`pongo run` timeout

Hi all!

I'm having some problems when executing pongo run. Firstly, I'm trying to execute the tests provided in this repo, but I'm getting some timeouts.

I tried to execute it more than one Kong version, and in more than one computer, but the same timeout occurred. It appear to be in the external calls.

I see in the logs the error:0200100D:system library:fopen:Permission denied:fopen but even with sudo pongo run it still appearing.

$ pongo run
[pongo-INFO] auto-starting the test environment, use the 'pongo down' action to stop it

Stopping after installing dependencies for kong-plugin-myplugin 0.1.0-1

Kong version: 2.6.0
[==========] Running tests from scanned files.
[----------] Global test environment setup.
[----------] Running tests from /kong-plugin/spec/myplugin/01-unit_spec.lua
[ RUN      ] /kong-plugin/spec/myplugin/01-unit_spec.lua @ 18: myplugin: (schema) accepts distinct request_header and response_header
[       OK ] /kong-plugin/spec/myplugin/01-unit_spec.lua @ 18: myplugin: (schema) accepts distinct request_header and response_header (0.31 ms)
[ RUN      ] /kong-plugin/spec/myplugin/01-unit_spec.lua @ 28: myplugin: (schema) does not accept identical request_header and response_header
[       OK ] /kong-plugin/spec/myplugin/01-unit_spec.lua @ 28: myplugin: (schema) does not accept identical request_header and response_header (0.19 ms)
[----------] 2 tests from /kong-plugin/spec/myplugin/01-unit_spec.lua (159.33 ms total)

[----------] Running tests from /kong-plugin/spec/myplugin/02-integration_spec.lua
[ RUN      ] /kong-plugin/spec/myplugin/02-integration_spec.lua @ 55: myplugin: (access) [#postgres] request gets a 'hello-world' header
/kong-plugin/spec/myplugin/02-integration_spec.lua:56: timeout

stack traceback:
	/kong-plugin/spec/myplugin/02-integration_spec.lua:56: in function </kong-plugin/spec/myplugin/02-integration_spec.lua:55>

[  ERROR   ] /kong-plugin/spec/myplugin/02-integration_spec.lua @ 55: myplugin: (access) [#postgres] request gets a 'hello-world' header (60059.46 ms)
[ RUN      ] /kong-plugin/spec/myplugin/02-integration_spec.lua @ 73: myplugin: (access) [#postgres] response gets a 'bye-world' header
/kong-plugin/spec/myplugin/02-integration_spec.lua:74: timeout

stack traceback:
	/kong-plugin/spec/myplugin/02-integration_spec.lua:74: in function </kong-plugin/spec/myplugin/02-integration_spec.lua:73>

[  ERROR   ] /kong-plugin/spec/myplugin/02-integration_spec.lua @ 73: myplugin: (access) [#postgres] response gets a 'bye-world' header (60026.64 ms)
[ RUN      ] /kong-plugin/spec/myplugin/02-integration_spec.lua @ 55: myplugin: (access) [#cassandra] request gets a 'hello-world' header
/kong-plugin/spec/myplugin/02-integration_spec.lua:56: timeout

stack traceback:
	/kong-plugin/spec/myplugin/02-integration_spec.lua:56: in function </kong-plugin/spec/myplugin/02-integration_spec.lua:55>

[  ERROR   ] /kong-plugin/spec/myplugin/02-integration_spec.lua @ 55: myplugin: (access) [#cassandra] request gets a 'hello-world' header (60048.85 ms)
[ RUN      ] /kong-plugin/spec/myplugin/02-integration_spec.lua @ 73: myplugin: (access) [#cassandra] response gets a 'bye-world' header
/kong-plugin/spec/myplugin/02-integration_spec.lua:74: timeout

stack traceback:
	/kong-plugin/spec/myplugin/02-integration_spec.lua:74: in function </kong-plugin/spec/myplugin/02-integration_spec.lua:73>

[  ERROR   ] /kong-plugin/spec/myplugin/02-integration_spec.lua @ 73: myplugin: (access) [#cassandra] response gets a 'bye-world' header (60052.69 ms)
[ RUN      ] /kong-plugin/spec/myplugin/02-integration_spec.lua @ 55: myplugin: (access) [#off] request gets a 'hello-world' header
/kong-plugin/spec/myplugin/02-integration_spec.lua:56: timeout

stack traceback:
	/kong-plugin/spec/myplugin/02-integration_spec.lua:56: in function </kong-plugin/spec/myplugin/02-integration_spec.lua:55>

[  ERROR   ] /kong-plugin/spec/myplugin/02-integration_spec.lua @ 55: myplugin: (access) [#off] request gets a 'hello-world' header (60017.37 ms)
[ RUN      ] /kong-plugin/spec/myplugin/02-integration_spec.lua @ 73: myplugin: (access) [#off] response gets a 'bye-world' header
/kong-plugin/spec/myplugin/02-integration_spec.lua:74: timeout

stack traceback:
	/kong-plugin/spec/myplugin/02-integration_spec.lua:74: in function </kong-plugin/spec/myplugin/02-integration_spec.lua:73>

[  ERROR   ] /kong-plugin/spec/myplugin/02-integration_spec.lua @ 73: myplugin: (access) [#off] response gets a 'bye-world' header (60055.03 ms)
[----------] 6 tests from /kong-plugin/spec/myplugin/02-integration_spec.lua (386911.62 ms total)

[----------] Global test environment teardown.
[==========] 8 tests from 2 test files ran. (387071.16 ms total)
[  PASSED  ] 2 tests.
[  ERROR   ] 6 errors, listed below:
[  ERROR   ] /kong-plugin/spec/myplugin/02-integration_spec.lua @ 55: myplugin: (access) [#postgres] request gets a 'hello-world' header
[  ERROR   ] /kong-plugin/spec/myplugin/02-integration_spec.lua @ 73: myplugin: (access) [#postgres] response gets a 'bye-world' header
[  ERROR   ] /kong-plugin/spec/myplugin/02-integration_spec.lua @ 55: myplugin: (access) [#cassandra] request gets a 'hello-world' header
[  ERROR   ] /kong-plugin/spec/myplugin/02-integration_spec.lua @ 73: myplugin: (access) [#cassandra] response gets a 'bye-world' header
[  ERROR   ] /kong-plugin/spec/myplugin/02-integration_spec.lua @ 55: myplugin: (access) [#off] request gets a 'hello-world' header
[  ERROR   ] /kong-plugin/spec/myplugin/02-integration_spec.lua @ 73: myplugin: (access) [#off] response gets a 'bye-world' header

 6 ERRORS

edit (additional info):

$ docker -v
Docker version 20.10.11, build dea9396e18
  • the containers (postgres, cassandra) are created
$ docker ps
CONTAINER ID   IMAGE                   COMMAND                  CREATED              STATUS                          PORTS                                         NAMES
00c9534a9bb6   kong-pongo-test:2.6.0   "/pongo/pongo_entryp…"   About a minute ago   Up About a minute (unhealthy)   8000-8001/tcp, 8443-8444/tcp                  kong-pongo_kong_run_87712978652c
05b4ac724969   cassandra:3.9           "/docker-entrypoint.…"   2 minutes ago        Up 2 minutes (healthy)          7000-7001/tcp, 7199/tcp, 9042/tcp, 9160/tcp   kong-pongo-cassandra-1
e12453404bf2   postgres:9.5            "docker-entrypoint.s…"   2 minutes ago        Up 2 minutes (healthy)          5432/tcp                                      kong-pongo-postgres-1
$ pongo tail
2021/11/22 15:30:40 [notice] 242#0: openresty/1.19.9.1
2021/11/22 15:30:40 [notice] 242#0: built by gcc 10.3.1 20210424 (Alpine 10.3.1_git20210424)
2021/11/22 15:30:40 [notice] 242#0: OS: Linux 5.15.4-arch1-1
2021/11/22 15:30:40 [notice] 242#0: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2021/11/22 15:30:40 [notice] 247#0: start worker processes
2021/11/22 15:30:40 [notice] 247#0: start worker process 248
2021/11/22 15:30:40 [emerg] 248#0: SSL_CTX_load_verify_locations("/kong-plugin/servroot/.ca_combined") failed (SSL: error:0200100D:system library:fopen:Permission denied:fopen('/kong-plugin/servroot/.ca_combined','r') error:2006D002:BIO routines:BIO_new_file:system lib error:0B084002:x509 certificate routines:X509_load_cert_crl_file:system lib)
2021/11/22 15:30:40 [notice] 247#0: signal 17 (SIGCHLD) received from 248
2021/11/22 15:30:40 [notice] 247#0: worker process 248 exited with code 2
2021/11/22 15:30:40 [alert] 247#0: worker process 248 exited with fatal code 2 and cannot be respawned

Any idea?

Thanks for attention.

pongo run failed

ERROR: .FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/bin/assets/docker-compose.yml'

when i run pongo run,i will get this error, and i don't know how to fix it

Tagged release versions

Being that the install process is documented as cloning the repo, it would be nice to have tag denoting fixed + stable points in time.
It might make sense to have the tags mirror the highest version of kong that is support at that time.

2.6.0 support kong <= 2.6.0

Errors during setup - from the stdout logging...

I see the following errors during the initial setup, not sure if these are already addressed?

  Building wheel for multidict (PEP 517): started
  Building wheel for multidict (PEP 517): finished with status 'error'
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3 /usr/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py build_wheel /tmp/tmpohanydcs
       cwd: /tmp/pip-install-8bhgcpmy/multidict_fffb5a7f135c472dbc4036c87159d568
  Complete output (40 lines):
  *********************
  * Accelerated build *
  *********************
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.9
  creating build/lib.linux-x86_64-3.9/multidict
  copying multidict/_multidict_py.py -> build/lib.linux-x86_64-3.9/multidict
  copying multidict/__init__.py -> build/lib.linux-x86_64-3.9/multidict
  copying multidict/_abc.py -> build/lib.linux-x86_64-3.9/multidict
  copying multidict/_multidict_base.py -> build/lib.linux-x86_64-3.9/multidict
  copying multidict/_compat.py -> build/lib.linux-x86_64-3.9/multidict
  running egg_info
  writing multidict.egg-info/PKG-INFO
  writing dependency_links to multidict.egg-info/dependency_links.txt
  writing top-level names to multidict.egg-info/top_level.txt
  reading manifest file 'multidict.egg-info/SOURCES.txt'
  reading manifest template 'MANIFEST.in'
  warning: no previously-included files matching '*.pyc' found anywhere in distribution
  warning: no previously-included files found matching 'multidict/_multidict.html'
  warning: no previously-included files found matching 'multidict/*.so'
  warning: no previously-included files found matching 'multidict/*.pyd'
  warning: no previously-included files found matching 'multidict/*.pyd'
  no previously-included directories found matching 'docs/_build'
  adding license file 'LICENSE'
  writing manifest file 'multidict.egg-info/SOURCES.txt'
  copying multidict/__init__.pyi -> build/lib.linux-x86_64-3.9/multidict
  copying multidict/py.typed -> build/lib.linux-x86_64-3.9/multidict
  running build_ext
  building 'multidict._multidict' extension
  creating build/temp.linux-x86_64-3.9
  creating build/temp.linux-x86_64-3.9/multidict
  gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fomit-frame-pointer -g -fno-semantic-interposition -fomit-frame-pointer -g -fno-semantic-interposition -fomit-frame-pointer -g -fno-semantic-interposition -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/usr/include/python3.9 -c multidict/_multidict.c -o build/temp.linux-x86_64-3.9/multidict/_multidict.o -O2 -std=c99 -Wall -Wsign-compare -Wconversion -fno-strict-aliasing -pedantic
  multidict/_multidict.c:1:10: fatal error: Python.h: No such file or directory
      1 | #include "Python.h"
        |          ^~~~~~~~~~
  compilation terminated.
  error: command '/usr/bin/gcc' failed with exit code 1
  ----------------------------------------
  ERROR: Failed building wheel for multidict
Failed to build multidict
ERROR: Could not build wheels for multidict which use PEP 517 and cannot be installed directly
fatal: not a git repository (or any of the parent directories): .git
busted 2.0.0 not found, installing via luarocks...
...
gcc -shared -o bit32.so lbitlib.o
Warning: unmatched variable LUA_LIBDIR
make[1]: Entering directory '/tmp/luarocks_cqueues-20200726.51-0-558413/cqueues-rel-20200726'
...
...
gcc -O2 -std=gnu99 -fPIC -g -Wall -Wextra  -Wno-missing-field-initializers  -Wno-override-init -Wno-unused -O2 -fPIC -D_REENTRANT -D_THREAD_SAFE -D_GNU_SOURCE -I"/usr/include" -I"/usr/include" -DSOCKET_DEBUG -DHAVE_CONFIG_H -DDNS_RANDOM=RAND_bytes -c -o /tmp/luarocks_cqueues-20200726.51-0-558413/cqueues-rel-20200726/src/lib/dns.o /tmp/luarocks_cqueues-20200726.51-0-558413/cqueues-rel-20200726/src/lib/dns.c
/tmp/luarocks_cqueues-20200726.51-0-558413/cqueues-rel-20200726/src/lib/dns.c: In function 'dns_so_check':
/tmp/luarocks_cqueues-20200726.51-0-558413/cqueues-rel-20200726/src/lib/dns.c:6547:17: warning: array subscript -2 is below array bounds of 'unsigned char[1]' [-Warray-bounds]
 6547 |  so->query->data[-2] = 0xff & (so->query->end >> 8);
      |  ~~~~~~~~~~~~~~~^~~~
In file included from /tmp/luarocks_cqueues-20200726.51-0-558413/cqueues-rel-20200726/src/lib/dns.c:83:
/tmp/luarocks_cqueues-20200726.51-0-558413/cqueues-rel-20200726/src/lib/dns.h:422:17: note: while referencing 'data'
  422 |   unsigned char data[1];
      |                 ^~~~
/tmp/luarocks_cqueues-20200726.51-0-558413/cqueues-rel-20200726/src/lib/dns.c:6548:17: warning: array subscript -1 is below array bounds of 'unsigned char[1]' [-Warray-bounds]
 6548 |  so->query->data[-1] = 0xff & (so->query->end >> 0);
      |  ~~~~~~~~~~~~~~~^~~~
In file included from /tmp/luarocks_cqueues-20200726.51-0-558413/cqueues-rel-20200726/src/lib/dns.c:83:
/tmp/luarocks_cqueues-20200726.51-0-558413/cqueues-rel-20200726/src/lib/dns.h:422:17: note: while referencing 'data'
  422 |   unsigned char data[1];
      |                 ^~~~
/tmp/luarocks_cqueues-20200726.51-0-558413/cqueues-rel-20200726/src/lib/dns.c:6550:9: warning: array subscript -2 is below array bounds of 'unsigned char[1]' [-Warray-bounds]
 6550 |  qsrc = &so->query->data[-2] + so->qout;
      |         ^~~~~~~~~~~~~~~~~~~~
In file included from /tmp/luarocks_cqueues-20200726.51-0-558413/cqueues-rel-20200726/src/lib/dns.c:83:
/tmp/luarocks_cqueues-20200726.51-0-558413/cqueues-rel-20200726/src/lib/dns.h:422:17: note: while referencing 'data'
  422 |   unsigned char data[1];
      |                 ^~~~
/tmp/luarocks_cqueues-20200726.51-0-558413/cqueues-rel-20200726/src/lib/dns.c:6576:10: warning: array subscript -2 is below array bounds of 'unsigned char[1]' [-Warray-bounds]
 6576 |   asrc = &so->answer->data[-2];
      |          ^~~~~~~~~~~~~~~~~~~~~
In file included from /tmp/luarocks_cqueues-20200726.51-0-558413/cqueues-rel-20200726/src/lib/dns.c:83:
/tmp/luarocks_cqueues-20200726.51-0-558413/cqueues-rel-20200726/src/lib/dns.h:422:17: note: while referencing 'data'
  422 |   unsigned char data[1];
      |                 ^~~~
/tmp/luarocks_cqueues-20200726.51-0-558413/cqueues-rel-20200726/src/lib/dns.c:6587:18: warning: array subscript -2 is below array bounds of 'unsigned char[1]' [-Warray-bounds]
 6587 |    alen = ((0xff & so->answer->data[-2]) << 8)
      |            ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /tmp/luarocks_cqueues-20200726.51-0-558413/cqueues-rel-20200726/src/lib/dns.c:83:
/tmp/luarocks_cqueues-20200726.51-0-558413/cqueues-rel-20200726/src/lib/dns.h:422:17: note: while referencing 'data'
  422 |   unsigned char data[1];
      |                 ^~~~
/tmp/luarocks_cqueues-20200726.51-0-558413/cqueues-rel-20200726/src/lib/dns.c:6588:42: warning: array subscript -1 is below array bounds of 'unsigned char[1]' [-Warray-bounds]
 6588 |         | ((0xff & so->answer->data[-1]) << 0);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
In file included from /tmp/luarocks_cqueues-20200726.51-0-558413/cqueues-rel-20200726/src/lib/dns.c:83:
/tmp/luarocks_cqueues-20200726.51-0-558413/cqueues-rel-20200726/src/lib/dns.h:422:17: note: while referencing 'data'
  422 |   unsigned char data[1];
      |                 ^~~~

We do see

Successfully tagged kong-pongo-test:2.8.0
[pongo-INFO] image 'kong-pongo-test:2.8.0' successfully build

However next we see

Kong version: 2.8.0
[==========] Running tests from scanned files.
[----------] Global test environment setup.
[----------] Running tests from /kong-plugin/spec/myplugin/01-unit_spec.lua
2022/03/10 19:50:22 [warn] [Penlight 1.12.0] the contents of module 'pl.text' has moved into 'pl.stringx' (deprecated after 1.11.0, scheduled for removal in 2.0.0)
[ RUN      ] /kong-plugin/spec/myplugin/01-unit_spec.lua @ 18: myplugin: (schema) accepts distinct request_header and response_header
[       OK ] /kong-plugin/spec/myplugin/01-unit_spec.lua @ 18: myplugin: (schema) accepts distinct request_header and response_header (1.08 ms)
[ RUN      ] /kong-plugin/spec/myplugin/01-unit_spec.lua @ 28: myplugin: (schema) does not accept identical request_header and response_header
[       OK ] /kong-plugin/spec/myplugin/01-unit_spec.lua @ 28: myplugin: (schema) does not accept identical request_header and response_header (1.35 ms)
[----------] 2 tests from /kong-plugin/spec/myplugin/01-unit_spec.lua (981.70 ms total)

[----------] Running tests from /kong-plugin/spec/myplugin/02-integration_spec.lua
/kong-plugin/spec/myplugin/02-integration_spec.lua:28: Error: nginx configuration is invalid (exit code 1):
nginx: the configuration file /kong-plugin/servroot/nginx.conf syntax is ok
nginx: [emerg] chown("/kong-plugin/servroot/client_body_temp", 100) failed (13: Permission denied)
nginx: configuration file /kong-plugin/servroot/nginx.conf test failed


  Run with --v (verbose) or --vv (debug) for more details


stack traceback:
	/kong-plugin/spec/myplugin/02-integration_spec.lua:28: in function </kong-plugin/spec/myplugin/02-integration_spec.lua:11>

/kong-plugin/spec/myplugin/02-integration_spec.lua:28: 2022/03/10 19:51:00 [warn] Support for Cassandra is deprecated. Please refer to https://konghq.com/blog/cassandra-support-deprecated (deprecated after 2.7, scheduled for removal in 4.0)
2022/03/10 19:51:00 [warn] You are using Cassandra but your 'db_update_propagation' setting is set to '0' (default). Due to the distributed nature of Cassandra, you should increase this value.
Error: nginx configuration is invalid (exit code 1):
nginx: the configuration file /kong-plugin/servroot/nginx.conf syntax is ok
nginx: [emerg] chown("/kong-plugin/servroot/client_body_temp", 100) failed (13: Permission denied)
nginx: configuration file /kong-plugin/servroot/nginx.conf test failed


  Run with --v (verbose) or --vv (debug) for more details


stack traceback:
	/kong-plugin/spec/myplugin/02-integration_spec.lua:28: in function </kong-plugin/spec/myplugin/02-integration_spec.lua:11>

/kong-plugin/spec/myplugin/02-integration_spec.lua:28: Error: nginx configuration is invalid (exit code 1):
nginx: the configuration file /kong-plugin/servroot/nginx.conf syntax is ok
nginx: [emerg] chown("/kong-plugin/servroot/client_body_temp", 100) failed (13: Permission denied)
nginx: configuration file /kong-plugin/servroot/nginx.conf test failed


  Run with --v (verbose) or --vv (debug) for more details


stack traceback:
	/kong-plugin/spec/myplugin/02-integration_spec.lua:28: in function </kong-plugin/spec/myplugin/02-integration_spec.lua:11>

[----------] 0 tests from /kong-plugin/spec/myplugin/02-integration_spec.lua (41515.26 ms total)

[----------] Global test environment teardown.
[==========] 2 tests from 2 test files ran. (42497.91 ms total)
[  PASSED  ] 2 tests.
[  ERROR   ] 3 errors, listed below:
[  ERROR   ] /kong-plugin/spec/myplugin/02-integration_spec.lua @ 11: myplugin: (access) [#postgres] lazy_setup
[  ERROR   ] /kong-plugin/spec/myplugin/02-integration_spec.lua @ 11: myplugin: (access) [#cassandra] lazy_setup
[  ERROR   ] /kong-plugin/spec/myplugin/02-integration_spec.lua @ 11: myplugin: (access) [#off] lazy_setup

 3 ERRORS
rkazak@Rohintons-Mac-mini kong-plugin % 

support Kong OSS

besides pulling the Kong images from a different repository (docker hub instead of bintray), everything else should mostly work 1-on-1.

Unit test config not match schema

This is my schema.lua

local typedefs = require "kong.db.schema.typedefs"

return {
  name = "coding-external-token",
  fields = {
    { consumer = typedefs.no_consumer },
    -- { config = { type = "record", fields = { test = { type = "string", required = true} } } }
    { 
      config = {type = "record", fields = { 
          rules = { type = "array", required = true, elements = {
              type = "record", fields = {
                client = { type = "string", required = true },
                jwt_secret = { type = "string", required = true },
                routes = { 
                  type = "array", required = true, elements = { 
                    type = "record", fields = {
                      path = { type = "string", required = true },
                      methods = { 
                          type = "array", required = true, elements = {
                            type = "string", required = true,
                        }
                      },
                    },
                  },
                },
              }
            },
          },
        }, 
      },
    },
  },
}

With this schema, I use kong-pongo test my custom plugin.
02-access_spac.lua

local PLUGIN_NAME = "coding-external-token"
local cjson       = require "cjson.safe"
local helpers     = require "spec.helpers"
local jwt_encoder = require "kong.plugins.jwt.jwt_parser"


for _, strategy in helpers.each_strategy() do
  describe(PLUGIN_NAME .. ": (access) [#" .. strategy .. "]", function()
    local client

    lazy_setup(function()

      local bp = helpers.get_db_utils(strategy, nil, { PLUGIN_NAME })

      -- Inject a test route. No need to create a service, there is a default
      -- service which will echo the request.
      local route1 = bp.routes:insert({
        hosts = { "coding-external-token.com" },
      })
      local rules = {
        client = "dmc",
        jwt_secret = "YXNkZ2UzNjQzNTd5MzI4OSsvLSovNisN",
        routes = {
          { 
            path = "/api/ci", 
            methods = {
              "GET", "POST",
            },
          },
          { 
            path = "/api/cd", 
            methods = {
              "PATCH", "DELETE",
            },
          },
        },
      }
      -- add the plugin to test to the route we created
      bp.plugins:insert {
        name = PLUGIN_NAME,
        route = { id = route1.id },
        config = { rules },
      }

      -- start kong
      assert(helpers.start_kong({
        -- set the strategy
        database   = strategy,
        -- use the custom test template to create a local mock server
        nginx_conf = "spec/fixtures/custom_nginx.template",
        -- make sure our plugin gets loaded
        plugins    = "bundled," .. PLUGIN_NAME,
      }))
    end)

    lazy_teardown(function()
      helpers.stop_kong(nil, true)
    end)

    before_each(function()
      client = helpers.proxy_client()
    end)

    after_each(function()
      if client then client:close() end
    end)

    describe("request", function()
      local payload = {
        exp = os.time() + 120,
        jti = 'dmc',
        username = 'nickname',
        uid = 'nickname',
      }
      local jwt = jwt_encoder.encode(payload, "YXNkZ2UzNjQzNTd5MzI4OSsvLSovNisN") 

      it("check request header", function()
        local r = client:get("/request", {
          headers = {
            host = "coding-external-token.com",
            ["Coding-Ex-Token"] = "Bearer " .. jwt,
          }
        })
        assert.response(r).has.status(200)
        local header_value = assert.request(r).has.header("x-forwarded-host")
        assert.equal("coding-external-token.com", header_value)
        local cached_body = assert.response(r).kong_response._cached_body
        cached_body = cjson.decode(cached_body)
        cached_headers= cached_body.headers
        assert.is.truthy(cached_headers['x-consumer-username'])
        assert.is.truthy(cached_headers['x-credential-username'])
      end)
    end)
  end)
end

When I run KONG_VERSION=2.0.4 pongo run ./spec_ex/coding-external-token/, it will show me:

Missing dependencies for kong-plugin-myplugin 0.1.0-1:
   lua-resty-env (not installed)
   lur-resty-http (not installed)

kong-plugin-myplugin 0.1.0-1 depends on lua-resty-env (not installed)
Installing https://luarocks.org/lua-resty-env-0.4.0-1.src.rock

lua-resty-env 0.4.0-1 is now installed in /usr/local (license: Apache License 2.0)

kong-plugin-myplugin 0.1.0-1 depends on lur-resty-http (not installed)

Error: Could not satisfy dependency lur-resty-http: No results matching query were found for Lua 5.1.
Kong version: 2.0.4
[==========] Running tests from scanned files.
[----------] Global test environment setup.
[----------] Running tests from /kong-plugin/spec_ex/coding-external-token/01-schema_spec.lua
[ RUN      ] ...-plugin/spec_ex/coding-external-token/01-schema_spec.lua @ 17: coding-external-token: (schema) validate config
[       OK ] ...-plugin/spec_ex/coding-external-token/01-schema_spec.lua @ 17: coding-external-token: (schema) validate config (0.37 ms)
[----------] 1 test from /kong-plugin/spec_ex/coding-external-token/01-schema_spec.lua (121.29 ms total)

[----------] Running tests from /kong-plugin/spec_ex/coding-external-token/02-access_spec.lua
./spec/helpers.lua:298: error loading plugin schemas: on plugin 'coding-external-token': [postgres] schema violation (fields.2: {
  fields = "expected an array"
})

stack traceback:
        ./spec/helpers.lua:298: in function 'get_db_utils'
        ...-plugin/spec_ex/coding-external-token/02-access_spec.lua:13: in function <...-plugin/spec_ex/coding-external-token/02-access_spec.lua:11>

./spec/helpers.lua:298: error loading plugin schemas: on plugin 'coding-external-token': [cassandra] schema violation (fields.2: {
  fields = "expected an array"
})

stack traceback:
        ./spec/helpers.lua:298: in function 'get_db_utils'
        ...-plugin/spec_ex/coding-external-token/02-access_spec.lua:13: in function <...-plugin/spec_ex/coding-external-token/02-access_spec.lua:11>

[----------] 0 tests from /kong-plugin/spec_ex/coding-external-token/02-access_spec.lua (610.76 ms total)

[----------] Global test environment teardown.
[==========] 1 test from 2 test files ran. (732.33 ms total)
[  PASSED  ] 1 test.
[  ERROR   ] 2 errors, listed below:
[  ERROR   ] ...-plugin/spec_ex/coding-external-token/02-access_spec.lua @ 11: coding-external-token: (access) [#postgres] lazy_setup
[  ERROR   ] ...-plugin/spec_ex/coding-external-token/02-access_spec.lua @ 11: coding-external-token: (access) [#cassandra] lazy_setup

I was so overwhelmed by this question, Please HELP ME!

Kong 2.1.2 CE, ERROR: bin/busted:58: module 'busted.runner' not found

I receive the following error:

Kong version: 2.1.2
ERROR: bin/busted:58: module 'busted.runner' not found:No LuaRocks module found for busted.runner
	no field package.preload['busted.runner']
	no file '/usr/local/openresty/site/lualib/busted/runner.ljbc'
	no file '/usr/local/openresty/site/lualib/busted/runner/init.ljbc'
	no file '/usr/local/openresty/lualib/busted/runner.ljbc'
	no file '/usr/local/openresty/lualib/busted/runner/init.ljbc'
	no file '/usr/local/openresty/site/lualib/busted/runner.lua'
	no file '/usr/local/openresty/site/lualib/busted/runner/init.lua'
	no file '/usr/local/openresty/lualib/busted/runner.lua'
	no file '/usr/local/openresty/lualib/busted/runner/init.lua'
	no file '/kong-plugin/busted/runner.lua'
	no file '/kong-plugin/busted/runner/init.lua'
	no file './busted/runner.lua'
	no file '/usr/local/openresty/luajit/share/luajit-2.1.0-beta3/busted/runner.lua'
	no file '/usr/local/share/lua/5.1/busted/runner.lua'
	no file '/usr/local/share/lua/5.1/busted/runner/init.lua'
	no file '/usr/local/openresty/luajit/share/lua/5.1/busted/runner.lua'
	no file '/usr/local/openresty/luajit/share/lua/5.1/busted/runner/init.lua'
	no file '/root/.luarocks/share/lua/5.1/busted/runner.lua'
	no file '/root/.luarocks/share/lua/5.1/busted/runner/init.lua'
	no file '/usr/local/openresty/site/lualib/busted/runner.so'
	no file '/usr/local/openresty/lualib/busted/runner.so'
	no file './busted/runner.so'
	no file '/usr/local/lib/lua/5.1/busted/runner.so'
	no file '/usr/local/openresty/luajit/lib/lua/5.1/busted/runner.so'
	no file '/usr/local/lib/lua/5.1/loadall.so'
	no file '/root/.luarocks/lib/lua/5.1/busted/runner.so'
	no file '/usr/local/openresty/site/lualib/busted.so'
	no file '/usr/local/openresty/lualib/busted.so'
	no file './busted.so'
	no file '/usr/local/lib/lua/5.1/busted.so'
	no file '/usr/local/openresty/luajit/lib/lua/5.1/busted.so'
	no file '/usr/local/lib/lua/5.1/loadall.so'
	no file '/root/.luarocks/lib/lua/5.1/busted.so'
stack traceback:
	bin/busted:58: in function 'file_gen'
	init_worker_by_lua:49: in function <init_worker_by_lua:47>
	[C]: in function 'xpcall'
	init_worker_by_lua:56: in function <init_worker_by_lua:54>

pongo logs out of docker registries

pongo does docker logout from the registry if set. Is there any security reason for logging out of the docker registry other than cleaning up?

$ git grep "docker logout"
pongo.sh:389:          docker logout $NIGHTLY_EE_DOCKER_REPO
pongo.sh:395:          docker logout $NIGHTLY_EE_DOCKER_REPO
pongo.sh:399:        docker logout $NIGHTLY_EE_DOCKER_REPO
pongo.sh:422:            docker logout $KONG_EE_REPO
pongo.sh:428:            docker logout $KONG_EE_REPO
pongo.sh:432:          docker logout $KONG_EE_REPO

Maybe worth adding a --no-logout option, or an env that can be set to DOCKER_DO_LOGOUT=0.

How to ensure plugin migrations are run when using Pongo?

I am writing a plugin for an old version of Kong (v0.14).. This plugin has some configs that come from the database because of which i have added the relevant migrations in a migrations folder (exposed as migrations submodule in rockspec).

But I get the following error when I run KONG_VERSION=0.14.1 pongo run -v -o gtest ./spec:

kong-plugin/spec/foo/02-access_spec.lua:36: 2020/09/30 06:55:23 [warn] postgres database 'kong_tests' is missing migration: (foo) 2020-09-30-foo
Error: /usr/local/share/lua/5.1/kong/cmd/start.lua:37: [postgres error] the current database schema does not match this version of Kong. Please run `kong migrations up` to update/initialize the database schema. Be aware that Kong migrations should only run from a single node, and that nodes running migrations concurrently will conflict with each other and might corrupt your database schema!

As I understand, when I invoke helpers.get_db_utils() in my spec, it internally runs dao:run_migrations(). May be this is not doing my custom plugin migrations?

Any pointers would be really helpful. Thanks 🙂

module 'busted.runner' not found not found for 0.14.1 and 0.14.0

I am getting. this error when running pongo, for both Kong 0.14.0 and 0.14.1

$ KONG_VERSION=0.14.0 pongo run -v -o gtest ./spec


Kong version: 0.14.0
ERROR: bin/busted:70: module 'busted.runner' not found:No LuaRocks module found for busted.runner
	no field package.preload['busted.runner']
	no file '/usr/local/openresty/site/lualib/busted/runner.ljbc'
	no file '/usr/local/openresty/site/lualib/busted/runner/init.ljbc'
	no file '/usr/local/openresty/lualib/busted/runner.ljbc'
	no file '/usr/local/openresty/lualib/busted/runner/init.ljbc'
	no file '/usr/local/openresty/site/lualib/busted/runner.lua'
	no file '/usr/local/openresty/site/lualib/busted/runner/init.lua'
	no file '/usr/local/openresty/lualib/busted/runner.lua'
	no file '/usr/local/openresty/lualib/busted/runner/init.lua'
	no file '/kong-plugin/busted/runner.lua'
	no file '/kong-plugin/busted/runner/init.lua'
	no file './busted/runner.lua'
	no file '/usr/local/openresty/luajit/share/luajit-2.1.0-beta3/busted/runner.lua'
	no file '/usr/local/share/lua/5.1/busted/runner.lua'
	no file '/usr/local/share/lua/5.1/busted/runner/init.lua'
	no file '/usr/local/openresty/luajit/share/lua/5.1/busted/runner.lua'
	no file '/usr/local/openresty/luajit/share/lua/5.1/busted/runner/init.lua'
	no file '/root/.luarocks/share/lua/5.1/busted/runner.lua'
	no file '/root/.luarocks/share/lua/5.1/busted/runner/init.lua'
	no file '/usr/local/openresty/site/lualib/busted/runner.so'
	no file '/usr/local/openresty/lualib/busted/runner.so'
	no file './busted/runner.so'
	no file '/usr/local/lib/lua/5.1/busted/runner.so'
	no file '/usr/local/openresty/luajit/lib/lua/5.1/busted/runner.so'
	no file '/usr/local/lib/lua/5.1/loadall.so'
	no file '/root/.luarocks/lib/lua/5.1/busted/runner.so'
	no file '/usr/local/openresty/site/lualib/busted.so'
	no file '/usr/local/openresty/lualib/busted.so'
	no file './busted.so'
	no file '/usr/local/lib/lua/5.1/busted.so'
	no file '/usr/local/openresty/luajit/lib/lua/5.1/busted.so'
	no file '/usr/local/lib/lua/5.1/loadall.so'
	no file '/root/.luarocks/lib/lua/5.1/busted.so'
stack traceback:
	bin/busted:70: in function 'file_gen'
	init_worker_by_lua:52: in function <init_worker_by_lua:50>
	[C]: in function 'xpcall'
	init_worker_by_lua:59: in function <init_worker_by_lua:57>
make: *** [spec] Error 1

/bin/sh: luarocks: not found

I found those error when run polngo:

[root@centos ~/kong-plugin]# pongo run
[pongo-INFO] auto-starting the test environment, use the 'pongo down' action to stop it
[pongo-INFO] image 'kong-pongo-test:2.3.3' not found, auto-building it
[pongo-INFO] starting build of image 'kong-pongo-test:2.3.3'
Sending build context to Docker daemon  49.09MB
Step 1/12 : ARG KONG_BASE
Step 2/12 : FROM ${KONG_BASE}
 ---> 07cad33482c5
Step 3/12 : ARG KONG_DEV_FILES
 ---> Using cache
 ---> 70cb2302da41
Step 4/12 : COPY $KONG_DEV_FILES /kong
 ---> Using cache
 ---> a8e5d7d37b94
Step 5/12 : COPY assets/busted_helper.lua /kong/bin
 ---> Using cache
 ---> 797fa34cd340
Step 6/12 : COPY assets/test_plugin_entrypoint.sh /kong/bin/test_plugin_entrypoint.sh
 ---> Using cache
 ---> a59bd9213fa5
Step 7/12 : COPY assets/pongo_pack /kong/bin/pongo_pack
 ---> Using cache
 ---> 453074e467c8
Step 8/12 : USER root
 ---> Using cache
 ---> 99544cb5d4e5
Step 9/12 : RUN apk update     && apk add zip unzip make g++ py-pip jq git bsd-compat-headers m4 openssl-dev curl luarocks     && curl -s -S -L https://github.com/fullstorydev/grpcurl/releases/download/v1.7.0/grpcurl_1.7.0_linux_x86_64.tar.gz | tar xz -C /kong/bin     && pip install 'httpie<2.0.0'    && cd /kong     && make dependencies     && /usr/local/bin/luarocks install busted-htest     && chmod +x /kong/bin/test_plugin_entrypoint.sh
 ---> Running in 3bc914bb710c
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz
v3.11.8-11-gde3fd9f346 [http://dl-cdn.alpinelinux.org/alpine/v3.11/main]
v3.11.7-55-g693730bf76 [http://dl-cdn.alpinelinux.org/alpine/v3.11/community]
OK: 11272 distinct packages available
(1/25) Installing bsd-compat-headers (0.7.2-r0)
(2/25) Installing curl (7.67.0-r3)
(3/25) Installing binutils (2.33.1-r0)
(4/25) Installing gmp (6.1.2-r1)
(5/25) Installing isl (0.18-r0)
(6/25) Installing libgomp (9.3.0-r0)
(7/25) Installing libatomic (9.3.0-r0)
(8/25) Installing mpfr4 (4.0.2-r1)
(9/25) Installing mpc1 (1.1.0-r1)
(10/25) Installing gcc (9.3.0-r0)
(11/25) Installing musl-dev (1.1.24-r3)
(12/25) Installing libc-dev (0.7.2-r0)
(13/25) Installing g++ (9.3.0-r0)
(14/25) Installing oniguruma (6.9.4-r1)
(15/25) Installing jq (1.6-r0)
(16/25) Installing luarocks (2.4.4-r1)
(17/25) Installing m4 (1.4.18-r1)
(18/25) Installing make (4.2.1-r2)
(19/25) Installing openssl-dev (1.1.1j-r0)
(20/25) Installing libffi (3.2.1-r6)
(21/25) Installing gdbm (1.13-r1)
(22/25) Installing sqlite-libs (3.30.1-r2)
(23/25) Installing python2 (2.7.18-r0)
(24/25) Installing py-setuptools (42.0.2-r0)
(25/25) Installing py2-pip (18.1-r0)
Executing busybox-1.31.1-r9.trigger
OK: 287 MiB in 64 packages
Collecting httpie<2.0.0
  Downloading https://files.pythonhosted.org/packages/da/08/22487f04aa2cb831c5e02c9286f1d145f81b06bf9bbf1e73b70d2dc15d7f/httpie-1.0.3-py2.py3-none-any.whl (59kB)
Collecting requests>=2.21.0 (from httpie<2.0.0)
  Downloading https://files.pythonhosted.org/packages/29/c1/24814557f1d22c56d50280771a17307e6bf87b70727d975fd6b2ce6b014a/requests-2.25.1-py2.py3-none-any.whl (61kB)
Collecting Pygments>=2.3.1 (from httpie<2.0.0)
  Downloading https://files.pythonhosted.org/packages/be/39/32da3184734730c0e4d3fa3b2b5872104668ad6dc1b5a73d8e477e5fe967/Pygments-2.5.2-py2.py3-none-any.whl (896kB)
Collecting urllib3<1.27,>=1.21.1 (from requests>=2.21.0->httpie<2.0.0)
  Downloading https://files.pythonhosted.org/packages/23/fc/8a49991f7905261f9ca9df5aa9b58363c3c821ce3e7f671895442b7100f2/urllib3-1.26.3-py2.py3-none-any.whl (137kB)
Collecting idna<3,>=2.5 (from requests>=2.21.0->httpie<2.0.0)
  Downloading https://files.pythonhosted.org/packages/a2/38/928ddce2273eaa564f6f50de919327bf3a00f091b5baba8dfa9460f3a8a8/idna-2.10-py2.py3-none-any.whl (58kB)
Collecting certifi>=2017.4.17 (from requests>=2.21.0->httpie<2.0.0)
  Downloading https://files.pythonhosted.org/packages/5e/a0/5f06e1e1d463903cf0c0eebeb751791119ed7a4b3737fdc9a77f1cdfb51f/certifi-2020.12.5-py2.py3-none-any.whl (147kB)
Collecting chardet<5,>=3.0.2 (from requests>=2.21.0->httpie<2.0.0)
  Downloading https://files.pythonhosted.org/packages/19/c7/fa589626997dd07bd87d9269342ccb74b1720384a4d739a1872bd84fbe68/chardet-4.0.0-py2.py3-none-any.whl (178kB)
Installing collected packages: urllib3, idna, certifi, chardet, requests, Pygments, httpie
Successfully installed Pygments-2.5.2 certifi-2020.12.5 chardet-4.0.0 httpie-1.0.3 idna-2.10 requests-2.25.1 urllib3-1.26.3
fatal: not a git repository (or any of the parent directories): .git
busted 2.0.0 not found, installing via luarocks...
Installing https://luarocks.org/busted-2.0.0-1.rockspec
Missing dependencies for busted 2.0.0-1:
   lua_cliargs 3.0 (not installed)
   luasystem >= 0.2.0 (not installed)
   dkjson >= 2.1.0 (not installed)
   say >= 1.3 (not installed)
   luassert >= 1.8.0 (not installed)
   lua-term >= 0.1 (not installed)
   mediator_lua >= 1.1.1 (not installed)

busted 2.0.0-1 depends on lua >= 5.1 (5.1-1 provided by VM)
busted 2.0.0-1 depends on lua_cliargs 3.0 (not installed)
Installing https://luarocks.org/lua_cliargs-3.0-2.src.rock

lua_cliargs 3.0-2 depends on lua >= 5.1 (5.1-1 provided by VM)
lua_cliargs 3.0-2 is now installed in /usr/local (license: MIT <http://opensource.org/licenses/MIT>)

busted 2.0.0-1 depends on luafilesystem >= 1.5.0 (1.8.0-1 installed)
busted 2.0.0-1 depends on luasystem >= 0.2.0 (not installed)
Installing https://luarocks.org/luasystem-0.2.1-0.src.rock

luasystem 0.2.1-0 depends on lua >= 5.1 (5.1-1 provided by VM)
gcc -O2 -fPIC -I/usr/local/openresty/luajit/include/luajit-2.1 -c src/core.c -o src/core.o -I/usr/include
gcc -O2 -fPIC -I/usr/local/openresty/luajit/include/luajit-2.1 -c src/compat.c -o src/compat.o -I/usr/include
gcc -O2 -fPIC -I/usr/local/openresty/luajit/include/luajit-2.1 -c src/time.c -o src/time.o -I/usr/include
gcc -shared -o system/core.so src/core.o src/compat.o src/time.o -L/usr/lib -Wl,-rpath,/usr/lib -lrt
luasystem 0.2.1-0 is now installed in /usr/local (license: MIT <http://opensource.org/licenses/MIT>)

busted 2.0.0-1 depends on dkjson >= 2.1.0 (not installed)
Installing https://luarocks.org/dkjson-2.5-2.src.rock

dkjson 2.5-2 depends on lua >= 5.1, < 5.4 (5.1-1 provided by VM)
dkjson 2.5-2 is now installed in /usr/local (license: MIT/X11)

busted 2.0.0-1 depends on say >= 1.3 (not installed)
Installing https://luarocks.org/say-1.3-1.rockspec

say 1.3-1 depends on lua >= 5.1 (5.1-1 provided by VM)
say 1.3-1 is now installed in /usr/local (license: MIT <http://opensource.org/licenses/MIT>)

busted 2.0.0-1 depends on luassert >= 1.8.0 (not installed)
Installing https://luarocks.org/luassert-1.8.0-0.rockspec

luassert 1.8.0-0 depends on lua >= 5.1 (5.1-1 provided by VM)
luassert 1.8.0-0 depends on say >= 1.2-1 (1.3-1 installed)
luassert 1.8.0-0 is now installed in /usr/local (license: MIT <http://opensource.org/licenses/MIT>)

busted 2.0.0-1 depends on lua-term >= 0.1 (not installed)
Installing https://luarocks.org/lua-term-0.7-1.rockspec

gcc -O2 -fPIC -I/usr/local/openresty/luajit/include/luajit-2.1 -c core.c -o core.o
gcc -shared -o term/core.so core.o
lua-term 0.7-1 is now installed in /usr/local (license: MIT/X11)

busted 2.0.0-1 depends on penlight >= 1.3.2 (1.9.2-1 installed)
busted 2.0.0-1 depends on mediator_lua >= 1.1.1 (not installed)
Installing https://luarocks.org/mediator_lua-1.1.2-0.rockspec

mediator_lua 1.1.2-0 depends on lua >= 5.1 (5.1-1 provided by VM)
mediator_lua 1.1.2-0 is now installed in /usr/local (license: MIT <http://opensource.org/licenses/MIT>)

busted 2.0.0-1 is now installed in /usr/local (license: MIT <http://opensource.org/licenses/MIT>)

/bin/sh: luarocks: not found
busted-htest 1.0.0 not found, installing via luarocks...
/bin/sh: luarocks: not found
/bin/sh: luarocks: not found
luacheck 0.24.0 not found, installing via luarocks...
/bin/sh: luarocks: not found
/bin/sh: luarocks: not found
lua-llthreads2 0.1.5 not found, installing via luarocks...
/bin/sh: luarocks: not found
/bin/sh: luarocks: not found
http 0.3 not found, installing via luarocks...
/bin/sh: luarocks: not found
/bin/sh: luarocks: not found
ldoc 1.4.6 not found, installing via luarocks...
/bin/sh: luarocks: not found
make: *** [Makefile:117: dependencies] Error 127
The command '/bin/sh -c apk update     && apk add zip unzip make g++ py-pip jq git bsd-compat-headers m4 openssl-dev curl luarocks     && curl -s -S -L https://github.com/fullstorydev/grpcurl/releases/download/v1.7.0/grpcurl_1.7.0_linux_x86_64.tar.gz | tar xz -C /kong/bin     && pip install 'httpie<2.0.0'    && cd /kong     && make dependencies     && /usr/local/bin/luarocks install busted-htest     && chmod +x /kong/bin/test_plugin_entrypoint.sh' returned a non-zero code: 2
[pongo-ERROR] Error: failed to build test environment

I try add path env for luarocks in kong-pongo/assets/Dockerfile,but not fixed :

RUN apk update \
    .....
    && ln -sf /usr/local/bin/luarocks /bin/ \    <---
    && make dependencies \
    ....

Errors during setup - wsl debian or ubuntu

Hi.

I am following the guide to install it but it fails during execution, I tried without root and with root, I am on Windows 11.

Steps I followed for the setup:

sudo apt update
sudo apt install git curl coreutils

cd ~
git clone https://github.com/Kong/kong-pongo.git
mkdir -p ~/.local/bin
ln -s $(realpath kong-pongo/pongo.sh) ~/.local/bin/pongo
PATH=$PATH:~/.local/bin

root@chrispc:~/kong-pongo# pongo run
[pongo-INFO] auto-starting the test environment, use the 'pongo down' action to stop it
[+] Running 2/2
 ⠿ Network pongo-1dd560c3               Created                                                                                                                    1.0s
 ⠿ Container pongo-1dd560c3-postgres-1  Started                                                                                                                    1.5s
[+] Running 1/1
 ⠿ Container pongo-1dd560c3-cassandra-1  Started                                                                                                                   1.3s
[pongo-INFO] Waiting for postgres
[pongo-INFO] Waiting for cassandra
[pongo-INFO] image 'kong-pongo-test:2.8.1' not found, auto-building it
[pongo-INFO] starting build of image 'kong-pongo-test:2.8.1'
[+] Building 27.5s (12/13)
 => [internal] load build definition from Dockerfile                                                                                                               0.0s
 => => transferring dockerfile: 32B                                                                                                                                0.0s
 => [internal] load .dockerignore                                                                                                                                  0.0s
 => => transferring context: 2B                                                                                                                                    0.0s
 => [internal] load metadata for docker.io/library/kong:2.8.1-alpine                                                                                               0.0s
 => [1/9] FROM docker.io/library/kong:2.8.1-alpine                                                                                                                 0.0s
 => [internal] load build context                                                                                                                                  0.0s
 => => transferring context: 25.64kB                                                                                                                               0.0s
 => CACHED [2/9] COPY ./kong-versions/2.8.1/kong /kong                                                                                                             0.0s
 => CACHED [3/9] COPY assets/busted_helper.lua      /pongo/busted_helper.lua                                                                                       0.0s
 => CACHED [4/9] COPY assets/pongo_entrypoint.sh    /pongo/pongo_entrypoint.sh                                                                                     0.0s
 => CACHED [5/9] COPY assets/default-pongo-setup.sh /pongo/default-pongo-setup.sh                                                                                  0.0s
 => CACHED [6/9] COPY assets/pongo_pack.lua         /pongo/pongo_pack.lua                                                                                          0.0s
 => CACHED [7/9] COPY assets/pongo_profile.sh       /etc/profile.d/pongo_profile.sh                                                                                0.0s
 => ERROR [8/9] RUN apk update     && apk add zip unzip make g++ py-pip jq git bsd-compat-headers m4 openssl-dev curl     && curl -k -s -S -L https://github.com  27.4s
[8/9] RUN apk update     && apk add zip unzip make g++ py-pip jq git bsd-compat-headers m4 openssl-dev curl     && curl -k -s -S -L https://github.com/fullstorydev/grpcurl/releases/download/v1.7.0/grpcurl_1.7.0_linux_x86_64.tar.gz | tar xz -C /kong/bin     && pip install httpie     ; cd /kong     && git config --global url.https://github.com/.insteadOf git://github.com/     && make dependencies     && luarocks install busted-htest     && luarocks install luacov:
#12 0.641 fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/main/x86_64/APKINDEX.tar.gz
#12 1.275 fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/community/x86_64/APKINDEX.tar.gz
#12 1.709 v3.15.4-23-g26ba280437 [https://dl-cdn.alpinelinux.org/alpine/v3.15/main]
#12 1.709 v3.15.4-26-g36f9d42a4c [https://dl-cdn.alpinelinux.org/alpine/v3.15/community]
#12 1.709 OK: 15857 distinct packages available
#12 2.076 (1/51) Installing bsd-compat-headers (0.7.2-r3)
#12 2.223 (2/51) Installing curl (7.80.0-r0)
#12 2.306 (3/51) Installing binutils (2.37-r3)
#12 2.771 (4/51) Installing libgomp (10.3.1_git20211027-r0)
#12 2.849 (5/51) Installing libatomic (10.3.1_git20211027-r0)
#12 2.871 (6/51) Installing libgphobos (10.3.1_git20211027-r0)
#12 3.173 (7/51) Installing gmp (6.2.1-r1)
#12 3.230 (8/51) Installing isl22 (0.22-r0)
#12 3.379 (9/51) Installing mpfr4 (4.1.0-r0)
#12 3.707 (10/51) Installing mpc1 (1.2.1-r0)
#12 3.855 (11/51) Installing gcc (10.3.1_git20211027-r0)
#12 8.712 (12/51) Installing musl-dev (1.2.2-r7)
#12 9.165 (13/51) Installing libc-dev (0.7.2-r3)
#12 9.186 (14/51) Installing g++ (10.3.1_git20211027-r0)
#12 11.79 (15/51) Installing oniguruma (6.9.7.1-r0)
#12 11.92 (16/51) Installing jq (1.6-r1)
#12 11.98 (17/51) Installing m4 (1.4.18-r2)
#12 12.02 (18/51) Installing make (4.3-r0)
#12 12.29 (19/51) Installing openssl-dev (1.1.1n-r0)
#12 12.43 (20/51) Installing libffi (3.4.2-r1)
#12 12.49 (21/51) Installing gdbm (1.22-r0)
#12 12.52 (22/51) Installing xz-libs (5.2.5-r1)
#12 12.59 (23/51) Installing mpdecimal (2.5.1-r1)
#12 12.65 (24/51) Installing sqlite-libs (3.36.0-r0)
#12 12.74 (25/51) Installing python3 (3.9.7-r4)
#12 14.69 (26/51) Installing py3-appdirs (1.4.4-r2)
#12 14.74 (27/51) Installing py3-certifi (2020.12.5-r1)
#12 14.78 (28/51) Installing py3-charset-normalizer (2.0.7-r0)
#12 14.83 (29/51) Installing py3-idna (3.3-r0)
#12 14.87 (30/51) Installing py3-urllib3 (1.26.7-r0)
#12 14.95 (31/51) Installing py3-requests (2.26.0-r1)
#12 15.01 (32/51) Installing py3-msgpack (1.0.2-r1)
#12 15.07 (33/51) Installing py3-lockfile (0.12.2-r4)
#12 15.09 (34/51) Installing py3-cachecontrol (0.12.10-r0)
#12 15.13 (35/51) Installing py3-colorama (0.4.4-r1)
#12 15.18 (36/51) Installing py3-contextlib2 (21.6.0-r1)
#12 15.21 (37/51) Installing py3-distlib (0.3.3-r0)
#12 15.37 (38/51) Installing py3-distro (1.6.0-r0)
#12 15.51 (39/51) Installing py3-six (1.16.0-r0)
#12 15.59 (40/51) Installing py3-webencodings (0.5.1-r4)
#12 15.65 (41/51) Installing py3-html5lib (1.1-r1)
#12 15.72 (42/51) Installing py3-parsing (2.4.7-r2)
#12 15.78 (43/51) Installing py3-packaging (20.9-r1)
#12 15.81 (44/51) Installing py3-tomli (1.2.2-r0)
#12 15.87 (45/51) Installing py3-pep517 (0.12.0-r0)
#12 15.90 (46/51) Installing py3-progress (1.6-r0)
#12 15.92 (47/51) Installing py3-retrying (1.3.3-r2)
#12 15.94 (48/51) Installing py3-ordered-set (4.0.2-r2)
#12 15.97 (49/51) Installing py3-setuptools (52.0.0-r4)
#12 16.09 (50/51) Installing py3-toml (0.10.2-r2)
#12 16.13 (51/51) Installing py3-pip (20.3.4-r1)
#12 16.52 Executing busybox-1.34.1-r5.trigger
#12 16.53 OK: 318 MiB in 91 packages
#12 21.82 curl: (6) Could not resolve host: objects.githubusercontent.com
#12 21.82 tar: invalid magic
#12 21.82 tar: short read
#12 21.84 fatal: not a git repository (or any of the parent directories): .git
#12 27.04 curl: (6) Could not resolve host: objects.githubusercontent.com
#12 27.04 tar: invalid magic
#12 27.04 tar: short read
#12 27.04 make: *** [Makefile:133: bin/grpcurl] Error 1
executor failed running [/bin/sh -c apk update     && apk add zip unzip make g++ py-pip jq git bsd-compat-headers m4 openssl-dev curl     && curl -k -s -S -L https://github.com/fullstorydev/grpcurl/releases/download/v1.7.0/grpcurl_1.7.0_linux_x86_64.tar.gz | tar xz -C /kong/bin     && pip install httpie     ; cd /kong     && git config --global url.https://github.com/.insteadOf git://github.com/     && make dependencies     && luarocks install busted-htest     && luarocks install luacov]: exit code: 2
[pongo-ERROR] Error: failed to build test environment

Any Idea?

Proper plugin configuration for development and/or CI/CD

Hi,
In order for a plugin to be available in Kong we need to edit the kong_tests.conf file. and add, for i.e.:

plugins=bundled,dummy,rewriter,my-plugin

then we would have to rebuild the test images, run test, etc.

What's the correct process (or best practice) of editing this file in a CI/CD with many plugins?
And to specific extent, when developing plugins. How would you configure such thing? Do I really need to configure and rebuild it every time I switch plugins?

Thanks!
Elad.

Failure when docker-compose not installed

Trying a run of pongo on a fresh machine (without docker-compose installed) resulted in:

$ ../kong-pongo/pongo.sh run ./spec
../kong-pongo/pongo.sh: line 223: docker-compose: command not found
Notice: auto-starting the test environment, use the 'down' action to stop it
../kong-pongo/pongo.sh: line 223: docker-compose: command not found
../kong-pongo/pongo.sh: line 223: docker-compose: command not found
Waiting for postgres

And proceeds to hang forever.

support busted parameters

currently you can only (and even must) pass files to the run command. The busted options are now hardcoded to -v -o gtest.

Anything passed that is not a file or directory will cause an error/abort.

Upload Pongo images instead of rebuilding them

Currently Pongo builds images locally after installation. We can probably reduce test times in CI if we upload the images to a docker repo and just pull them. This will also improve the experience for users behind corporate proxies and curated repositories.

2 issues I can see for now;

  • since they are development images, they'll probably be flagged for security issues, do we want to maintain this? (or don't we care about the red flags?)
  • Pongo itself is not versioned. But the images are somewhat tightly coupled to the Pongo version that build it.

Postgres version

The readme says that the default postgres version is 9.5, and the examples use 9.4

Isn't the minimum supported version 9.6? And shouldn't testing be encouraged with newer releases?

Kong 2.0.3 hasn't yet been published on dockerhub

#62 introduces support for Kong 2.0.3, but this causes build issues if using master, as only 2.0.2 is yet available on dockerhub. Certainly, this issue can be avoided by checking out a specific revision, but it might be more usable if this repo had tags for each supported Kong version.

How can I run tests against a redis cluster?

I'm developing a kong plugin that needs to use a redis cluster. But there's no way to specify redis image when running pongo only redis version. Is there a plan to add that configuration setting to the pongo tool?
Thank you!

Module busted.runner not found for KONG_VERSION=2.5.0

Exactly the same as in #94 but for version 2.5.0:

Creating kong-pongo_kong_run ... done

Stopping after installing dependencies for kong-plugin-myplugin 0.1.0-1

Kong version: 2.5.0
ERROR: bin/busted:58: module 'busted.runner' not found:No LuaRocks module found for busted.runner
        no field package.preload['busted.runner']
        no file '/usr/local/openresty/site/lualib/busted/runner.ljbc'
        no file '/usr/local/openresty/site/lualib/busted/runner/init.ljbc'
        no file '/usr/local/openresty/lualib/busted/runner.ljbc'
        no file '/usr/local/openresty/lualib/busted/runner/init.ljbc'
        no file '/usr/local/openresty/site/lualib/busted/runner.lua'
        no file '/usr/local/openresty/site/lualib/busted/runner/init.lua'
        no file '/usr/local/openresty/lualib/busted/runner.lua'
        no file '/usr/local/openresty/lualib/busted/runner/init.lua'
        no file '/kong-plugin/busted/runner.lua'
        no file '/kong-plugin/busted/runner/init.lua'
        no file './busted/runner.lua'
        no file '/usr/local/openresty/luajit/share/luajit-2.1.0-beta3/busted/runner.lua'
        no file '/usr/local/share/lua/5.1/busted/runner.lua'
        no file '/usr/local/share/lua/5.1/busted/runner/init.lua'
        no file '/usr/local/openresty/luajit/share/lua/5.1/busted/runner.lua'
        no file '/usr/local/openresty/luajit/share/lua/5.1/busted/runner/init.lua'
        no file '/root/.luarocks/share/lua/5.1/busted/runner.lua'
        no file '/root/.luarocks/share/lua/5.1/busted/runner/init.lua'
        no file '/usr/local/openresty/site/lualib/busted/runner.so'
        no file '/usr/local/openresty/lualib/busted/runner.so'
        no file './busted/runner.so'
        no file '/usr/local/lib/lua/5.1/busted/runner.so'
        no file '/usr/local/openresty/luajit/lib/lua/5.1/busted/runner.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
        no file '/root/.luarocks/lib/lua/5.1/busted/runner.so'
        no file '/usr/local/openresty/site/lualib/busted.so'
        no file '/usr/local/openresty/lualib/busted.so'
        no file './busted.so'
        no file '/usr/local/lib/lua/5.1/busted.so'
        no file '/usr/local/openresty/luajit/lib/lua/5.1/busted.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
        no file '/root/.luarocks/lib/lua/5.1/busted.so'
stack traceback:
        bin/busted:58: in function 'file_gen'
        init_worker_by_lua:47: in function <init_worker_by_lua:45>
        [C]: in function 'xpcall'
        init_worker_by_lua:54: in function <init_worker_by_lua:52>
ERROR: 1

Error Building docker: Make Not Found

I tried to build kong pongo docker image, I got the following error:

❯ KONG_VERSION=2.6.0 kong-pongo/pongo.sh build --no-cassandra --no-postgres --force

[pongo-INFO] starting build of image 'kong-pongo-test:2.6.0'
[+] Building 1520.3s (12/13)
 => [internal] load build definition from Dockerfile                                                                                                  0.0s
 => => transferring dockerfile: 37B                                                                                                                   0.0s
 => [internal] load .dockerignore                                                                                                                     0.0s
 => => transferring context: 2B                                                                                                                       0.0s
 => [internal] load metadata for docker.io/library/kong:2.6.0-alpine                                                                                  0.0s
 => [1/9] FROM docker.io/library/kong:2.6.0-alpine                                                                                                    0.0s
 => [internal] load build context                                                                                                                     0.1s
 => => transferring context: 25.72kB                                                                                                                  0.1s
 => CACHED [2/9] COPY ./kong-versions/2.6.0/kong /kong                                                                                                0.0s
 => CACHED [3/9] COPY assets/busted_helper.lua      /pongo/busted_helper.lua                                                                          0.0s
 => CACHED [4/9] COPY assets/pongo_entrypoint.sh    /pongo/pongo_entrypoint.sh                                                                        0.0s
 => CACHED [5/9] COPY assets/default-pongo-setup.sh /pongo/default-pongo-setup.sh                                                                     0.0s
 => CACHED [6/9] COPY assets/pongo_pack.lua         /pongo/pongo_pack.lua                                                                             0.0s
 => CACHED [7/9] COPY assets/pongo_profile.sh       /etc/profile.d/pongo_profile.sh                                                                   0.0s
 => ERROR [8/9] RUN apk update     && apk add zip unzip make g++ py-pip jq git bsd-compat-headers m4 openssl-dev curl     && curl -k -s -S -L htt  1520.1s
------
 > [8/9] RUN apk update     && apk add zip unzip make g++ py-pip jq git bsd-compat-headers m4 openssl-dev curl     && curl -k -s -S -L https://github.com/fullstorydev/grpcurl/releases/download/v1.7.0/grpcurl_1.7.0_linux_x86_64.tar.gz | tar xz -C /kong/bin     && pip install httpie     ; cd /kong     && make dependencies     && luarocks install busted-htest     && luarocks install luacov:
#12 0.222 fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/x86_64/APKINDEX.tar.gz
#12 63.25 fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/x86_64/APKINDEX.tar.gz
#12 1520.0 ERROR: https://dl-cdn.alpinelinux.org/alpine/v3.14/community: BAD signature
#12 1520.0 WARNING: Ignoring https://dl-cdn.alpinelinux.org/alpine/v3.14/community: No such file or directory
#12 1520.1 v3.14.3-14-g9234faeb0d [https://dl-cdn.alpinelinux.org/alpine/v3.14/main]
#12 1520.1 1 errors; 4791 distinct packages available
#12 1520.1 /bin/sh: make: not found
------
executor failed running [/bin/sh -c apk update     && apk add zip unzip make g++ py-pip jq git bsd-compat-headers m4 openssl-dev curl     && curl -k -s -S -L https://github.com/fullstorydev/grpcurl/releases/download/v1.7.0/grpcurl_1.7.0_linux_x86_64.tar.gz | tar xz -C /kong/bin     && pip install httpie     ; cd /kong     && make dependencies     && luarocks install busted-htest     && luarocks install luacov]: exit code: 127
[pongo-ERROR] Error: failed to build test environment

My Docker version:

❯ docker version
Client:
 Cloud integration: v1.0.20
 Version:           20.10.10
 API version:       1.41
 Go version:        go1.16.9
 Git commit:        b485636
 Built:             Mon Oct 25 07:43:15 2021
 OS/Arch:           darwin/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.10
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.9
  Git commit:       e2f740d
  Built:            Mon Oct 25 07:41:30 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.11
  GitCommit:        5b46e404f6b9f661a205e28d59c982d3634148f8
 runc:
  Version:          1.0.2
  GitCommit:        v1.0.2-0-g52b36a2
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Any help will be appreciated. Thank you!

`pongo nuke`

It seems that pongo clean is similar in features to gojira nuke. Could it be renamed to pongo nuke then?

Does kong-pongo support http mock data?

In my plugin, I will send a request to another service(I named svc-a) by lua-resty-http. But sometimes svc-a is not available, so i want to when I use kong-pongo send a http request in my plugin, I can get some data that I already set in a json or yaml file.

I'm not sure kong-pongo is support this feature, if not, could you give me a advice?

What i want seems like this:

mock_data.json

{
    "code":0,
    "data":{
        "name":"nickname",
        "uid":"12345",
        "sex":"man"
    }
}

plugin code

local http = require "resty.http"

-- some code...
local function get_user_from_http(conf, sid)
  local httpc = http.new()
  httpc:set_timeout(conf.session_service_timeout)

  if not iam_domain or not iam_auth then
    kong.log.err("kong service deploy error, can not get environment")
    return false, { status = 500, message = "Kong Error: No ENV" }
  end

  local iam_type = "session"
  local iam_value = sid
  local iam_url = string.format("%s%s?type=%s&value=%s", iam_domain, iam_auth, iam_type, iam_value)

  local resp, err = httpc:request_uri(iam_url)
  if err then
    kong.log.err("call iam server to get user info err: " .. err)
    return nil, { status = 400, message = "Bad Request " .. iam_url }
  end

  if resp.status ~= 200 then
    kong.log.err("invalid user: " .. token)
    return nil, { status = 400, message = "Bad Request, Status Not Equal 200" }
  end

  local result = cjson.decode(resp.body)
  if result.code ~= 0 then
    kong.log.err("iam service return err: " .. cjson.encode(result.msg))
    return nil, { status = 401, message = "Invaild Session " .. cjson.encode(result)}
  end
  return result.data       -- data is what i set in mock_data.json
end
-- some code...

unit test code

  -- some code...
  describe(PLUGIN_NAME .. ": (access) [#" .. strategy .. "]", function()
    local client

    lazy_setup(function()

      local bp = helpers.get_db_utils(strategy, nil, { PLUGIN_NAME }) 
           
      -- Inject a test route. No need to create a service, there is a default
      -- service which will echo the request.
      local route1 = bp.routes:insert({
        hosts = { "token.com" },
      })

      -- add the plugin to test to the route we created
      bp.plugins:insert {
        name = PLUGIN_NAME,
        route = { id = route1.id },
        config = {
            svc_jwt_token = "coding-kong-token",
        },
      }

      bp.plugins:insert {
        name = "key-auth",
        route = { id = route1.id}
      }
      local consumer = bp.consumers:insert {
        username = "anonymous"
      }
      consumer_id = consumer.id
      consumer_name = consumer.username
      
      bp.keyauth_credentials:insert {
        key      = "kong",
        consumer = { id = consumer.id },
      }

      -- start kong
      assert(helpers.start_kong({
        -- set the strategy
        database   = strategy,
        -- use the custom test template to create a local mock server
        nginx_conf = "spec/fixtures/custom_nginx.template",
        -- make sure our plugin gets loaded
        plugins = "bundled," .. PLUGIN_NAME,
      }))
    end)

    lazy_teardown(function()
      helpers.stop_kong(nil, true)
    end)

    before_each(function()
      client = helpers.proxy_client()
    end)

    after_each(function()
      if client then client:close() end
    end)

    describe("request", function()
      it("check response status", function()
        local r = client:get("/request", {
          headers = {
            host = "token.com",
            apikey = "kong",    -- this will get nick authenticated
          }
        })
        assert.response(r).has.status(200)
      end)
    end)
  end)
  -- some code...

Gitlab CI

Hi there!

I want to run plugin tests in Gitlab CI. My question is: Is it possible to run kong-pongo in Gitlab runner with Docker socket binding configuration (as described here)

CI job which I want to run kong-pongo script is docker container executed by Docker runner with following arguments:

docker run -v /var/run/docker.sock:/var/run/docker.sock -it docker:compose

There is problem because checkouted plugin repository is inside docker container and docker engine is running in host (Gitlab runner). Then I get following error message:

/kong-plugin # pongo run
Creating kong-pongo_kong_run ... done
Error response from daemon: Mounts denied: 
The path /kong-plugin is not shared from the host and is not known to Docker.
You can configure shared paths from Docker -> Preferences... -> Resources -> File Sharing.
See https://docs.docker.com/docker-for-mac for more info.

Regards,

Jan

running tests against custom plugins with dao

Not sure if this is the right forum to post, please redirect if not.

I have a custom plugin with a dao defined. I would like to run tests against it by inserting some values, similar to what's happening here.
I could not find any documentation or example that seemed to do so for custom plugins. The blueprint defined in fixtures has pre-defined dao objects. Can I add a custom dao object to this blueprint? If yes, how?

New variables like KONG_IMAGE for other dependencies

Pulling images from the docker hub is not possible in all places (our ci/cd can only pull images from the private registry). setting a variable for the other dependencies like Postgres, Cassandra, etc will fix this issue.

Add support to specify different nightly images

Currently, pongo supports only a single CE nightly (kong latest) and EE (master) for nightly testing. I would be useful to add the support to specify nightly image since we have multiple active nightlies, like ee 2.3-nightly and 2.4-nightly.

Running pongo as non-root

I would like to be able to run pongo as a non-root user but it seems to generally run into problems creating directories.
This is a bit of a problem for us in CI (any ci that doesn't use container based runners) as it tests to leave files + directories on the host that are owned by root and can't be removed.

This basically requires a human to ssh onto the build boxes and manually remove files.

I think (I haven't tried) one can get around this by running clean up steps

pongo rm -rf /kong-plugin/serveroot
pongo rm -rf /kong-plugin/<test reports>

But even that doesn't always work.

Work-arounds are ok for a bit, but we really don't want to be running things as a root user anywhere, even if in a container.

Pull kong/kong, Dockerfile RUN command ERROR

when pull kong/kong, I got this problem, and I don't know how to locate the problem and solve it

Step 13/18 : RUN make dependencies
 ---> Running in 235588261d86
make: *** No rule to make target 'dependencies'.  Stop.
The command '/bin/sh -c make dependencies' returned a non-zero code: 2
[pongo-ERROR] Error: failed to build test environment

Incorrect KONG_PG_HOST resolution

Issue
When developing plugins using kong-pongo and cloning even a https://github.com/Kong/kong-plugin.git it's impossible to run tests with pongo run in Linux systems (details below).
Run command simply fails with:

[----------] Running tests from /kong-plugin/spec/myplugin/02-integration_spec.lua
./spec/helpers.lua:194: [PostgreSQL error] failed to retrieve PostgreSQL server_version_num: host or service not provided, or not known

above error fails on db connector initiation

Root cause
In docker-compose.yml kong is starting with KONG_PG_HOST=${SERVICE_NETWORK_NAME}_postgres_1.${SERVICE_NETWORK_NAME}, which relies on SERVICE_NETWORK_NAME.
Unfortunately this way of building PG hostname seems to be inconsistent and postgres image that is started has different network aliases (on my PC):

## From docker inspect <postgres container>
"Networks": {
                "pongo-b4a16ef9": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "pongo-b4a16ef9-postgres-1",
                        "postgres",
                        "4e04f8f1cb22"
                    ],
                    "NetworkID": "7cf615e6a60c43ca2f5d736a89a66cfe3224788495afd9ac6ee4c7feaf85d6c4",
                    "EndpointID": "521cb698afbb52fba452668a5afd5d97cc379c7a8a523af3c400a9666742c932",
                    "Gateway": "172.19.0.1",
                    "IPAddress": "172.19.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:13:00:02",
                    "DriverOpts": null
                }
            }

As you can see usual compose things like _1.networkname sometimes do not apply, which result in slightly different hostname of PG container.

Proposed fix
The easiest of the bunch is setting an env variable, which would force an alias for PG container and KONG_PG_HOST env variable, removing the issue altogether. Default value can be still calculated (if no env variable was passed) by pongo executable before actual docker-compose runs.

System info

OS: Arch Linux x86_64 
Kernel: 5.16.9-arch1-1 
Shell: bash 5.1.16 
DE: Plasma 5.24.1 
WM: KWin 
Terminal: yakuake 
Docker version: 20.10.12, build e91ed5707e

If any extra info is required, just ask me to add it

Deprecated plugin warning when using Pongo to test custom plugins -- need help in eliminating the dependency.

(I am opening this issue on behalf of an enterprise customer)

EE 1.5.0.4

While running pongo on some custom plugins developed internally, we received the following warning for each plugin's spec:

[lua] plugins.lua:231: load_plugin(): plugin 'route-by-header' has been deprecated, context: ngx.timer

Note: all our test cases passed, but we do not wish to incur additional technical debt associated with this deprecation, provided we can remediate it at this time.

I'm looking for some suggestions on how to debug the introduction of this dependency into the code tree so that I can understand how to eliminate it.

skip enterprise ci tests when secrets are unavailable

Secrets are unavailable when PR's are submitted by external contributors (source of the PR is outside the Kong organization). This will make any CI jobs against an Enterprise version fail because it needs the secrets to pull the image and license.

Internal slack discussion:

colin 9:27 PM
how shall we deal with community users getting enterprise failures cc @thijs Schreijer (Tieske)
https://travis-ci.com/github/Kong/kong-plugin-proxy-cache/jobs/359015970
travis-ci.comtravis-ci.com

9:27
considering just an exit 0 if NIGHTLY_EE_APIKEY isn't set :think:

Thijs Schreijer (Tieske) 10:12 PM
been wondering about that as well. There is no clean solution. I think we can tst for an external repo in Travis, and only in those cases skip Enterprise tests

Thijs Schreijer (Tieske) 10:17 PM
hmmm, both approaches won’t work, since they would both also skip the CE tests jobs
New

colin 10:23 PM
image.png
image.png

10:24
somewhere around
if [[ ! $? -eq 0 ]]; then
docker logout $NIGHTLY_EE_DOCKER_REPO
err "
Failed to log into the nightly Kong Enterprise docker repo. Make sure to provide the
proper credentials in the $NIGHTLY_EE_USER and $NIGHTLY_EE_APIKEY environment variables."
fi
docker pull $image
if [[ ! $? -eq 0 ]]; then
docker logout $NIGHTLY_EE_DOCKER_REPO
err "failed to pull: $image"
fi
instead of err giving a non zero exit code if that env is false exit 0?

Thijs Schreijer (Tieske) 10:28 PM
yeah, was looking at the same page

10:28
but using that would tie Pongo to Travis, which I do not like

10:32
maybe wrap it in a Pongo variable in .travis.yml;
PONGO_SECRETS_AVAILABLE=$TRAVIS_SECURE_ENV_VARS
if it is set to false we skip any login, and exit 0 with a notice/warning. On any other value we just continue.

10:35
maybe check for both variables, so it works ootb with Travis, and allows PONGO_SECRETS_AVAILABLE to be used in other enviornments

colin 10:35 PM
that seems sensible at first blush :think:

Thijs Schreijer (Tieske) 10:35 PM
That would also prevent us from having to update all the repo’s by adding the variable to the .travis.yml file

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.