นำเข้าโปรเจกต์ Compose
บท
ร่างตัวอย่าง
คุณ
เขียน
aggrega draft --example import-composeจากsource ซึ่ง
cd import-compose
โปรเจกต์
compose.yaml:
# A small notes service: its API, the PostgreSQL database it keeps the notes in,# and the Redis cache in front of it.name: notes
services: api: image: ghcr.io/example/notes-api:2.3.0 ports: - "8080:8080" environment: DATABASE_HOST: db DATABASE_USER: notes DATABASE_NAME: notes DATABASE_PASSWORD: ${POSTGRES_PASSWORD} CACHE_HOST: cache depends_on: - db - cache db: image: postgres:16 environment: POSTGRES_USER: notes POSTGRES_DB: notes POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} volumes: - db-data:/var/lib/postgresql/data cache: image: redis:7
volumes: db-data:ข้าง.aggrega-config.yaml ทำให้
# The workspace key marks this directory as the workspace root, so an import run# here writes its drafts beside compose.yaml.workspace: {}# The registry the importer is fetched from the first time an import needs it.default_registry: hub.aggrega.aiการนำ--target ร่าง Manifest จาก Recipes ของAGGREGA_CATALOG_DIRS หรือworkspace.catalog_dirs — อ่าน
ไฟล์คำตอบ
บิลด์--target helm ต้องimport-answers.yaml ข้าง compose.yaml ซึ่ง
# Values the import could not draft from the source, keyed by the drafted file and the key path inside# it. Write each one beside its key; an import of the same source, and a sync, read them from here and# ask nothing. A secret is never written here: its key asks where the secret comes from — a variable# name, ${NAME}, or the name of a Kubernetes Secret.release.yaml: # The origin of the secret value, written by the operator in the Release. Read exactly as # values.origin is. Write it here or in values.origin, never in both. A secret: name where it comes # from, never the value. spec.components.db.features.password.infra.origin: "notes-db-password"การนำ--target helm: แสดง
aggrega import ระบุ--answers ซึ่ง
เปลี่ยนsource:
cd sourceรันการนำเข้า
aggrega import compose.yaml --target composeที่
wrote aggregate.yamlwrote release.yamlwrote manifest.yamlwrote .aggrega-import.jsonที่<workspace> แทน
[… omitted: a warning that the importer runs unverified, printed where its module is read from beside its Plugin entity in a catalog folder rather than fetched]read as the compose format, with drafted paths relative to <workspace>warn: the value of environment.POSTGRES_USER of node db is carried as written in the drafts: its format marks the field as no credential, though it can carry one, and setting empty_credentials to all writes it emptywarn: the value of environment.POSTGRES_DB of node db is carried as written in the drafts: its format marks the field as no credential, though it can carry one, and setting empty_credentials to all writes it emptymapped api (ghcr.io/example/notes-api) to core/compute/server as a reference, NONEmapped db (postgres) to core/datastore/postgres as a reference, HIGH at 0.9mapped cache (redis) to core/datastore/redis as a reference, HIGH at 0.9Pull complete: <workspace>/release.lock (entities=10, source_artifacts=0, external_inputs=0)
- บรรทัด
warnระบุแต่ละ ค่าที่ ฉบับ ร่าง นำ มา ตาม ที่ เขียน ตาม บริการ และ ตัวแปร ของ ค่า นั้น ไม่ ระบุ ด้วย ค่า: Compose ไม่ ทำ เครื่องหมาย ค่า ใด เป็น ข้อมูล รับรอง และ ค่า ใด ก็ อาจ มี ข้อมูล รับรอง ได้ ใน ที่ นี้ ไม่มี ตัวแปร ที่ API อ่าน จาก บริการ อื่น ไม่ ได้ นำ มา เป็น ค่า เลย — การ เชื่อม ต่อ ส่ง มอบ ให้ — และ สอง ตัว ที่ อ่าน ${POSTGRES_PASSWORD}เป็นการอ้างอิง ตัวแปร เท่านั้น จึง ไม่มี คำ เตือน ระบุ ถึง - บรรทัด
mappedบอกว่า แต่ละ บริการ กลาย เป็น อะไร apiรันอิมเมจ ของ ตนเอง จึง เป็น อินสแตนซ์ ของ เซิร์ฟเวอร์ ทั่วไป ของ ไลบรารี มาตรฐาน คือ core/compute/serverส่วนdbและcacheรันอิมเมจ ที่ Compose Recipes ของ ไลบรารี มาตรฐาน รัน สำหรับ core/datastore/postgresและcore/datastore/redisแต่ละรายการ ตรง กับ Component นั้น ใน ระดับ สูง ที่ 0.9 และ ฉบับ ร่าง อ้างอิง Component นั้น - บรรทัด
Pull completeคือการนำ เข้า ดึง สิ่ง ที่ Release ที่ ร่าง พึ่งพา เหมือน ที่ aggrega pullทำ ลงในrelease.lockฉบับร่าง จึง ตรวจ สอบ ความ ถูก ต้อง และ บิลด์ ได้ ทันที ภาย ใต้ --offlineการนำเข้า ไม่ pull สิ่ง ใด และ ระบุ aggrega pullที่ต้อง รัน
สิ่งที่การนำเข้าเขียน
Aggregate, Release และ Manifest ชื่อ imported/notes ตาม name: ของname: ตั้งcompose และtarget_namespace ของimported เว้น
aggregate.yaml — หนึ่ง
# Not carried, since the draft reads the services and the models alone: volumes.apiVersion: aggrega.ai/v1beta1kind: Aggregatemetadata: name: imported/notes version: 0.1.0 description: Draft Aggregate imported from a source in the compose format.spec: components: api: type: core/compute/server features: # For the compose target, the lines below declare database_password on api: a secret the Release alone attaches arrives under the key value, so each is declared with a key of its own and no two arrive under one; the Release attaches its origin, naming this type or none. database_password: type: core/secret-value values: key: DATABASE_PASSWORD uses: cache: cache: target: cache # The variables the source sets to what cache publishes, delivered from it under the names the source gives them. inject: env: - in: "CACHE_HOST" from: host db: db: target: db # The variables the source sets to what db publishes, delivered from it under the names the source gives them. inject: env: - in: "DATABASE_HOST" from: host - in: "DATABASE_USER" from: user - in: "DATABASE_NAME" from: database db: type: core/datastore/postgres # The values of core/datastore/postgres the source sets as POSTGRES_USER, POSTGRES_DB, the variables its Compose Recipes set from them. values: user: "notes" database: "notes" features: # For the compose target, the lines below declare password on db: a secret the Release alone attaches arrives under the key value, so each is declared with a key of its own and no two arrive under one; the Release attaches its origin, naming this type or none. password: type: core/secret-value values: key: POSTGRES_PASSWORD cache: type: core/datastore/redisตัวแปรinject ของDATABASE_HOST เป็น db และhost ที่DATABASE_USER และ DATABASE_NAME ตรงvalues ของcore/secret-value ที่
release.yaml — สภาพ
apiVersion: aggrega.ai/v1beta1kind: Releasemetadata: name: imported/notes # environment is a drafted default, since no source names the environment this Release deploys to; change it to name the one it deploys to. environment: development version: 0.1.0 description: Draft Release imported from a source in the compose format.spec: aggregate: imported/notes manifest: imported/notes components: # The source also states, for the Release to carry where core/compute/server takes it: # ports: # - "8080:8080" api: infra: image: "ghcr.io/example/notes-api:2.3.0" port: 8080 # Published on this machine's loopback address, 127.0.0.1: reachable from this machine only, by any process running on it. Delete this line to keep the service internal. published_port: 8080 features: database_password: type: core/secret-value infra: # Attached by reference, never as a value: the value api reads as DATABASE_PASSWORD, read from the variable POSTGRES_PASSWORD, which a target substituting variable references, as Docker Compose does when the stack starts, reads from the environment, so no file carries the value. origin: "${POSTGRES_PASSWORD}" # The source states, for the Release to carry where core/datastore/postgres takes it: # volumes: # - "db-data:/var/lib/postgresql/data" db: infra: # The tag of the image the source runs, postgres:16, the engine_version of core/datastore/postgres its Compose Recipes run. engine_version: "16" features: password: type: core/secret-value infra: # Attached by reference, never as a value: the password of db, which the source sets as POSTGRES_PASSWORD, read from the variable POSTGRES_PASSWORD, which a target substituting variable references, as Docker Compose does when the stack starts, reads from the environment, so no file carries the value. origin: "${POSTGRES_PASSWORD}" cache: infra: # The tag of the image the source runs, redis:7, the engine_version of core/datastore/redis its Compose Recipes run. engine_version: "7"สภาพdevelopment เป็นport ของ API คือpublished_port คือports เผยhttp://127.0.0.1:8080 ได้ และports ของport และ published_port นำ
manifest.yaml — Compose Recipe ของ
apiVersion: aggrega.ai/v1beta1kind: Manifestmetadata: name: imported/notes version: 0.1.0spec: mappings: components: type: core/compute/server: compose/server core/datastore/postgres: compose/postgres core/datastore/redis: compose/redis features: type: core/secret-value: compose/dotenv-secretrelease.lock บันทึก.aggrega-import.json เป็นaggrega import --sync ครั้ง
ตรวจสอบความถูกต้องและบิลด์
aggrega validate --release release.yamlaggrega build --release release.yaml

การ
notice: LINT: Feature "core/secret-value" at core/secret-value:1.0.0 declares property "origin" in both values: and infra: pillars (path: origin)release dependency validation passed: release.yaml (schema-pillar + dependency pillars)และ<workspace> แทน
notice: LINT: Feature "core/secret-value" at core/secret-value:1.0.0 declares property "origin" in both values: and infra: pillars (path: origin)[… omitted: a total build time, which differs per run]Build completed: 1 file written to <workspace>/distบรรทัด notice เป็นorigin จาก values ของ Aggregate หรือ infra ของ Release และ
บริการ api ใน dist/compose/docker-compose.yaml อ่าน
api: image: ghcr.io/example/notes-api:2.3.0 environment: CACHE_HOST: cache DATABASE_HOST: db DATABASE_NAME: notes DATABASE_PASSWORD: ${POSTGRES_PASSWORD} DATABASE_USER: notes ports: - 127.0.0.1:8080:8080 [… omitted: the labels the build writes on every service, naming the Aggregate, the component, the environment and the compiler's version] networks: - compose depends_on: - cache - db [… omitted: the CPU and memory the server's defaults reserve]และ
db: image: postgres:16 environment: POSTGRES_USER: notes POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} POSTGRES_DB: notes [… omitted: the labels, the network and a health check running PostgreSQL's pg_isready] cache: image: redis:7 [… omitted: the labels, the network and a health check running redis-cli ping]ไฟล์
กับผู้ช่วย AI
ผู้
ใช้เฉพาะเครื่องมือของ Aggrega และอย่าสร้างโฟลเดอร์เอง หากโฟลเดอร์พื้นที่ทำงานยังไม่มีโฟลเดอร์ `import-compose` เรียกเครื่องมือ `draft` หนึ่งครั้งโดยตั้ง `example` เป็น `import-compose` และไม่ตั้ง `dir`: เครื่องมือนี้เขียนตัวอย่างลงในโฟลเดอร์ `import-compose` ใหม่ ซึ่งโฟลเดอร์ `source` ของโฟลเดอร์นั้นมีสิ่งที่หน้านี้นำเข้า จากนั้นเรียกเครื่องมือ `import` โดยตั้ง `workspace_root` เป็น `import-compose/source` ตั้ง `source` เป็น `compose.yaml` และตั้ง `target` เป็น `compose`: เครื่องมือนี้อ่านคำตอบที่ต้องใช้จาก `import-answers.yaml` ข้าง `compose.yaml` เขียนฉบับร่างลงใน `import-compose/source` และ pull สิ่งที่ฉบับร่างต้องใช้ จากนั้นเรียกเครื่องมือ `validate` โดยตั้ง `workspace_root` เป็น `import-compose/source` และ `release` เป็น `release.yaml` และเครื่องมือ `build` โดยตั้ง `workspace_root` เป็น `import-compose/source` ตั้ง `release` เป็น `release.yaml` และตั้ง `write` เป็น true บอกฉันว่าบิลด์เขียนไฟล์ใดบ้าง ไฟล์เหล่านั้นอยู่ใต้ `import-compose/source/dist/`เปิดใน VS Code
เมื่อimport-compose/source ใน VS Code ซึ่งrelease.yaml ที่dist/ ของ
วิธีรัน
ghcr.io/example/notes-api:2.3.0 แทนError Head "https://ghcr.io/v2/example/notes-api/manifests/2.3.0": denied ระบุinfra.image ของ api ใน release.yaml จนกว่า API ของmendhak/http-https-echo:39 ซึ่ง
api: infra: image: "mendhak/http-https-echo:39" port: 8080บิลด์release.lock ที่--auto-pull ซึ่งaggrega pull Docker Compose เติม${POSTGRES_PASSWORD} ทั้งThe "POSTGRES_PASSWORD" variable is not set. Defaulting to a blank string. และ
aggrega build --release release.yaml --auto-pullexport POSTGRES_PASSWORD='a password of your own'docker compose -p notes -f dist/compose/docker-compose.yaml up -d --wait-p ตั้ง--wait กลับ
ทดสอบ
ถาม API ที่ http://127.0.0.1:8080 ซึ่งpublished_port เผย
curl -sS http://127.0.0.1:8080/notes{ "path": "/notes", "headers": { "host": "127.0.0.1:8080", [… omitted: the user agent and the media types the client sent] }, "method": "GET", [… omitted: the rest of the request as the stand-in received it, the client's address and the container's host name]}สิ่ง
docker compose -p notes -f dist/compose/docker-compose.yaml exec api printenv DATABASE_HOST DATABASE_USER DATABASE_NAME CACHE_HOSTdbnotesnotescacheหยุด
docker compose -p notes -f dist/compose/docker-compose.yaml downบน Kubernetes
โปรเจกต์--target helm และnotes-db-password จากsource แล้ว จึงrelease.yaml ของ
aggrega import compose.yaml --target helm --output-dir helmcd helmaggrega build --release release.yaml --auto-pullบิลด์dist/helm/ ที่source ซึ่งhelm คือ ../dist/helm/ สร้าง Secret notes-db-password ในvalue และapi-default: ส่ง
kubectl port-forward -n <namespace> svc/api-default 8080:8080จาก"host": "127.0.0.1:8080" การkubectl exec -n <namespace> deploy/api -- printenv DATABASE_HOST DATABASE_USER DATABASE_NAME CACHE_HOST พิมพ์ db-default, notes, notes และ cache-default API ยังnotes-db-password ถึงDATABASE_PASSWORD ในapi
เมื่อไฟล์ Compose เปลี่ยน
เก็บ .aggrega-import.json ไว้
aggrega import compose.yaml --syncเปลี่ยน