Skip to content

Commit 3b6540c

Browse files
committed
fix
1 parent 4217e8a commit 3b6540c

File tree

6 files changed

+81
-55
lines changed

6 files changed

+81
-55
lines changed

.github/workflows/cicd.yaml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
APISIX_ADMIN_API: "http://68.183.178.88:9180"
2020
# Demo admin key; replace if you change APISIX admin_key in config.
2121
APISIX_ADMIN_KEY: "edd1c9f034335f136f87ad84b625c8f1"
22+
ADC_VERSION: "0.21.2"
2223
steps:
2324
- name: Checkout
2425
uses: actions/checkout@v4
@@ -29,17 +30,31 @@ jobs:
2930
echo "adc version (if present):" || true
3031
(adc --version || true)
3132
32-
- name: Install ADC (example, adjust as needed)
33+
- name: Install ADC CLI
3334
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."
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
3753
3854
- name: Render OpenAPI -> APISIX config
3955
id: render
4056
run: |
4157
bash scripts/adc_render.sh
42-
continue-on-error: true
4358
4459
- name: Upload rendered artifact (if any)
4560
if: always()

.gitignore

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

README.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ Prerequisites: Docker 20+, Docker Compose, curl.
2727

2828
When ADC CLI is ready, use `make render` to produce APISIX config and `make publish` to deploy it (see below).
2929

30-
## OpenAPI + APISIX/ADC annotations
30+
## OpenAPI + ADC annotations
3131

3232
- 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`)
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`)
3637

3738
## Use ADC (Local)
3839

@@ -45,14 +46,14 @@ When ADC CLI is ready, use `make render` to produce APISIX config and `make publ
4546

4647
Notes:
4748
- 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+
- 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`).
4950

5051
## GitHub Actions (CI/CD)
5152

5253
- Workflow: `.github/workflows/cicd.yaml`
5354
- Triggers: push to `main` or PR
5455
- Steps:
55-
- Install/prepare ADC (adjust to your environment)
56+
- Install ADC CLI (GitHub Actions downloads v0.21.2 release binary)
5657
- Validate and render OpenAPI → APISIX config
5758
- Publish to APISIX Admin API
5859
Environment in workflow (demo only):
@@ -65,16 +66,14 @@ Environment in workflow (demo only):
6566

6667
If outbound network is allowed and you prefer public `httpbin.org`:
6768

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.
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.
7372

7473
## APISIX/etcd Configuration
7574

7675
- `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)
76+
- APISIX config: stored in `apisix/conf/config.yaml` and mounted read-only into the APISIX container via Compose
7877
- etcd: `http://etcd:2379`
7978
- Admin API: `9180`
8079
- Gateway ports: `9080` (HTTP), `9443` (HTTPS)
@@ -99,8 +98,8 @@ If outbound network is allowed and you prefer public `httpbin.org`:
9998
## Layout
10099

101100
- `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
101+
- `apisix/conf/config.yaml`: APISIX config mounted by Compose
102+
- `openapi/httpbin.yaml`: OpenAPI with x-adc hints for ADC
104103
- `scripts/adc_render.sh`: ADC render script (auto-detect verbs)
105104
- `scripts/adc_publish.sh`: ADC publish/apply/sync script (auto-detect verbs)
106105
- `scripts/bootstrap_routes_via_admin.sh`: seed APISIX resources via Admin API

openapi/httpbin.yaml

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,32 @@ openapi: 3.0.3
22
info:
33
title: Httpbin via APISIX
44
description: |
5-
Demonstration of routing httpbin through APISIX. Includes x-apisix extensions for ADC to generate APISIX resources.
5+
Demonstration of routing httpbin through APISIX. Includes x-adc extensions for ADC to generate APISIX resources.
66
version: 1.0.0
77
servers:
8-
- url: http://localhost:9080
9-
description: Local APISIX Gateway
8+
- url: http://httpbin:8080
9+
description: Local httpbin upstream (ADC uses the first server entry to build upstream nodes)
1010

1111
paths:
1212
/get:
1313
get:
1414
summary: Proxy to httpbin GET
1515
description: Returns request info from httpbin
1616
tags: [httpbin]
17+
x-adc-name: httpbin_get
18+
x-adc-plugins:
19+
cors: {}
1720
responses:
1821
'200':
1922
description: OK
20-
x-apisix-plugins:
21-
cors: {}
22-
x-apisix-upstream:
23-
type: roundrobin
24-
scheme: http
25-
nodes:
26-
"httpbin:8080": 1
2723

2824
/status/{code}:
2925
get:
3026
summary: Return specific HTTP status code
3127
tags: [httpbin]
28+
x-adc-name: httpbin_status
29+
x-adc-plugins:
30+
cors: {}
3231
parameters:
3332
- in: path
3433
name: code
@@ -40,18 +39,14 @@ paths:
4039
responses:
4140
'200':
4241
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
5042

5143
/anything:
5244
post:
5345
summary: Echo any request data
5446
tags: [httpbin]
47+
x-adc-name: httpbin_anything
48+
x-adc-plugins:
49+
cors: {}
5550
requestBody:
5651
required: false
5752
content:
@@ -64,12 +59,5 @@ paths:
6459
responses:
6560
'200':
6661
description: OK
67-
x-apisix-plugins:
68-
cors: {}
69-
x-apisix-upstream:
70-
type: roundrobin
71-
scheme: http
72-
nodes:
73-
"httpbin:8080": 1
7462

7563
components: {}

scripts/adc_publish.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ if ! command -v adc >/dev/null 2>&1; then
2222
exec bash "${ROOT_DIR}/scripts/bootstrap_routes_via_admin.sh"
2323
fi
2424

25+
if [ ! -f "${INPUT_FILE}" ]; then
26+
echo "[ERROR] Config file not found: ${INPUT_FILE}. Run scripts/adc_render.sh first." 1>&2
27+
exit 3
28+
fi
29+
2530
echo "Using ADC: $(adc --version 2>/dev/null || echo unknown)"
2631

2732
try_publish() {

scripts/adc_render.sh

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ set -euo pipefail
44
# Render APISIX config from OpenAPI using ADC CLI (v0.21.2 supported)
55
# This script tries multiple subcommands as ADC changed verbs across versions.
66
# Priority (auto-detected):
7-
# 1) adc openapi generate -i <in> -o <out>
8-
# 2) adc generate -i <in> -o <out>
9-
# 3) adc compile -i <in> -o <out>
7+
# 1) adc convert openapi -f <in> -o <out>
8+
# 2) adc openapi generate -i <in> -o <out>
9+
# 3) adc generate -i <in> -o <out>
10+
# 4) adc render -i <in> -o <out>
11+
# 5) adc compile -i <in> -o <out>
1012
# If none are available, exits with guidance.
1113

1214
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
@@ -26,7 +28,7 @@ echo "Using ADC: $(adc --version 2>/dev/null || echo unknown)"
2628
echo "Input OpenAPI: ${INPUT_OPENAPI}"
2729
echo "Output: ${OUT_FILE}"
2830

29-
run_with() {
31+
run_with_io_flags() {
3032
echo "Trying: adc $*"
3133
set +e
3234
adc "$@" -i "${INPUT_OPENAPI}" -o "${OUT_FILE}"
@@ -35,19 +37,34 @@ run_with() {
3537
return $rc
3638
}
3739

40+
run_convert_openapi() {
41+
echo "Trying: adc convert openapi"
42+
set +e
43+
adc convert openapi -f "${INPUT_OPENAPI}" -o "${OUT_FILE}"
44+
rc=$?
45+
set -e
46+
return $rc
47+
}
48+
3849
# Try known commands in order
39-
if run_with openapi generate; then
40-
echo "Render OK -> ${OUT_FILE}"
41-
exit 0
42-
elif run_with generate; then
43-
echo "Render OK -> ${OUT_FILE}"
44-
exit 0
45-
elif run_with compile; then
50+
if run_convert_openapi; then
4651
echo "Render OK -> ${OUT_FILE}"
4752
exit 0
4853
fi
4954

50-
echo "[ERROR] Failed to render with known ADC commands (openapi generate / generate / compile)." 1>&2
55+
for cmd in \
56+
"openapi generate" \
57+
"generate" \
58+
"render" \
59+
"compile"
60+
do
61+
if run_with_io_flags ${cmd}; then
62+
echo "Render OK -> ${OUT_FILE}"
63+
exit 0
64+
fi
65+
done
66+
67+
echo "[ERROR] Failed to render with known ADC commands (convert openapi / openapi generate / generate / render / compile)." 1>&2
5168
echo " Your ADC (v0.21.2 reported) may use a different verb." 1>&2
5269
echo " Please adjust this script to the correct ADC command." 1>&2
5370
exit 2

0 commit comments

Comments
 (0)