Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI tests #10

Merged
merged 12 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .ci/check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash -ex

gofmt -d -s .
./scripts/verify-codegen.sh
golint -set_exit_status $(go list ./...)
go vet .
go test ./...
65 changes: 65 additions & 0 deletions .ci/setup_kong.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash

set -e

KONG_IMAGE=${KONG_IMAGE}
NETWORK_NAME=deck-test

PG_CONTAINER_NAME=pg
DATABASE_USER=kong
DATABASE_NAME=kong
KONG_DB_PASSWORD=kong
KONG_PG_HOST=pg

GATEWAY_CONTAINER_NAME=kong

waitContainer() {
for try in {1..100}; do
echo "waiting for $1.."
nc localhost $2 && break;
sleep $3
done
}

# create docker network
docker network create $NETWORK_NAME

# Start a PostgreSQL container
docker run --rm -d --name $PG_CONTAINER_NAME \
--network=$NETWORK_NAME \
-p 5432:5432 \
-e "POSTGRES_USER=$DATABASE_USER" \
-e "POSTGRES_DB=$DATABASE_NAME" \
-e "POSTGRES_PASSWORD=$KONG_DB_PASSWORD" \
postgres:9.6

waitContainer "PostgreSQL" 8001 0.2

# Prepare the Kong database
docker run --rm --network=$NETWORK_NAME \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=$KONG_PG_HOST" \
-e "KONG_PG_PASSWORD=$KONG_DB_PASSWORD" \
-e "KONG_PASSWORD=$KONG_DB_PASSWORD" \
$KONG_IMAGE kong migrations bootstrap

# Start Kong Gateway
docker run -d --name $GATEWAY_CONTAINER_NAME \
--network=$NETWORK_NAME \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=$KONG_PG_HOST" \
-e "KONG_PG_USER=$DATABASE_USER" \
-e "KONG_PG_PASSWORD=$KONG_DB_PASSWORD" \
-e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \
-e "KONG_PROXY_ACCESS_LOG=/dev/stdout" \
-e "KONG_ADMIN_ACCESS_LOG=/dev/stdout" \
-e "KONG_PROXY_ERROR_LOG=/dev/stderr" \
-e "KONG_ADMIN_ERROR_LOG=/dev/stderr" \
-e "KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl" \
-p 8000:8000 \
-p 8443:8443 \
-p 127.0.0.1:8001:8001 \
-p 127.0.0.1:8444:8444 \
$KONG_IMAGE

waitContainer "Kong" 8001 0.2
129 changes: 129 additions & 0 deletions .ci/setup_kong_ee.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#!/bin/bash

set -e

MY_SECRET_CERT='''-----BEGIN CERTIFICATE-----
MIIEczCCAlugAwIBAgIJAMw8/GAiHIFBMA0GCSqGSIb3DQEBCwUAMDYxCzAJBgNV
BAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRIwEAYDVQQDDAlsb2NhbGhvc3Qw
HhcNMjIxMDA0MTg1MjI5WhcNMjcxMDAzMTg1MjI5WjA2MQswCQYDVQQGEwJVUzET
MBEGA1UECAwKQ2FsaWZvcm5pYTESMBAGA1UEAwwJbG9jYWxob3N0MIIBIjANBgkq
hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3LUv6RauFfFn4a2BNSTE5oQNhASBh2Lk
0Gd0tfPcmTzJbohFwyAGskYj0NBRxnRVZdLPeoZIQyYSaiPWyeDITnXyKk3Nh9Zk
xQ03YsbZCk9jIsp78/ECdnYCCS4dpYGswu8b37dxUta+6AhEEte73ezrAhc+ZIy5
2yjcix4P5+vfhBf0EzBT8D7z+wZjji3F/A969EqphFwPz3KudkTOR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+bKNS3lVLeUvYu4udmzrY74idAoGBAJ/8zQ9mZWNZwJxKXmdC
qOsKcc6Vx46gG1dzID9wzs8xjNKylX2oS9bkhpl2elbH1trUNfyOeCZz3BH+KVGt
QimdG+nKtx+lqWYbiOfz1/cYvIPR9j11r7KrYNEm+jPs2gm3cSC31IvMKbXJjSJV
PHycXK1oJWcQgGXsWfenUOBhAoGBAKezvRa9Z04h/2A7ZWbNuCGosWHdD/pmvit/
Ggy29q54sQ8Yhz39l109Xpwq1GyvYCJUj6FULe7gIo8yyat9Y83l3ZbGt4vXq/Y8
fy+n2RMcOaE3iWywMyczYtQr45gyPYT73OzAx93bJ0l7MvEEb/jAklWS5r6lgOR/
SumVayN5AoGBALLaG16NDrV2L3u/xzxw7uy5b3prpEi4wgZd4i72XaK+dMqtNVYy
KlBs7O9y+fc4AIIn6JD+9tymB1TWEn1B+3Vv6jmtzbztuCQTbJ6rTT3CFcE6TdyJ
8rYuG3/p2VkcG29TWbQARtj5ewv9p5QNfaecUzN+tps89YzawWQBanwI
-----END RSA PRIVATE KEY-----'''

KONG_IMAGE=${KONG_IMAGE}
NETWORK_NAME=deck-test

PG_CONTAINER_NAME=pg
DATABASE_USER=kong
DATABASE_NAME=kong
KONG_DB_PASSWORD=kong
KONG_PG_HOST=pg

GATEWAY_CONTAINER_NAME=kong

# create docker network
docker network create $NETWORK_NAME

waitContainer() {
for try in {1..100}; do
echo "waiting for $1.."
nc localhost $2 && break;
sleep $3
done
}

# Start a PostgreSQL container
docker run --rm -d --name $PG_CONTAINER_NAME \
--network=$NETWORK_NAME \
-p 5432:5432 \
-e "POSTGRES_USER=$DATABASE_USER" \
-e "POSTGRES_DB=$DATABASE_NAME" \
-e "POSTGRES_PASSWORD=$KONG_DB_PASSWORD" \
postgres:9.6

waitContainer "PostgreSQL" 5432 0.2

# Prepare the Kong database
docker run --rm --network=$NETWORK_NAME \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=$KONG_PG_HOST" \
-e "KONG_PG_PASSWORD=$KONG_DB_PASSWORD" \
-e "KONG_PASSWORD=$KONG_DB_PASSWORD" \
-e "KONG_LICENSE_DATA=$KONG_LICENSE_DATA" \
$KONG_IMAGE kong migrations bootstrap

# Start Kong Gateway EE
docker run -d --name $GATEWAY_CONTAINER_NAME \
--network=$NETWORK_NAME \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=$KONG_PG_HOST" \
-e "KONG_PG_USER=$DATABASE_USER" \
-e "KONG_PG_PASSWORD=$KONG_DB_PASSWORD" \
-e "KONG_PROXY_ACCESS_LOG=/dev/stdout" \
-e "KONG_ADMIN_ACCESS_LOG=/dev/stdout" \
-e "KONG_PROXY_ERROR_LOG=/dev/stderr" \
-e "KONG_ADMIN_ERROR_LOG=/dev/stderr" \
-e "KONG_ADMIN_LISTEN=0.0.0.0:8001" \
-e "KONG_PORTAL_GUI_URI=127.0.0.1:8003" \
-e "KONG_ADMIN_GUI_URL=http://127.0.0.1:8002" \
-e "KONG_LICENSE_DATA=$KONG_LICENSE_DATA" \
-e "MY_SECRET_CERT=$MY_SECRET_CERT" \
-e "MY_SECRET_KEY=$MY_SECRET_KEY" \
-p 8000:8000 \
-p 8443:8443 \
-p 8001:8001 \
-p 8444:8444 \
-p 8002:8002 \
-p 8445:8445 \
-p 8003:8003 \
-p 8004:8004 \
$KONG_IMAGE

waitContainer "Kong" 8001 0.2
62 changes: 62 additions & 0 deletions .github/workflows/integration-enterprise.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Enterprise Integration Test

concurrency:
# Run only for most recent commit in PRs but for all tags and commits on main
# Ref: https://docs.github.com/en/actions/using-jobs/using-concurrency
group: ${{ github.workflow }}-${{ github.head_ref || github.sha }}
cancel-in-progress: true

on:
push:
branches:
- main
pull_request: {}

jobs:
integration:
strategy:
matrix:
kong_image:
- 'kong/kong-gateway:1.5.0.11'
- 'kong/kong-gateway:2.1.4.6'
- 'kong/kong-gateway:2.2.1.3'
- 'kong/kong-gateway:2.3.3.4'
- 'kong/kong-gateway:2.4.1.3'
- 'kong/kong-gateway:2.5.1.2'
- 'kong/kong-gateway:2.6.0.2'
- 'kong/kong-gateway:2.7'
- 'kong/kong-gateway:2.8'
- 'kong/kong-gateway:3.0'
- 'kong/kong-gateway:3.1'
- 'kong/kong-gateway:3.2'
- 'kong/kong-gateway:3.3'
- 'kong/kong-gateway-dev:latest'
env:
KONG_ANONYMOUS_REPORTS: "off"
KONG_IMAGE: ${{ matrix.kong_image }}

runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v4
with:
go-version: '^1.20'
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{secrets.DOCKERHUB_PULL_USERNAME}}
password: ${{secrets.DOCKERHUB_PULL_TOKEN}}
- uses: Kong/kong-license@master
id: license
with:
password: ${{ secrets.PULP_PASSWORD }}
- name: Setup Kong
env:
KONG_LICENSE_DATA: ${{ steps.license.outputs.license }}
run: make setup-kong-ee
- name: Run integration tests
env:
KONG_LICENSE_DATA: ${{ steps.license.outputs.license }}
run: make test-integration
51 changes: 51 additions & 0 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Integration Test
rainest marked this conversation as resolved.
Show resolved Hide resolved

concurrency:
# Run only for most recent commit in PRs but for all tags and commits on main
# Ref: https://docs.github.com/en/actions/using-jobs/using-concurrency
group: ${{ github.workflow }}-${{ github.head_ref || github.sha }}
cancel-in-progress: true

on:
push:
branches:
- main
pull_request:
- *

jobs:
integration:
strategy:
matrix:
kong_image:
- 'kong:1.4.3'
- 'kong:1.5.1'
- 'kong:2.0.5'
- 'kong:2.1.4'
- 'kong:2.2.2'
- 'kong:2.3.3'
- 'kong:2.4.1'
- 'kong:2.5.1'
- 'kong:2.6.0'
- 'kong:2.7'
- 'kong:2.8'
- 'kong:3.0'
- 'kong:3.1'
- 'kong:3.2'
- 'kong:3.3'
rainest marked this conversation as resolved.
Show resolved Hide resolved
- 'kong/kong:master-alpine'
env:
KONG_ANONYMOUS_REPORTS: "off"
KONG_IMAGE: ${{ matrix.kong_image }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v4
with:
go-version: '^1.20'
- name: Setup Kong
run: make setup-kong
- name: Run integration tests
run: make test-integration
37 changes: 37 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CI Test

concurrency:
# Run only for most recent commit in PRs but for all tags and commits on main
# Ref: https://docs.github.com/en/actions/using-jobs/using-concurrency
group: ${{ github.workflow }}-${{ github.head_ref || github.sha }}
cancel-in-progress: true

on:
push:
branches:
- main
pull_request:
- *

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v4
with:
go-version: '^1.20'
- name: Setup golangci-lint
uses: golangci/[email protected]
- name: Run tests with Coverage
run: make coverage
- name: Upload Code Coverage
uses: codecov/codecov-action@v3
with:
name: codecov
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
- name: Build
run: make build
Loading