Skip to content

Commit a63c179

Browse files
committed
init
0 parents  commit a63c179

File tree

14 files changed

+488
-0
lines changed

14 files changed

+488
-0
lines changed

.github/workflows/cicd.yaml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: apisix-adc-cicd
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
build-and-publish:
14+
runs-on: ubuntu-latest
15+
env:
16+
# Demo only: plaintext values for simplicity. Do NOT use in production.
17+
# Set this to your public VM address so GitHub Actions can reach APISIX Admin API.
18+
# In Production environments, use secrets to inject these values securely.
19+
APISIX_ADMIN_API: "http://68.183.178.88:9180"
20+
# Demo admin key; replace if you change APISIX admin_key in config.
21+
APISIX_ADMIN_KEY: "edd1c9f034335f136f87ad84b625c8f1"
22+
ADC_VERSION: "0.21.2"
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Show environment
28+
run: |
29+
echo "APISIX_ADMIN_API=${APISIX_ADMIN_API}"
30+
echo "adc version (if present):" || true
31+
(adc --version || true)
32+
33+
- name: Install ADC CLI
34+
run: |
35+
set -euxo pipefail
36+
arch="$(uname -m)"
37+
case "${arch}" in
38+
x86_64|amd64) adc_arch="amd64" ;;
39+
arm64|aarch64) adc_arch="arm64" ;;
40+
*)
41+
echo "Unsupported architecture: ${arch}" >&2
42+
exit 1
43+
;;
44+
esac
45+
url="https://github.com/api7/adc/releases/download/v${ADC_VERSION}/adc_${ADC_VERSION}_linux_${adc_arch}.tar.gz"
46+
curl -sSL -o adc.tar.gz "${url}"
47+
tar -xzf adc.tar.gz
48+
install_dir="${HOME}/.local/bin"
49+
mkdir -p "${install_dir}"
50+
install -m 0755 adc "${install_dir}/adc"
51+
echo "${install_dir}" >> "${GITHUB_PATH}"
52+
adc --version
53+
54+
- name: Render OpenAPI -> APISIX config
55+
id: render
56+
run: |
57+
bash scripts/adc_render.sh
58+
59+
- name: Upload rendered artifact (if any)
60+
if: always()
61+
uses: actions/upload-artifact@v4
62+
with:
63+
name: apisix-config
64+
path: dist/
65+
if-no-files-found: ignore
66+
67+
- name: Publish to APISIX via Admin API/ADC
68+
env:
69+
APISIX_ADMIN_API: ${{ env.APISIX_ADMIN_API }}
70+
APISIX_ADMIN_KEY: ${{ env.APISIX_ADMIN_KEY }}
71+
run: |
72+
if [ -z "${APISIX_ADMIN_API}" ] || [ -z "${APISIX_ADMIN_KEY}" ]; then
73+
echo "APISIX_ADMIN_API / APISIX_ADMIN_KEY envs are required (demo uses plaintext)" >&2
74+
exit 1
75+
fi
76+
bash scripts/adc_publish.sh

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist/
2+
.DS_Store

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.PHONY: up down logs render publish seed
2+
3+
up:
4+
docker compose up -d
5+
6+
down:
7+
docker compose down
8+
9+
logs:
10+
docker compose logs -f apisix
11+
12+
render:
13+
bash scripts/adc_render.sh
14+
15+
publish:
16+
bash scripts/adc_publish.sh
17+
18+
seed:
19+
bash scripts/bootstrap_routes_via_admin.sh

README.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# APISIX + etcd + ADC + GitHub Actions + OpenAPI Demo
2+
3+
This repository provides a runnable demo featuring:
4+
5+
- APISIX Gateway + etcd via Docker Compose
6+
- OpenAPI (httpbin example) with APISIX/ADC annotations
7+
- ADC CLI to generate and publish APISIX configuration
8+
- GitHub Actions for CI/CD
9+
10+
Note: This demo routes to a local `httpbin` container by default for offline use. You can optionally switch to the public `httpbin.org`.
11+
12+
## Quickstart (Local)
13+
14+
Prerequisites: Docker 20+, Docker Compose, curl.
15+
16+
- Start APISIX + etcd + httpbin:
17+
- `docker compose up -d`
18+
- Wait 10–20s for APISIX to be ready
19+
- Verify Admin API (optional):
20+
- `curl -s http://localhost:9180/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' | head`
21+
- Seed routes without ADC (admin API demo):
22+
- `bash scripts/bootstrap_routes_via_admin.sh`
23+
- Test traffic through APISIX:
24+
- `curl -i http://localhost:9080/get`
25+
- `curl -i http://localhost:9080/status/201`
26+
- `curl -i -X POST http://localhost:9080/anything -d 'hello=apisix'`
27+
28+
When ADC CLI is ready, use `make render` to produce APISIX config and `make publish` to deploy it (see below).
29+
30+
## OpenAPI + ADC annotations
31+
32+
- See `openapi/httpbin.yaml`, including `/get`, `/status/{code}`, `/anything`.
33+
- The first `servers` entry defines upstream nodes (`httpbin:8080` for local compose).
34+
- `x-adc-*` per operation guides ADC resource generation:
35+
- `x-adc-name`: route name override (`httpbin_get`, etc.)
36+
- `x-adc-plugins`: enable plugins (e.g., `cors`)
37+
38+
## Use ADC (Local)
39+
40+
- Install ADC CLI (see https://github.com/api7/adc)
41+
- Render:
42+
- `make render`
43+
- Output: `dist/apisix.yaml`
44+
- Publish (requires Admin API key below):
45+
- `make publish`
46+
47+
Notes:
48+
- This repo assumes `adc` is available in PATH.
49+
- ADC verbs vary by version. Scripts attempt common ones and will guide you if adjustment is needed. For ADC 0.21.2, the script first tries `adc convert openapi`; if unavailable it falls back to historical verbs (`adc openapi generate`, `adc generate`, `adc render`, `adc compile`).
50+
51+
## GitHub Actions (CI/CD)
52+
53+
- Workflow: `.github/workflows/cicd.yaml`
54+
- Triggers: push to `main` or PR
55+
- Steps:
56+
- Install ADC CLI (GitHub Actions downloads v0.21.2 release binary)
57+
- Validate and render OpenAPI → APISIX config
58+
- Publish to APISIX Admin API
59+
Environment in workflow (demo only):
60+
- The workflow uses plaintext env vars for simplicity:
61+
- `APISIX_ADMIN_API`: e.g., `http://YOUR_PUBLIC_VM:9180`
62+
- `APISIX_ADMIN_KEY`: demo `edd1c9f034335f136f87ad84b625c8f1`
63+
- This is for demo purposes only. For production, use GitHub Secrets.
64+
65+
## Switch to httpbin.org (Optional)
66+
67+
If outbound network is allowed and you prefer public `httpbin.org`:
68+
69+
1. Edit `openapi/httpbin.yaml`, update the first `servers` entry to `https://httpbin.org` (or your upstream).
70+
2. Add/adjust `x-adc-plugins` as needed (e.g., `proxy-rewrite` to set `host: httpbin.org`).
71+
3. Re-run `make render` and publish.
72+
73+
## APISIX/etcd Configuration
74+
75+
- `docker-compose.yml` runs `etcd`, `apisix`, `httpbin` containers (no persistent volumes)
76+
- APISIX config: stored in `apisix/conf/config.yaml` and mounted read-only into the APISIX container via Compose
77+
- etcd: `http://etcd:2379`
78+
- Admin API: `9180`
79+
- Gateway ports: `9080` (HTTP), `9443` (HTTPS)
80+
- Admin Key (demo only): `edd1c9f034335f136f87ad84b625c8f1`
81+
- APISIX image: `apache/apisix:3.14.1-ubuntu`
82+
83+
## Useful Commands
84+
85+
- `make up`: start all services
86+
- `docker compose logs -f apisix`: tail APISIX logs
87+
- `make render`: generate APISIX config using ADC
88+
- `make publish`: publish config to APISIX Admin API
89+
- `bash scripts/bootstrap_routes_via_admin.sh`: seed routes via Admin API (no ADC)
90+
- `make down`: stop containers (no persistent volumes)
91+
92+
## Running on a Public VM
93+
94+
- Point GitHub Actions to your VM by editing `.github/workflows/cicd.yaml` env:
95+
- `APISIX_ADMIN_API: "http://YOUR_PUBLIC_VM:9180"`
96+
- Ensure your VM firewall/security group allows inbound TCP 9180 from GitHub Actions runners (demo only). For production, restrict sources and rotate the admin key.
97+
98+
## Layout
99+
100+
- `docker-compose.yml`: containers orchestration
101+
- `apisix/conf/config.yaml`: APISIX config mounted by Compose
102+
- `openapi/httpbin.yaml`: OpenAPI with x-adc hints for ADC
103+
- `scripts/adc_render.sh`: ADC render script (auto-detect verbs)
104+
- `scripts/adc_publish.sh`: ADC publish/apply/sync script (auto-detect verbs)
105+
- `scripts/bootstrap_routes_via_admin.sh`: seed APISIX resources via Admin API
106+
- `apisix/admin_payloads/*.json`: Admin API payload examples
107+
- `.github/workflows/cicd.yaml`: CI/CD workflow
108+
- `Makefile`: helper targets
109+
110+
If you want me to pin scripts/workflow exactly to your ADC 0.21.2 verbs, I can adjust commands precisely once you confirm the exact subcommands you use locally (e.g., `adc openapi generate`).
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"uri": "/anything",
3+
"name": "httpbin_anything",
4+
"desc": "POST /anything via APISIX",
5+
"upstream_id": "httpbin_upstream",
6+
"methods": ["POST"],
7+
"plugins": {
8+
"cors": {}
9+
}
10+
}
11+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"uri": "/get",
3+
"name": "httpbin_get",
4+
"desc": "GET /get via APISIX",
5+
"upstream_id": "httpbin_upstream",
6+
"methods": ["GET"],
7+
"plugins": {
8+
"cors": {}
9+
}
10+
}
11+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"uri": "/status/*",
3+
"name": "httpbin_status",
4+
"desc": "GET /status/{code} via APISIX",
5+
"upstream_id": "httpbin_upstream",
6+
"methods": ["GET"],
7+
"plugins": {
8+
"cors": {}
9+
}
10+
}
11+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"type": "roundrobin",
3+
"scheme": "http",
4+
"nodes": {
5+
"httpbin:8080": 1
6+
},
7+
"pass_host": "pass",
8+
"name": "httpbin_upstream",
9+
"desc": "Local httpbin upstream"
10+
}

apisix/conf/config.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
deployment:
2+
role: traditional
3+
role_traditional:
4+
config_provider: etcd
5+
admin:
6+
# Demo only: open to all. Narrow CIDR in production.
7+
allow_admin:
8+
- 0.0.0.0/0
9+
admin_key:
10+
- name: admin
11+
key: edd1c9f034335f136f87ad84b625c8f1
12+
role: admin
13+
- name: "viewer"
14+
key: 4054f7cf07e344346cd3f287985e76a2
15+
role: viewer
16+
etcd:
17+
host:
18+
- "http://etcd:2379"
19+
prefix: "/apisix"
20+
timeout: 30
21+
apisix:
22+
node_listen: 9080
23+
enable_admin: true
24+
ssl:
25+
enable: true
26+
listen_port: 9443
27+
stream_plugins: []
28+
plugin_attr:
29+
prometheus:
30+
export_addr:
31+
ip: "0.0.0.0"
32+
port: 9091
33+
nginx_config:
34+
error_log: logs/error.log
35+
worker_processes: auto
36+
worker_rlimit_nofile: 20480
37+
http:
38+
access_log: logs/access.log
39+
keepalive_timeout: 60s

docker-compose.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
services:
2+
etcd:
3+
image: bitnamilegacy/etcd:3.5.15
4+
container_name: etcd
5+
environment:
6+
- ALLOW_NONE_AUTHENTICATION=yes
7+
- ETCD_ENABLE_V2=false
8+
- ETCD_ADVERTISE_CLIENT_URLS=http://etcd:2379
9+
- ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379
10+
- ETCDCTL_API=3
11+
ports:
12+
- "2379:2379"
13+
healthcheck:
14+
test: ["CMD", "etcdctl", "--endpoints=http://127.0.0.1:2379", "endpoint", "health"]
15+
interval: 5s
16+
timeout: 3s
17+
retries: 20
18+
start_period: 5s
19+
networks:
20+
- apisix
21+
22+
apisix:
23+
image: apache/apisix:3.14.1-ubuntu
24+
container_name: apisix
25+
depends_on:
26+
etcd:
27+
condition: service_healthy
28+
restart: unless-stopped
29+
ports:
30+
- "9080:9080" # APISIX HTTP
31+
- "9443:9443" # APISIX HTTPS
32+
- "9180:9180" # Admin API
33+
volumes:
34+
- ./apisix/conf/config.yaml:/usr/local/apisix/conf/config.yaml:ro
35+
networks:
36+
- apisix
37+
38+
httpbin:
39+
image: mccutchen/go-httpbin:latest
40+
container_name: httpbin
41+
expose:
42+
- "8080"
43+
ports:
44+
- "8080:8080" # Optional: access http://localhost:8080 directly
45+
networks:
46+
- apisix
47+
48+
networks:
49+
apisix:
50+
driver: bridge

0 commit comments

Comments
 (0)