|
| 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`). |
0 commit comments