Published on

How to use Gitpod to develop Apache APISIX?

Authors

Background

Use Gitpod as the Apache APISIX development and startup environment, which is convenient for new users to use, develop, and contribute.

Terminology

Apache APISIX

A new generation of API gateways under the Apache Software Foundation, watch the video What's API Gateway to learn more.

ETCD

The configuration storage center of Apache APISIX, which can be understood as a database (but not completely equivalent).

Gitpod

Developer tools running in the browser (with VS Code embedded). No need to configure the environment, deploy code in our own machines, which is easier to unify the development environment.

Steps

Register and Login GitHub.com

Please follow GitHub's Docs here.

Fork apache/apisix Repository

  1. Visit https://github.com/apache/apisix to enter the homepage of the apache/apisix project.
  2. Click the Fork button in the upper right corner to enter the following page image
  3. Click the Create fork button and wait a moment image image
  4. The fork is successful when your GitHub account name is displayed in the upper left corner
  5. Click Code -> HTTPS -> Copy (this link will be used below) image

Import project to Gitpod

  1. Visit https://www.gitpod.io/ , click Try now, and log in with GitHub
  2. Select the default option VS Code Browser and click Continue image image
  3. Click on New Workspace and paste the Repository link copied above image
  4. Click this link and go to the following page image
  5. When the following interface is displayed, it means ready (directory on the left, code editing box on the upper right, command line area on the lower right) image

Install ETCD

# Go to the parent directory of the apisix folder to install ETCD

cd ..

ETCD_VERSION='3.4.13'

wget https://github.com/etcd-io/etcd/releases/download/v${ETCD_VERSION}/etcd-v${ETCD_VERSION}-linux-amd64.tar.gz

tar -xvf etcd-v${ETCD_VERSION}-linux-amd64.tar.gz && cd etcd-v${ETCD_VERSION}-linux-amd64 && sudo cp -a etcd etcdctl /usr/bin/

nohup etcd >/tmp/etcd.log 2>&1 &

cd ../apisix

Install Dependencies

  1. See the Gitpod command line, the current default is the master branch, in this tutorial we use the 2.14.1 tag;
  2. Enter the following command in the command line and press Enter, the command line will display gitpod /workspace/apisix (2.14.1) indicating that the switch is successful;
git checkout 2.14.1
  1. If you have fork the apache/apisix repository before, please execute the following command to synchronize the latest code. Otherwise, please go directly to the next step.
git fetch --tags

git checkout 2.14.1
  1. Install dependencies and build the project: Enter the following command on the command line and press Enter
curl https://raw.githubusercontent.com/apache/apisix/master/utils/install-dependencies.sh -sL | bash -

make deps

Run apisix

Execute the following command to start apisix.

make run

Execute the following command to verify that apisix is installed and started successfully.

curl localhost:9080

# After executing the above command, the following content will be displayed, indicating that the startup is successful
# {"error_msg":"404 Route Not Found"}

Stop apisix

make stop

Rebuild the project after editing codes

make stop
make run

Submit code changes

Using the file directory panel on the left side of Gitpod, select the code you want to commit.

Advanced

If you want to operate the Apache APISIX instance through the Admin API, and create Routes, Upstreams, etc., you can continue reading below.

The Apache APISIX instance exposes the Admin API for operators to call. To avoid malicious access, you need to carry the key when calling the API. You can find the Apache APISIX default key by viewing the /conf/config.yaml file. The following is an example of calling: If you need to query the list of routes that have been created, you can access:

curl -i -X GET http://127.0.0.1:9080/apisix/admin/routes -H "X-API-KEY: edd1c9f034335f136f87ad84b625c8f1"

If the key is correct, it will return something like this:

HTTP/1.1 200 OK
Date: Thu, 19 May 2022 03:05:28 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Server: APISIX/2.14.1
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: *
Access-Control-Max-Age: 3600

# The above is the HTTP Response Header of the HTTP request, but please focus on the following: If nodes is empty, it means that no Route is currently created.
{"action":"get","count":0,"node":{"nodes":[],"key":"\/apisix\/routes","dir":true}}

Other

If you encounter any questions, please join the Slack community and ask for help.