Building Kong - linux-on-ibm-z/docs GitHub Wiki

Building Kong

The instructions provided below specify the steps to build Kong version 3.9.1 on Linux on IBM Z for following distributions:

  • RHEL (8.10, 9.4, 9.6)
  • Ubuntu (22.04, 24.04, 25.04)

General Notes:

  • When following the steps below please use a standard permission user unless otherwise specified.
  • A directory /<source_root>/ will be referred to in these instructions, this is a temporary writable directory anywhere you'd like to place it.

1. Build using script

If you want to build Kong using manual steps, go to STEP 2.

Use the following commands to build Kong using the build script. Please make sure you have wget installed.

Note: Use a Personal Access Token. This token does not need to have any other permission than Public Repositories (read-only), and set it as GITHUB_TOKEN environment variable.

export GITHUB_TOKEN=<token>

wget -q https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/Kong/3.9.1/build_kong.sh

# Build Kong
bash build_kong.sh [Provide -t option for executing build with tests]

If the build completes successfully, go to STEP 6. In case of error, check logs for more details or go to STEP 2 to follow manual build steps.

2. Install the system dependencies

export SOURCE_ROOT=/<source_root>/
export PATCH_URL=https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/Kong/3.9.1/patch

export GITHUB_TOKEN=<token> 
  • RHEL (8.10, 9.4, 9.6)

    sudo yum install -y automake gcc gcc-c++ git libyaml-devel cmake make patch perl perl-IPC-Cmd protobuf-devel unzip java-21-openjdk-devel valgrind valgrind-devel zlib-devel zip
    
  • Ubuntu (22.04, 24.04, 25.04)

    sudo apt-get update
    sudo apt-get install -y automake build-essential curl wget openjdk-21-jdk file git libyaml-dev libprotobuf-dev m4 perl pkg-config procps unzip valgrind zlib1g-dev libyaml-dev cmake zip

3. Install prerequisites

3.1. Install Go

cd $SOURCE_ROOT
GO_VERSION=1.24.0
wget -q https://storage.googleapis.com/golang/go"${GO_VERSION}".linux-s390x.tar.gz
chmod ugo+r go"${GO_VERSION}".linux-s390x.tar.gz
sudo tar -C /usr/local -xzf go"${GO_VERSION}".linux-s390x.tar.gz
export PATH=$PATH:/usr/local/go/bin
go version

3.2. Build bazel

cd $SOURCE_ROOT
mkdir bazel && cd bazel
wget https://github.com/bazelbuild/bazel/releases/download/7.3.1/bazel-7.3.1-dist.zip
unzip bazel-7.3.1-dist.zip
chmod -R +w .
env EXTRA_BAZEL_ARGS="--tool_java_runtime_version=local_jdk" bash ./compile.sh
sudo cp $SOURCE_ROOT/bazel/output/bazel /usr/local/bin/bazel

3.3. Build rust and rules_rust

#install rust
cd $SOURCE_ROOT
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh /dev/stdin -y
export PATH="$HOME/.cargo/bin:$PATH"

#build rust_rules
cd $SOURCE_ROOT
git clone --depth 1 -b 0.56.0 https://github.com/bazelbuild/rules_rust.git
cd $SOURCE_ROOT/rules_rust/crate_universe
cargo build --bin=cargo-bazel
export CARGO_BAZEL_GENERATOR_URL=file://$(pwd)/target/debug/cargo-bazel
export CARGO_BAZEL_REPIN=true

3.4. Install gh and login

mkdir -p $SOURCE_ROOT/gh_repo/bin
cd $SOURCE_ROOT/gh_repo
git clone -b v2.45.0 https://github.com/cli/cli.git
cd cli
make bin/gh
cp ./bin/gh $SOURCE_ROOT/gh_repo/bin/gh
export PATH=$SOURCE_ROOT/gh_repo/bin:$PATH
cd $SOURCE_ROOT/gh_repo

tee BUILD.bazel <<EOF
filegroup(
    name = "gh",
    srcs = ["../gh_repo/gh"],
    visibility = ["//visibility:public"],
)
EOF
tee WORKSPACE <<EOF
filegroup(
    name = "gh",
    srcs = ["../gh_repo/gh"],
    visibility = ["//visibility:public"],
)
EOF

4. Build Kong

4.1. Build Kong from source

cd $SOURCE_ROOT
git clone -b 3.9.1 https://github.com/Kong/kong.git
cd kong
curl -sSL ${PATCH_URL}/kong.diff | git apply - || echo "Error: patch failed."
make build-venv
make build-kong

5. Run Kong tests (Optional)

5.1. Install docker

  • Docker packages for RHEL and Ubuntu can be installed by following the instructions here.

  • Ensure the current user belongs to group docker.

    Use the below command to add group docker if it does not exist:

    sudo groupadd docker

    Use the below command to add current user to group docker if it has not been done:

    sudo usermod -aG docker $USER && newgrp docker

5.2. Build grpcbin image

cd $SOURCE_ROOT
git clone -b v1.0.9 https://github.com/kong/grpcbin.git
cd grpcbin
docker build -t kong/grpcbin:latest .

5.3. Run tests

cd $SOURCE_ROOT
sudo apt install -y libssl-dev #only for ubuntu
sudo yum install -y openssl-devel #only for RHEL

git clone -b v0.4.4 https://github.com/Kong/h2client.git
cd h2client
go build -o h2client
mkdir -p $SOURCE_ROOT/kong/bin
cp h2client $SOURCE_ROOT/kong/bin/
chmod +x $SOURCE_ROOT/kong/bin/h2client

cd $SOURCE_ROOT/kong
. bazel-bin/build/kong-dev-venv.sh
kong version
start_services
kong migrations bootstrap
make dev
make test

Note: spec/01-unit/03-conf_loader_spec.lua test case fails on intel as well.

6. Verify by Starting Kong (Optional)

cd $SOURCE_ROOT/kong
kong start

References:

⚠️ **GitHub.com Fallback** ⚠️