Skip to content

Commit 9fc7822

Browse files
committed
xx
0 parents  commit 9fc7822

File tree

12 files changed

+518
-0
lines changed

12 files changed

+518
-0
lines changed

.github/workflows/cicd.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Show environment
27+
run: |
28+
echo "APISIX_ADMIN_API=${APISIX_ADMIN_API}"
29+
echo "adc version (if present):" || true
30+
(adc --version || true)
31+
32+
- name: Install ADC (example, adjust as needed)
33+
run: |
34+
echo "Install ADC here (adjust to your environment)."
35+
echo "Example: download ADC 0.21.2 binary and add to PATH."
36+
echo "Ensure 'adc' is available in PATH afterward."
37+
38+
- name: Render OpenAPI -> APISIX config
39+
id: render
40+
run: |
41+
bash scripts/adc_render.sh
42+
continue-on-error: true
43+
44+
- name: Upload rendered artifact (if any)
45+
if: always()
46+
uses: actions/upload-artifact@v4
47+
with:
48+
name: apisix-config
49+
path: dist/
50+
if-no-files-found: ignore
51+
52+
- name: Publish to APISIX via Admin API/ADC
53+
env:
54+
APISIX_ADMIN_API: ${{ env.APISIX_ADMIN_API }}
55+
APISIX_ADMIN_KEY: ${{ env.APISIX_ADMIN_KEY }}
56+
run: |
57+
if [ -z "${APISIX_ADMIN_API}" ] || [ -z "${APISIX_ADMIN_KEY}" ]; then
58+
echo "APISIX_ADMIN_API / APISIX_ADMIN_KEY envs are required (demo uses plaintext)" >&2
59+
exit 1
60+
fi
61+
bash scripts/adc_publish.sh

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: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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 + APISIX/ADC annotations
31+
32+
- See `openapi/httpbin.yaml`, including `/get`, `/status/{code}`, `/anything`.
33+
- `x-apisix-*` per operation guides ADC resource generation:
34+
- `x-apisix-upstream`: upstream nodes (`httpbin:8080`)
35+
- `x-apisix-plugins`: enable plugins (e.g., `cors`, `proxy-rewrite`)
36+
37+
## Use ADC (Local)
38+
39+
- Install ADC CLI (see https://github.com/api7/adc)
40+
- Render:
41+
- `make render`
42+
- Output: `dist/apisix.yaml`
43+
- Publish (requires Admin API key below):
44+
- `make publish`
45+
46+
Notes:
47+
- This repo assumes `adc` is available in PATH.
48+
- ADC verbs vary by version. Scripts attempt common ones and will guide you if adjustment is needed. For ADC 0.21.2, there is no `render` command; `scripts/adc_render.sh` tries `openapi generate`, `generate`, then `compile`.
49+
50+
## GitHub Actions (CI/CD)
51+
52+
- Workflow: `.github/workflows/cicd.yaml`
53+
- Triggers: push to `main` or PR
54+
- Steps:
55+
- Install/prepare ADC (adjust to your environment)
56+
- Validate and render OpenAPI → APISIX config
57+
- Publish to APISIX Admin API
58+
Environment in workflow (demo only):
59+
- The workflow uses plaintext env vars for simplicity:
60+
- `APISIX_ADMIN_API`: e.g., `http://YOUR_PUBLIC_VM:9180`
61+
- `APISIX_ADMIN_KEY`: demo `edd1c9f034335f136f87ad84b625c8f1`
62+
- This is for demo purposes only. For production, use GitHub Secrets.
63+
64+
## Switch to httpbin.org (Optional)
65+
66+
If outbound network is allowed and you prefer public `httpbin.org`:
67+
68+
1. Edit `openapi/httpbin.yaml`, set `x-apisix-upstream` to:
69+
- `nodes: { "httpbin.org:443": 1 }`
70+
- `scheme: https`
71+
- Optionally add `proxy-rewrite` with `host: httpbin.org`
72+
2. Re-run `make render` and publish.
73+
74+
## APISIX/etcd Configuration
75+
76+
- `docker-compose.yml` runs `etcd`, `apisix`, `httpbin` containers (no persistent volumes)
77+
- APISIX config: provided inline via `APISIX_CONFIG_YAML` in Compose (file `apisix/conf/config.yaml` is included as a reference, not mounted)
78+
- etcd: `http://etcd:2379`
79+
- Admin API: `9180`
80+
- Gateway ports: `9080` (HTTP), `9443` (HTTPS)
81+
- Admin Key (demo only): `edd1c9f034335f136f87ad84b625c8f1`
82+
- APISIX image: `apache/apisix:3.14.1-debian`
83+
84+
## Useful Commands
85+
86+
- `make up`: start all services
87+
- `docker compose logs -f apisix`: tail APISIX logs
88+
- `make render`: generate APISIX config using ADC
89+
- `make publish`: publish config to APISIX Admin API
90+
- `bash scripts/bootstrap_routes_via_admin.sh`: seed routes via Admin API (no ADC)
91+
- `make down`: stop containers (no persistent volumes)
92+
93+
## Running on a Public VM
94+
95+
- Point GitHub Actions to your VM by editing `.github/workflows/cicd.yaml` env:
96+
- `APISIX_ADMIN_API: "http://YOUR_PUBLIC_VM:9180"`
97+
- 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.
98+
99+
## Layout
100+
101+
- `docker-compose.yml`: containers orchestration
102+
- `apisix/conf/config.yaml`: Reference APISIX config (Compose uses inline APISIX_CONFIG_YAML)
103+
- `openapi/httpbin.yaml`: OpenAPI with x-apisix hints for ADC
104+
- `scripts/adc_render.sh`: ADC render script (auto-detect verbs)
105+
- `scripts/adc_publish.sh`: ADC publish/apply/sync script (auto-detect verbs)
106+
- `scripts/bootstrap_routes_via_admin.sh`: seed APISIX resources via Admin API
107+
- `apisix/admin_payloads/*.json`: Admin API payload examples
108+
- `.github/workflows/cicd.yaml`: CI/CD workflow
109+
- `Makefile`: helper targets
110+
111+
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+
}

docker-compose.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
ports:
11+
- "2379:2379"
12+
networks:
13+
- apisix
14+
15+
apisix:
16+
image: apache/apisix:3.14.1-ubuntu
17+
container_name: apisix
18+
depends_on:
19+
- etcd
20+
environment:
21+
APISIX_CONFIG_YAML: |
22+
deployment:
23+
role: traditional
24+
role_traditional:
25+
config_provider: etcd
26+
apisix:
27+
node_listen: 9080
28+
enable_admin: true
29+
# Demo only: open to all. Narrow CIDR in production.
30+
allow_admin:
31+
- 0.0.0.0/0
32+
admin_key:
33+
- name: admin
34+
key: edd1c9f034335f136f87ad84b625c8f1
35+
role: admin
36+
ssl:
37+
enable: true
38+
listen_port: 9443
39+
etcd:
40+
host:
41+
- "http://etcd:2379"
42+
prefix: "/apisix"
43+
timeout: 30
44+
plugins:
45+
- cors
46+
- proxy-rewrite
47+
- request-id
48+
- server-info
49+
plugin_attr: {}
50+
nginx_config:
51+
error_log: logs/error.log
52+
worker_processes: auto
53+
worker_rlimit_nofile: 20480
54+
http:
55+
access_log: logs/access.log
56+
keepalive_timeout: 60s
57+
restart: unless-stopped
58+
ports:
59+
- "9080:9080" # APISIX HTTP
60+
- "9443:9443" # APISIX HTTPS
61+
- "9180:9180" # Admin API
62+
networks:
63+
- apisix
64+
65+
httpbin:
66+
image: mccutchen/go-httpbin:latest
67+
container_name: httpbin
68+
expose:
69+
- "8080"
70+
ports:
71+
- "8080:8080" # Optional: access http://localhost:8080 directly
72+
networks:
73+
- apisix
74+
75+
networks:
76+
apisix:
77+
driver: bridge

openapi/httpbin.yaml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
openapi: 3.0.3
2+
info:
3+
title: Httpbin via APISIX
4+
description: |
5+
Demonstration of routing httpbin through APISIX. Includes x-apisix extensions for ADC to generate APISIX resources.
6+
version: 1.0.0
7+
servers:
8+
- url: http://localhost:9080
9+
description: Local APISIX Gateway
10+
11+
paths:
12+
/get:
13+
get:
14+
summary: Proxy to httpbin GET
15+
description: Returns request info from httpbin
16+
tags: [httpbin]
17+
responses:
18+
'200':
19+
description: OK
20+
x-apisix-plugins:
21+
cors: {}
22+
x-apisix-upstream:
23+
type: roundrobin
24+
scheme: http
25+
nodes:
26+
"httpbin:8080": 1
27+
28+
/status/{code}:
29+
get:
30+
summary: Return specific HTTP status code
31+
tags: [httpbin]
32+
parameters:
33+
- in: path
34+
name: code
35+
required: true
36+
schema:
37+
type: integer
38+
minimum: 100
39+
maximum: 599
40+
responses:
41+
'200':
42+
description: Example response (status code depends on path parameter)
43+
x-apisix-plugins:
44+
cors: {}
45+
x-apisix-upstream:
46+
type: roundrobin
47+
scheme: http
48+
nodes:
49+
"httpbin:8080": 1
50+
51+
/anything:
52+
post:
53+
summary: Echo any request data
54+
tags: [httpbin]
55+
requestBody:
56+
required: false
57+
content:
58+
application/json:
59+
schema:
60+
type: object
61+
application/x-www-form-urlencoded:
62+
schema:
63+
type: object
64+
responses:
65+
'200':
66+
description: OK
67+
x-apisix-plugins:
68+
cors: {}
69+
x-apisix-upstream:
70+
type: roundrobin
71+
scheme: http
72+
nodes:
73+
"httpbin:8080": 1
74+
75+
components: {}

0 commit comments

Comments
 (0)