ข้ามไปยังเนื้อหา
AggregaAggregaAggregaAggrega
เลือกภาษา: ไทย
หน้านี้ถูกแปลด้วยเครื่อง อ่านต้นฉบับภาษาอังกฤษ

นำเข้าแอปพลิเคชัน Dify

บทแนะนำทีละขั้นตอนนี้นำเข้าแอปพลิเคชันที่ส่งออกจาก Dify — ผู้ช่วยแชตบนโมเดล OpenAI — เป็น Aggregate, Release และ Manifest ที่บิลด์การติดตั้ง Dify ของไลบรารีมาตรฐานพร้อมแอปพลิเคชันสำหรับ Kubernetes ตามที่เขียนไว้ จากนั้นบิลด์สิ่งเหล่านั้นและรันสิ่งที่บิลด์ได้ ทุกไฟล์และทุกบล็อกของเอาต์พุตด้านล่างมาจากการรันจริง แอปพลิเคชันและแต่ละขั้นตอนของบทแนะนำอยู่ในตัวอย่าง import-dify ซึ่งสคริปต์ตรวจสอบรันการนำเข้าอีกครั้ง เปรียบเทียบสิ่งที่นำเข้าเขียน สิ่งที่พิมพ์ และบล็อกที่หน้านี้อ้างกับไฟล์ที่เก็บไว้ที่นั่น และตรวจสอบความถูกต้องและบิลด์สิ่งที่การนำเข้าเขียน

ร่างตัวอย่าง

คุณรันการนำเข้านี้ด้วยคำสั่งในหน้านี้ได้ หรือ ให้ผู้ช่วย AI ของคุณรันให้

เขียนตัวอย่างลงในโฟลเดอร์ใหม่ที่ตั้งชื่อตามตัวอย่าง:

Terminal window
aggrega draft --example import-dify

จากนั้นจะพิมพ์คำสั่งที่ต้องรันต่อ คำสั่งแรกเปลี่ยนเข้าโฟลเดอร์ใหม่ ส่วนคำสั่งถัดไปด้านล่างเปลี่ยนเข้าโฟลเดอร์ source ซึ่งมีสิ่งที่หน้านี้นำเข้าและเป็นที่ที่การนำเข้ารัน:

Terminal window
cd import-dify

โฟลเดอร์ source ของตัวอย่างที่ร่างไว้เปิดอยู่ใน Visual Studio Code แสดงไฟล์ส่งออกแอป Dify ของผู้ช่วยสนับสนุนในโหมดแชต

แอปพลิเคชัน

support-assistant.yml ที่เขียนสำหรับบทแนะนำทีละขั้นตอนนี้ เป็นแอปพลิเคชันแชตใน DSL ของ Dify ซึ่งเป็น YAML ที่ Dify ส่งออกสำหรับแอปพลิเคชัน ที่ DSL เวอร์ชัน 0.7.0 ประกอบด้วยข้อความเปิด พรอมต์สั้นๆ และโมเดลที่ใช้ตอบ ซึ่งระบุด้วยผู้ให้บริการของโมเดล:

model:
completion_params:
stop: []
temperature: 0.4
mode: chat
name: gpt-4o-mini
provider: langgenius/openai/openai

ข้างไฟล์นั้น มี .aggrega-config.yaml ที่ทำให้โฟลเดอร์เป็นพื้นที่ทำงาน:

# The workspace key marks this directory as the workspace root, so an import run
# here writes its drafts beside support-assistant.yml.
workspace: {}
# The registry the importer is fetched from the first time an import needs it.
default_registry: hub.aggrega.ai

และ import-answers.yaml เก็บคำตอบของสิ่งที่แอปพลิเคชันไม่มีทางเก็บไว้ได้ ได้แก่ข้อมูลลับของแอปพลิเคชันในการติดตั้ง ซึ่งเป็นคีย์ที่ Dify ใช้ลงนามเซสชันและใช้เข้ารหัสคีย์ของผู้ให้บริการโมเดลที่ Dify เก็บไว้ และบัญชีเจ้าของที่นำเข้าแอปพลิเคชันภายใต้บัญชีนั้น ได้แก่อีเมลและรหัสผ่าน บน Kubernetes ข้อมูลลับแต่ละรายการอ่านจาก Kubernetes Secret คำตอบจึงเป็นชื่อของ Secret นั้น ไฟล์เดียวกันใช้กับการนำเข้าสำหรับ Docker Compose ได้ ดังที่ บน Docker Compose แสดง:

# 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:
# Passed down to core/dify's secret_key parameter, which has no default; that parameter's description
# in core/dify says what the value is.
spec.parameters.secret_key: "dify-credentials"
# Email address of the installation's owner account, read only when values.app_definition is set. The
# step that imports the application creates this account when it performs Dify's first-time setup, and
# signs in as it; on an installation whose setup has already run, it names an existing account allowed
# to import applications, and the password attached to the owner_password slot is that account's.
# Required when values.app_definition is set: the build halts when it is empty. It has no default.
spec.boundaries.platform.aggregates.dify.components.api.infra.owner_email: "owner@example.com"
# 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.boundaries.platform.aggregates.dify.components.api.features.owner_password.infra.origin: "dify-owner"

owner@example.com แทนอีเมลของคุณเอง dify-credentials และ dify-owner คือ Secrets ที่ วิธีรัน สร้างขึ้น หากไม่มีไฟล์ การนำเข้าบนเทอร์มินัลจะถามค่าทั้งสามค่าทีละค่า ทีละหนึ่งคำถาม และเขียนคำตอบของคุณลงในไฟล์คำตอบใหม่ เมื่อไม่มีทางถามได้ การนำเข้าจะเขียนไฟล์นั้นโดยมีคีย์สามคีย์และคำตอบว่าง แสดงรายการคีย์เหล่านั้น และออกด้วยสถานะ 1 ไฟล์คำตอบของการนำเข้า อธิบายไฟล์นี้อย่างครบถ้วน

พื้นที่ทำงานไม่ระบุโฟลเดอร์แค็ตตาล็อกใดเลย การนำเข้าจึงอ่านแค็ตตาล็อกของไลบรารีมาตรฐานจากรีจิสทรีที่ใช้ดึงตัวนำเข้า คือสแนปช็อตที่ลงนามของแค็ตตาล็อกที่เผยแพร่ ซึ่งการนำเข้าครั้งแรกดึงมา ตรวจสอบ และเก็บไว้ในแคชเนื้อหาของพื้นที่ทำงาน และระบุด้วยไดเจสต์ในบันทึกที่การนำเข้าเขียนไว้ข้างฉบับร่าง พื้นที่ทำงานที่ระบุโฟลเดอร์แค็ตตาล็อกของตนเอง — ใน AGGREGA_CATALOG_DIRS หรือใต้ workspace.catalog_dirs — จะอ่านโฟลเดอร์เหล่านั้นก่อน โดยมีสแนปช็อตที่เผยแพร่อยู่ถัดจากนั้น เปลี่ยนไดเรกทอรีไปที่ source:

Terminal window
cd source

รันการนำเข้า

การติดตั้ง Dify ของไลบรารีมาตรฐานทำให้เกิดขึ้นจริงบน Kubernetes และบน Docker Compose บทแนะนำทีละขั้นตอนนี้ระบุเป้าหมาย helm:

Terminal window
aggrega import support-assistant.yml --target helm

ที่เอาต์พุตมาตรฐาน การนำเข้าแสดงสิ่งที่เขียน:

wrote aggregate.yaml
wrote release.yaml
wrote manifest.yaml
wrote .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 dify format, with drafted paths relative to <workspace>
warn: node model_config.model (model) names the model "gpt-4o-mini" of the model provider "langgenius/openai/openai", whose credentials are set inside Dify, and core/ai-agent/dify configures that for itself rather than reaching it through a socket, so the draft wires no part for it
made no choice for model_config.model (model)
Pull complete: <workspace>/release.lock (entities=25, source_artifacts=0, external_inputs=0)

การนำเข้าที่รันจากตัวแก้ไข: Aggregate, Release และ Manifest ที่ร่างไว้ปรากฏข้างไฟล์ส่งออกของแอป เอาต์พุต Aggrega แสดงสิ่งที่ฉบับร่างเชื่อมโยงและไฟล์ที่เขียน และการแจ้งเตือนระบุว่าการนำเข้าร่างไฟล์ 3 ไฟล์ จำแนกได้ว่าเป็น dify

  • บรรทัด warn บอกว่าโมเดลอยู่ภายใน Dify: Dify กำหนดค่าผู้ให้บริการโมเดลและคีย์ของผู้ให้บริการเหล่านั้นเอง ฉบับร่างจึงไม่เชื่อมโยงโมเดลใดเลย เมื่อ Dify รันแล้ว คุณติดตั้งผู้ให้บริการ OpenAI ของ Dify และตั้งคีย์ของผู้ให้บริการนั้น ดังที่ ทดสอบ แสดง
  • บรรทัด Pull complete คือขั้นตอน pull เมื่อทุกค่าได้คำตอบจากไฟล์คำตอบ การนำเข้า pull การพึ่งพาของ Release ที่ร่างไว้ เหมือนที่ aggrega pull ทำ และเขียน release.lock บิลด์ด้านล่างไม่ต้องใช้สิ่งใดเพิ่ม

สิ่งที่การนำเข้าเขียน

Aggregate, Release และ Manifest ตั้งชื่อเป็น imported/support-assistant ตามชื่อของแอปพลิเคชัน คือ Support assistant ใต้ app ที่ย่อเป็น support-assistant — แอปพลิเคชันที่ไม่มีชื่อจะตั้งชื่อตามไฟล์ของแอปพลิเคชันนั้น — ภายใต้เนมสเปซที่การตั้งค่า target_namespace ของตัวนำเข้ากำหนด คือ imported เว้นแต่คุณตั้งเนมสเปซอื่น (การตั้งค่า)

aggregate.yaml — การติดตั้ง Dify ของไลบรารีมาตรฐาน คือ core/dify ซึ่งเป็น Aggregate ที่ฉบับร่างประกอบไว้ใต้ aggregates โดยถือแอปพลิเคชันไว้ตามที่เขียนในพารามิเตอร์ app_definition ซึ่งที่นี่ตัดส่วนใหญ่ออก และ secret_key ของการติดตั้งส่งต่อลงมาจากพารามิเตอร์ที่ฉบับร่างประกาศ:

apiVersion: aggrega.ai/v1beta1
kind: Aggregate
metadata:
name: imported/support-assistant
version: 0.1.0
description: Draft Aggregate imported from a source in the dify format.
spec:
parameters:
secret_key:
type: string
required: true
minLength: 1
description: "Passed down to core/dify's secret_key parameter, which has no default; that parameter's description in core/dify says what the value is."
aggregates:
# An import sees the Components of the workspace's catalog and none of its Aggregates, so it does not check that the catalog holds core/dify.
dify:
type: core/dify
parameters:
secret_key: "{{ .parameters.secret_key }}"
app_definition: |
app:
description: Answers questions about the support plans of a small software company.
[… omitted: the rest of the application, as exported]
version: 0.7.0

การติดตั้งมีส่วนประกอบสิบรายการ — เซิร์ฟเวอร์ API ของ Dify worker ตัวจัดตารางเวลา ฟรอนต์เอนด์เว็บ แซนด์บ็อกซ์โค้ด รันไทม์ของปลั๊กอิน พร็อกซีขาออก PostgreSQL แคชที่เข้ากันได้กับ Redis และ Weaviate — ที่เชื่อมโยงกัน และการนำเข้าแอปพลิเคชันเป็นขั้นตอนที่ Recipe ของเซิร์ฟเวอร์ API เรนเดอร์ ข้อมูลลับของแอปพลิเคชันไม่มีค่าเริ่มต้นใน core/dify ฉบับร่างจึงประกาศ secret_key เป็นพารามิเตอร์ของตนเองโดยไม่มีค่าเริ่มต้น และส่งต่อลงไปให้ Release ระบุค่า ข้อมูลรับรองอื่นของการติดตั้งใช้ค่าเริ่มต้นที่ core/dify กำหนดให้ ดังที่ วิธีรัน อธิบาย

release.yaml — Release ซึ่งจัดเส้นทางการติดตั้งเข้าสู่แนวเขต platform และระบุค่าสิ่งที่แอปพลิเคชันให้ไม่ได้จากไฟล์คำตอบ:

apiVersion: aggrega.ai/v1beta1
kind: Release
metadata:
name: imported/support-assistant
# 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 dify format.
spec:
aggregate: imported/support-assistant
manifest: imported/support-assistant
parameters:
# Left for the Release, since the source cannot supply it: secret_key, which the drafted Aggregate declares and passes down to core/dify; that parameter's description there says what the value is
secret_key: "dify-credentials"
boundaries:
platform:
aggregates:
dify:
components:
api:
infra:
# Lets the installation reach Dify's plugin marketplace, which the plugin serving the application's model, such as OpenAI's, is installed from.
marketplace_enabled: true
# Left for the Release, since the source cannot supply it: components.api.infra.owner_email, the email of the installation's owner account the application is imported under, on the api component of core/dify
owner_email: "owner@example.com"
features:
owner_password:
type: core/referenced-secret
infra:
# Left for the Release, since the source cannot supply it: the name of a Kubernetes Secret already in the namespace holding, under the data key value, the owner account's password.
origin: "dify-owner"
worker:
infra:
# Lets the installation reach Dify's plugin marketplace, which the plugin serving the application's model, such as OpenAI's, is installed from.
marketplace_enabled: true
scheduler:
infra:
# Lets the installation reach Dify's plugin marketplace, which the plugin serving the application's model, such as OpenAI's, is installed from.
marketplace_enabled: true
  • environment คือ development ซึ่งเป็นค่าเริ่มต้นที่ความคิดเห็นด้านบนบอกให้เปลี่ยนเป็นสภาพแวดล้อมที่ Release ปรับใช้
  • secret_key คือชื่อของ Secret ที่เก็บข้อมูลลับของแอปพลิเคชัน คือ dify-credentials ภายใต้คีย์ข้อมูลที่การติดตั้งระบุ คือ secret-key: Manifest อ่านข้อมูลรับรองทุกรายการจาก Secret ที่มีอยู่ในเนมสเปซแล้ว
  • บัญชีเจ้าของ ตั้งค่าบนส่วนประกอบ api ของการติดตั้ง ในรายการการกำหนดเส้นทางที่วางการติดตั้งไว้ในแนวเขตของตน ได้แก่อีเมล และรหัสผ่านที่แนบเป็น core/referenced-secret ซึ่งระบุ Secret ที่เก็บรหัสผ่านนั้น คือ dify-owner ภายใต้คีย์ข้อมูล value ความคิดเห็นด้านบนค่าที่ตอบแล้วบอกว่าเหตุใดการนำเข้าจึงร่างค่าเหล่านั้นไม่ได้
  • marketplace_enabled เป็น true บนเซิร์ฟเวอร์ API คือ api worker และตัวจัดตารางเวลาของเซิร์ฟเวอร์นั้น ในทุกเป้าหมาย: การติดตั้งไม่เข้าถึงสิ่งใดของผู้จำหน่าย Dify เลย เว้นแต่ Release อนุญาต และผู้ให้บริการ OpenAI ที่แอปพลิเคชันใช้ตอบเป็นปลั๊กอินที่ Dify ติดตั้งจากตลาดปลั๊กอินของตน ดังที่ ทดสอบ แสดง ทั้งสามตัวอ่านการตั้งค่าของตนเอง

manifest.yaml — Recipe ของ Helm สำหรับส่วนประกอบแต่ละรายการที่การติดตั้งประกอบขึ้น และการทำให้เป็นรูปธรรมที่อ่านข้อมูลรับรองจาก Secret ที่มีอยู่ในเนมสเปซแล้ว:

apiVersion: aggrega.ai/v1beta1
kind: Manifest
metadata:
name: imported/support-assistant
version: 0.1.0
spec:
mappings:
components:
type:
core/datastore/postgres: helm/postgres
core/datastore/redis: helm/redis
core/datastore/weaviate: helm/weaviate
core/ai-agent/dify-ssrf-proxy: helm/dify-ssrf-proxy
core/ai-agent/dify-sandbox: helm/dify-sandbox
core/ai-agent/dify-plugin-daemon: helm/dify-plugin-daemon
core/ai-agent/dify: helm/dify
core/ai-agent/dify-worker: helm/dify-worker
core/ai-agent/dify-worker-beat: helm/dify-worker-beat
core/ai-agent/dify-web: helm/dify-web
features:
type:
core/referenced-secret: helm/k8s-existing-secret

--target แมปประเภทส่วนประกอบของการติดตั้งที่ฉบับร่างประกอบ รวมทั้งประเภทของฉบับร่างเอง เมื่อแค็ตตาล็อกเสนอ Recipes ของ Helm หลายรายการสำหรับหนึ่งประเภท เช่นที่ทำกับ PostgreSQL ก็จะแมปรายการที่ตั้งชื่อตามประเภทนั้น คือ helm/postgres

.aggrega-import.json คือบันทึกของสิ่งที่การนำเข้าเขียน ซึ่ง aggrega import --sync ครั้งต่อมาอ่าน และ release.lock ปักหมุดเอนทิตีแค็ตตาล็อกทุกรายการที่ Release หาค่าไปถึง ด้วยเวอร์ชันและไดเจสต์

ตรวจสอบความถูกต้องและบิลด์

Terminal window
aggrega validate --release release.yaml
aggrega build --release release.yaml

Release ที่ร่างไว้เปิดอยู่ในตัวแก้ไขหลังตรวจสอบความถูกต้อง โดยเอาต์พุต Aggrega และการแจ้งเตือนต่างรายงานว่าไม่พบปัญหา

การบิลด์ Release ที่ร่างไว้: โฟลเดอร์ dist ปรากฏใน Explorer เอาต์พุต Aggrega แสดงแมนิเฟสต์ Kubernetes ของการติดตั้ง Dify และการแจ้งเตือนระบุว่าเขียนไฟล์ 24 ไฟล์

การตรวจสอบความถูกต้องพิมพ์:

notice: LINT: Feature "core/referenced-secret" at core/referenced-secret: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/referenced-secret" at core/referenced-secret: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: 24 files written to <workspace>/dist

บรรทัด notice เป็นเชิงแนะนำ: Feature ของข้อมูลลับรับ origin จาก values ของ Aggregate หรือ infra ของ Release และการแจ้งให้ทราบรายงานว่ามีค่าระดับใบหนึ่งค่าที่ประกาศไว้ทั้งสองที่ ซึ่งไม่เปลี่ยนคำตัดสิน

บิลด์เขียนแมนิเฟสต์ Kubernetes ของการติดตั้งไว้ใต้ dist/boundaries/platform/helm/ ในนั้นมี Job ที่นำเข้าแอปพลิเคชัน คือ dify.api/dify-app-import.job.yaml Job นี้รอให้เซิร์ฟเวอร์ API ของ Dify ตอบ ทำการตั้งค่าครั้งแรกของ Dify ด้วยบัญชีเจ้าของที่ Release ระบุ ในกรณีที่การตั้งค่านั้นยังไม่ได้รัน และนำเข้าแอปพลิเคชัน:

spec:
podFailurePolicy:
rules:
- action: FailJob
onExitCodes:
containerName: import
operator: In
values: [2]
template:
spec:
restartPolicy: Never
containers:
- name: import
image: "langgenius/dify-api:1.17.0"
command: ["python", "/seed/import.py"]
env:
- name: DIFY_API_URL
value: "http://dify-zdapi-default:5001"
- name: OWNER_EMAIL
value: "owner@example.com"
- name: OWNER_PASSWORD
valueFrom:
secretKeyRef:
name: "dify-owner"
key: "value"
volumeMounts:
- name: seed
mountPath: /seed
readOnly: true
volumes:
- name: seed
configMap:
name: dify-zdapi-app

ตัวแอปพลิเคชันอยู่ใน ConfigMap ที่อยู่ข้างกัน เมื่อ Dify ปฏิเสธสิ่งที่ขั้นตอนส่งไป ด้วยการตอบกลับที่เป็นข้อผิดพลาดฝั่งไคลเอนต์ นอกจากการหมดเวลาของคำขอหรือขีดจำกัดอัตราคำขอ หรือด้วยการรายงานว่านำเข้าล้มเหลว ขั้นตอนจะพิมพ์ข้อความที่การตอบกลับของ Dify มาด้วย และออกด้วยสถานะ 2 เหมือนที่ทำเมื่อนิยามไม่ระบุแอปพลิเคชันใต้ app.name podFailurePolicy ของ Job ทำให้ Job ล้มเหลวที่ความพยายามนั้น เพราะการลองใหม่จะถูกปฏิเสธแบบเดียวกัน ความล้มเหลวอื่นใด เช่นเซิร์ฟเวอร์ไม่ตอบภายในประมาณสิบนาที จะลองใหม่

กับผู้ช่วย AI

ผู้ช่วย AI ที่ ตั้งค่าด้วยเครื่องมือของ Aggrega ทำสิ่งเดียวกันได้: วางพรอมต์นี้ลงไป

ใช้เฉพาะเครื่องมือของ Aggrega และอย่าสร้างโฟลเดอร์เอง หากโฟลเดอร์พื้นที่ทำงานยังไม่มีโฟลเดอร์ `import-dify` เรียกเครื่องมือ `draft` หนึ่งครั้ง โดยตั้ง `example` เป็น `import-dify` และไม่ระบุ `dir`: เครื่องมือเขียนตัวอย่างลงในโฟลเดอร์ `import-dify` ใหม่ ซึ่งโฟลเดอร์ `source` ของโฟลเดอร์นั้นเก็บสิ่งที่หน้านี้นำเข้า จากนั้นเรียกเครื่องมือ `import` โดยตั้ง `workspace_root` เป็น `import-dify/source` ตั้ง `source` เป็น `support-assistant.yml` และตั้ง `target` เป็น `helm`: เครื่องมืออ่านคำตอบที่ต้องใช้จาก `import-answers.yaml` ข้าง `support-assistant.yml` เขียนฉบับร่างลงใน `import-dify/source` และ pull สิ่งที่ฉบับร่างต้องใช้ จากนั้นเรียกเครื่องมือ `validate` โดยตั้ง `workspace_root` เป็น `import-dify/source` และตั้ง `release` เป็น `release.yaml` และเรียกเครื่องมือ `build` โดยตั้ง `workspace_root` เป็น `import-dify/source` ตั้ง `release` เป็น `release.yaml` และตั้ง `write` เป็น true บอกฉันว่าบิลด์เขียนไฟล์ใดบ้าง ไฟล์เหล่านั้นอยู่ใต้ `import-dify/source/dist/`

เปิดใน VS Code

เปิดโฟลเดอร์ import-dify/source ใน VS Code ที่ติดตั้ง ส่วนขยาย Aggrega สำหรับ Visual Studio Code แล้ว ซึ่งการนำเข้าเขียนฉบับร่างไว้ที่นั่น โฟลเดอร์มี Release หนึ่งรายการ คือ release.yaml ที่ร่างไว้ ตัวแก้ไขจึงเลือกให้คุณ เมื่อขั้นตอนใน บน Docker Compose ร่าง Release ที่สองลงใน compose แล้ว Aggrega: Select Release… เลือก Release ที่ตัวแก้ไขใช้ทำงาน ตัวแก้ไขตรวจสอบฉบับร่างกับ Release ที่เลือกขณะที่คุณแก้ไข โดยทำเครื่องหมายสิ่งที่พบในไฟล์และในแผง Problems Aggrega: Show topology graph ใน Command Palette วาดส่วนประกอบของ Release ที่เลือกและการเชื่อมต่อระหว่างส่วนประกอบเหล่านั้น Aggrega: Build, Aggrega: Preview build และ Aggrega: Pull ทำงานกับ Release เดียวกัน และแต่ละรายการยังเป็นปุ่มบนแผง Commands ของมุมมอง Aggrega ในแถบกิจกรรม Build เขียนไฟล์ของตนลงใน dist/ ของโฟลเดอร์ ใช้ Aggrega ใน Visual Studio Code ครอบคลุมส่วนที่เหลือ

วิธีรัน

ก่อนนำแมนิเฟสต์ไปใช้ สร้าง Secrets ที่แมนิเฟสต์อ่าน เวิร์กโหลดที่ระบุ Secret ซึ่งไม่มีอยู่จะไม่เริ่มทำงาน Secrets สองรายการเก็บสิ่งที่ไฟล์คำตอบระบุ คือ dify-owner ซึ่งเก็บรหัสผ่านของเจ้าของภายใต้ value และ dify-credentials ซึ่งเก็บข้อมูลลับของแอปพลิเคชันภายใต้ secret-key ข้อมูลรับรองอื่นอีกสี่รายการของการติดตั้ง — รหัสผ่านฐานข้อมูลและคีย์สามคีย์ที่ส่วนประกอบของการติดตั้งแสดงต่อกัน — ใช้ค่าเริ่มต้นที่ core/dify กำหนด และบน Kubernetes ค่าเริ่มต้นแต่ละค่าคือชื่อของ Secret ที่แมนิเฟสต์อ่านค่านั้น ได้แก่ dify-db-password-for-evaluation-only ภายใต้ db-password, dify-code-execution-key-for-evaluation-only ภายใต้ code-execution-key, dify-plugin-daemon-key-for-evaluation-only ภายใต้ plugin-daemon-key และ dify-inner-api-key-for-evaluation-only ภายใต้ inner-api-key สร้าง Secrets อีกสี่รายการนั้นด้วย โดยแต่ละรายการเก็บค่าของคุณเอง หากต้องการอ่านจาก Secrets ที่ตั้งชื่ออื่น ส่งชื่อเหล่านั้นให้ core/dify ในรายการ dify ของ Aggregate ใต้ parameters เป็น db_password, code_execution_key, plugin_daemon_key และ inner_api_key

ตั้งรหัสผ่านของเจ้าของใน shell ของคุณเป็น DIFY_OWNER_PASSWORD เพราะคุณใช้รหัสผ่านนั้นลงชื่อเข้าใช้ด้านล่าง Dify รับรหัสผ่านของเจ้าของที่มีอย่างน้อยแปดอักขระและมีตัวอักษรกับตัวเลข: หากเป็นรหัสผ่านอื่น Job นำเข้าจะล้มเหลวทันทีที่ Dify ปฏิเสธการตั้งค่า และบันทึกของ Job อ่านว่า first-time setup was refused with HTTP 422: Validation error for parameter 'payload' ซึ่งเป็นการตอบกลับที่ Dify ให้แก่บัญชีเจ้าของที่ปฏิเสธ การรอด้านล่างรอให้ Job เสร็จสมบูรณ์ และ Job ที่ล้มเหลวไม่เสร็จสมบูรณ์เลย การรอจึงรันไปจนหมดเวลา รัน kubectl wait --for=condition=failed job/dify-zdapi-app-import --timeout=15m ในเทอร์มินัลที่สองข้างกัน แล้วการรอนั้นจะคืนค่าทันทีที่ Job ล้มเหลว ลบ Job และ Secret dify-owner สร้าง Secret ใหม่ด้วยรหัสผ่านที่ Dify รับ แล้วนำไปใช้อีกครั้ง

เขียนไฟล์ให้ Secrets อื่นอีกห้ารายการ รายการละหนึ่งไฟล์ แต่ละไฟล์มีหนึ่งบรรทัด คือคีย์ข้อมูล = และค่าของคุณเอง — dify-credentials.env พร้อม secret-key=, db-password.env พร้อม db-password=, code-execution-key.env พร้อม code-execution-key=, plugin-daemon-key.env พร้อม plugin-daemon-key= และ inner-api-key.env พร้อม inner-api-key= จากนั้นสร้าง Secrets หกรายการ เมื่อถึงตอนนั้นคลัสเตอร์เก็บค่าไว้แล้ว ลบไฟล์เหล่านั้น:

Terminal window
printf 'value=%s\n' "$DIFY_OWNER_PASSWORD" > dify-owner.env
kubectl create secret generic dify-owner --from-env-file=dify-owner.env
kubectl create secret generic dify-credentials --from-env-file=dify-credentials.env
kubectl create secret generic dify-db-password-for-evaluation-only --from-env-file=db-password.env
kubectl create secret generic dify-code-execution-key-for-evaluation-only --from-env-file=code-execution-key.env
kubectl create secret generic dify-plugin-daemon-key-for-evaluation-only --from-env-file=plugin-daemon-key.env
kubectl create secret generic dify-inner-api-key-for-evaluation-only --from-env-file=inner-api-key.env
rm dify-owner.env dify-credentials.env db-password.env code-execution-key.env plugin-daemon-key.env inner-api-key.env

นำแมนิเฟสต์ไปใช้ ตามที่ขั้นตอนรันของ วิธีที่การนำเข้าทำงาน อธิบาย — -R เข้าถึง Job และ ConfigMaps สองรายการใน dify.api/ และ dify.proxy/ — จากนั้นรอ Job นำเข้าและอ่านบันทึกของ Job แล้วรอรันไทม์ของปลั๊กอิน:

Terminal window
kubectl apply -R -f dist/boundaries/platform/helm/
kubectl wait --for=condition=complete job/dify-zdapi-app-import --timeout=15m
kubectl logs job/dify-zdapi-app-import
kubectl rollout status statefulset/dify-zdplugins
service/dify-zdapi-default created
deployment.apps/dify-zdapi created
[… omitted: a line for each of the other Services, Deployments and StatefulSets]
job.batch/dify-zdapi-app-import created
configmap/dify-zdapi-app created
configmap/dify-zdproxy-config created
job.batch/dify-zdapi-app-import condition met
first-time setup done: owner account owner@example.com
imported 'Support assistant' as application 7e03e85c-b13f-4ddc-b539-040470a61d4c
partitioned roll out complete: 1 new pods have been updated...

บันทึกบอกตัวระบุของแอปพลิเคชัน ซึ่ง ทดสอบ ต้องใช้

ทดสอบ

API ของ Dify ตอบที่ http://127.0.0.1:5001 บน Kubernetes ส่งต่อพอร์ตภายในเครื่องไปยัง Service ของเซิร์ฟเวอร์ API คือ dify-zdapi-default ในเนมสเปซที่คุณนำไปใช้ และเปิดคำสั่งไว้ในเทอร์มินัลที่สอง:

Terminal window
kubectl port-forward -n <namespace> svc/dify-zdapi-default 5001:5001

บน Docker Compose ที่เริ่มตามที่ บน Docker Compose แสดง Release เผยแพร่ API ที่ที่อยู่นั้นแล้ว และเผยแพร่คอนโซลที่ http://127.0.0.1:3001 เปิด http://127.0.0.1:3001/signin ซึ่งเป็นหน้าลงชื่อเข้าใช้ของคอนโซล / เปลี่ยนเส้นทางไปที่นั่น หน้านี้ส่งคำขอไปยัง API ที่ http://127.0.0.1:5001 และ API ของ Dify ตอบเบราว์เซอร์เฉพาะหน้าที่เสิร์ฟจากที่อยู่ที่ console_url ที่ร่างไว้ระบุ คือ http://127.0.0.1:3001 จึงลงชื่อเข้าใช้ที่นั่นในฐานะเจ้าของ หากเปิดที่ที่อยู่อื่น คำขอของคอนโซลจะไม่ได้รับการตอบกลับเช่นนั้น และเบราว์เซอร์ปฏิเสธการตอบกลับทุกรายการ เผยแพร่คอนโซลบนพอร์ตอื่นและเปลี่ยน console_url ตามไปด้วย

แอปพลิเคชันตอบผ่าน API ได้เช่นกัน โดยไม่ต้องใช้เบราว์เซอร์ ในเทอร์มินัลที่ตั้ง DIFY_OWNER_PASSWORD ไว้ ลงชื่อเข้าใช้ในฐานะเจ้าของ API ของคอนโซลรับรหัสผ่านที่เข้ารหัสแบบ Base64 และการลงชื่อเข้าใช้ทิ้งเซสชันไว้ใน cookies.txt คำขอคอนโซลทุกครั้งต่อจากนั้นส่งเซสชันกลับ พร้อมโทเค็น CSRF จากไฟล์เดียวกันในเฮดเดอร์ X-CSRF-Token คำขอที่ไม่มีโทเค็นนั้นจะถูกปฏิเสธด้วย CSRF token is missing or invalid.

Terminal window
printf '{"email": "owner@example.com", "password": "%s"}' "$(printf %s "$DIFY_OWNER_PASSWORD" | base64 | tr -d '\n')" |
curl -sS -c cookies.txt http://127.0.0.1:5001/console/api/login -H 'Content-Type: application/json' -d @-
CSRF=$(awk '$6 == "csrf_token" {print $7}' cookies.txt)
{"result":"success"}

ผู้ให้บริการโมเดลของ Dify เป็นปลั๊กอิน และการติดตั้งใหม่ไม่มีเลย ติดตั้งผู้ให้บริการ OpenAI ของ Dify เวอร์ชัน 1.1.0 ซึ่งเป็นตัวที่การรันนั้นติดตั้งไว้ รันไทม์ของปลั๊กอินดึงปลั๊กอินนี้จากตลาดของ Dify ที่ marketplace_enabled ที่ร่างไว้ทำให้การติดตั้งของ Dify เข้าถึงได้ การติดตั้งนั้นจึงต้องเข้าถึงอินเทอร์เน็ตได้:

Terminal window
curl -sS -b cookies.txt -H "X-CSRF-Token: $CSRF" -H 'Content-Type: application/json' \
http://127.0.0.1:5001/console/api/workspaces/current/plugin/install/marketplace \
-d '{"plugin_unique_identifiers": ["langgenius/openai:1.1.0@1ded02acee56efd5788c86fd447d792e4923e959554a4942f440c7859d164340"]}'
{"all_installed":false,"task_id":"01a1dc0a-653d-756b-a104-e5d6d1e43695","task":null}

เมื่อลบ marketplace_enabled ออกจาก Release Dify จะปฏิเสธคำขอแทน ด้วย {"code":"invalid_param","message":"marketplace is not enabled","status":400} การติดตั้งรันอยู่เบื้องหลัง ขอดูงานของการติดตั้งนั้นด้วย task_id ที่การตอบกลับระบุ จนกว่า status ของงานจะเป็น success:

Terminal window
curl -sS -b cookies.txt -H "X-CSRF-Token: $CSRF" \
http://127.0.0.1:5001/console/api/workspaces/current/plugin/tasks/<task id>
{"task":{"id":"01a1dc0a-653d-756b-a104-e5d6d1e43695",[… omitted: when it was created and last updated],"status":"success","total_plugins":1,"completed_plugins":1,"plugins":[{"plugin_unique_identifier":"langgenius\/openai:1.1.0@1ded02acee56efd5788c86fd447d792e4923e959554a4942f440c7859d164340",[… omitted: the plugin's status, its icon and its names in four languages]}]}}

เขียนคีย์ของผู้ให้บริการลงใน openai.json เป็น {"credentials": {"openai_api_key": "your OpenAI key"}} ตั้งค่าคีย์นั้น แล้วลบไฟล์:

Terminal window
curl -sS -b cookies.txt -H "X-CSRF-Token: $CSRF" -H 'Content-Type: application/json' \
http://127.0.0.1:5001/console/api/workspaces/current/model-providers/langgenius/openai/openai/credentials \
-d @openai.json
rm openai.json

Dify ตรวจสอบคีย์ด้วยคำขอหนึ่งครั้งไปยังผู้ให้บริการก่อนเก็บคีย์ และตอบ {"result":"success"} สำหรับคีย์ที่ผู้ให้บริการยอมรับ การรันตั้งตัวยึดตำแหน่งไว้ และ Dify ปฏิเสธด้วยคำตอบของ OpenAI:

{"code":"invalid_param","message":"Error code: 401 - {'error': {'message': 'Incorrect API key provided: sk-place*****************-key. You can find your API key at https:\/\/platform.openai.com\/account\/api-keys.', 'type': 'invalid_request_error', 'code': 'invalid_api_key', 'param': None}, 'status': 401}","status":400}

แอปพลิเคชันตอบคำขอที่ทำด้วยคีย์ API ของตนเอง สร้างคีย์หนึ่งคีย์ ด้วยตัวระบุของแอปพลิเคชันจากบันทึกของขั้นตอนที่นำเข้าแอปพลิเคชันนั้น — บน Docker Compose คือ docker compose -p support-assistant -f ../dist/boundaries/platform/compose/docker-compose.yaml logs dify-zdapi-app-import:

Terminal window
curl -sS -X POST -b cookies.txt -H "X-CSRF-Token: $CSRF" \
http://127.0.0.1:5001/console/api/apps/<application id>/api-keys
{"id":"8d6c1eb1-cf61-4825-9b04-f32689ed0489","type":"app","token":"[… omitted: the key]","last_used_at":null,"created_at":1794693042}

และส่งข้อความถึงแอปพลิเคชันด้วยคีย์นั้น ซึ่งคือ token ของการตอบกลับ:

Terminal window
curl -sS http://127.0.0.1:5001/v1/chat-messages \
-H 'Authorization: Bearer <app key>' -H 'Content-Type: application/json' \
-d '{"inputs": {}, "query": "In one short sentence: what does a support plan cover?", "response_mode": "blocking", "user": "test-it"}'

เมื่อตัวยึดตำแหน่งถูกปฏิเสธ โมเดลไม่มีคีย์ และ Dify บอกเช่นนั้น:

{"code":"provider_not_initialize","message":"Model gpt-4o-mini credentials is not initialized.","status":400}

การรันบน Kubernetes และบน Docker Compose ได้การตอบกลับเหมือนกัน เมื่อใช้คีย์ที่ผู้ให้บริการยอมรับ การตอบกลับมีคำตอบของโมเดลที่ answer

บน Kubernetes หยุดการส่งต่อพอร์ต จากนั้นลบสิ่งที่คุณนำไปใช้ Secrets และไฟล์เซสชัน:

Terminal window
kubectl delete -R -f dist/boundaries/platform/helm/
kubectl delete secret dify-owner dify-credentials dify-db-password-for-evaluation-only dify-code-execution-key-for-evaluation-only dify-plugin-daemon-key-for-evaluation-only dify-inner-api-key-for-evaluation-only
kubectl delete pvc data-dify-zddb-0 storage-dify-zdplugins-0 data-dify-zdvector-0
rm cookies.txt

Kubernetes เก็บ volume claim ที่ StatefulSet สร้างไว้เมื่อลบ StatefulSet คำสั่งที่สามจึงลบ claim เหล่านั้น และลบฐานข้อมูล ปลั๊กอินที่ติดตั้ง และที่จัดเก็บเวกเตอร์ไปด้วย บน Docker Compose docker compose -p support-assistant -f ../dist/boundaries/platform/compose/docker-compose.yaml down -v ลบสแตกและวอลุ่มของสแตก

บน Docker Compose

แอปพลิเคชันเดียวกันนำเข้าสำหรับ Docker Compose ได้ด้วยเป้าหมาย compose จากไฟล์คำตอบเดียวกัน ฉบับร่างสำหรับ Kubernetes อยู่ใน source แล้ว จึงร่างฉบับของ Compose ลงในโฟลเดอร์ของตนเองด้วย --output-dir การนำเข้ายังอ่านไฟล์คำตอบที่อยู่ข้างแอปพลิเคชันเหมือนเดิม:

Terminal window
aggrega import support-assistant.yml --target compose --output-dir compose

Docker Compose ไม่มี Secret ให้ระบุชื่อ ดังนั้นสำหรับ compose ฉบับร่างจึงเขียนข้อมูลลับของแอปพลิเคชันและรหัสผ่านของเจ้าของเอง โดยแต่ละรายการเป็นการอ้างอิงตัวแปรที่ Docker Compose เติมจากสภาพแวดล้อมของผู้ที่เริ่มสแตก ที่นั่นค้างอยู่เพียงอีเมลของเจ้าของ การนำเข้าเก็บชื่อ Secret สองชื่อไว้ในไฟล์คำตอบโดยไม่นำไปใช้ และบอกเรื่องนี้ทางข้อผิดพลาดมาตรฐาน:

info: the answers file <workspace>/import-answers.yaml also answers spec.boundaries.platform.aggregates.dify.components.api.features.owner_password.infra.origin in release.yaml, spec.parameters.secret_key in release.yaml, which these drafts do not leave empty; those answers are kept there and not applied

Release ที่ร่างไว้อ่านข้อมูลลับของแอปพลิเคชันจาก DIFY_SECRET_KEY และอ่านรหัสผ่านของเจ้าของจาก DIFY_OWNER_PASSWORD และเผยแพร่ API บนพอร์ต 5001 และฟรอนต์เอนด์ คือ console บนพอร์ต 3001 ของที่อยู่ loopback:

parameters:
# Passed by reference, never as a value: secret_key, which the drafted Aggregate declares and passes down to core/dify; that parameter's description there says what the value is; it is read from the variable DIFY_SECRET_KEY, which a target substituting variable references, as Docker Compose does when the stack starts, reads from the environment, so no file carries the value.
secret_key: "${DIFY_SECRET_KEY}"
[… omitted: the boundary, the marketplace switch, and the owner's email, answered as above]
# 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: 5001
console_url: "http://127.0.0.1:3001"
features:
owner_password:
type: core/referenced-secret
infra:
# Attached by reference, never as a value: the owner account's password, read from the variable DIFY_OWNER_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: "${DIFY_OWNER_PASSWORD}"
[… omitted: the worker and the scheduler, each with the marketplace switch, as above]
console:
infra:
# 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: 3001

แต่ละพอร์ตเข้าถึงได้จากเครื่องของคุณเท่านั้น ตามที่ความคิดเห็นของพอร์ตนั้นบอก และการลบบรรทัดหนึ่งทำให้บริการนั้นอยู่บนเครือข่ายของสแตกเท่านั้น ฟรอนต์เอนด์รับฟังที่พอร์ต 3000 ภายในคอนเทนเนอร์ของตนและเผยแพร่บนพอร์ต 3001 จึงรันได้ข้างตัวอย่างอื่นที่เผยแพร่พอร์ต 3000 console_url ของเซิร์ฟเวอร์ API คือที่อยู่ที่ฟรอนต์เอนด์เผยแพร่ พอร์ตที่คุณเปลี่ยนสำหรับฟรอนต์เอนด์จึงเปลี่ยนที่นั่นด้วย

Manifest แมปส่วนประกอบแต่ละรายการไปยัง Recipe ของ Compose และแมป core/referenced-secret ไปยัง compose/dotenv-referenced-secret ซึ่งเขียนการอ้างอิงแต่ละรายการลงในไฟล์ Compose ตามที่เป็นอยู่ ตรวจสอบความถูกต้องและบิลด์จากโฟลเดอร์ใหม่:

Terminal window
cd compose
aggrega validate --release release.yaml
aggrega build --release release.yaml

บิลด์เขียนใต้ dist ที่รูทของพื้นที่ทำงาน และพื้นที่ทำงานยังคงเป็น source ซึ่งเป็นโฟลเดอร์ที่เก็บ .aggrega-config.yaml: ไฟล์ Compose คือ source/dist/boundaries/platform/compose/docker-compose.yaml ซึ่งจาก compose คือ ../dist/boundaries/platform/compose/docker-compose.yaml และบิลด์ไม่เขียนโฟลเดอร์ dist ภายใน compose เลย ไฟล์นี้มี SECRET_KEY: ${DIFY_SECRET_KEY} และ OWNER_PASSWORD: ${DIFY_OWNER_PASSWORD} แทนที่จะเป็นค่าใดค่าหนึ่ง ตั้งตัวแปรทั้งสองใน shell ของคุณ หรือในไฟล์ .env ข้างไฟล์ Compose ก่อนเริ่มสแตก

ข้อมูลรับรองอื่นอีกสี่รายการของการติดตั้งใช้ค่าเริ่มต้นที่ core/dify กำหนด และบน Docker Compose ค่าเริ่มต้นแต่ละค่าคือค่านั้นเอง เขียนลงในไฟล์ Compose ตามที่เป็นอยู่ ได้แก่ DB_PASSWORD: dify-db-password-for-evaluation-only โดย POSTGRES_PASSWORD บนฐานข้อมูลเป็นค่าเดียวกัน และเช่นเดียวกันกับ dify-code-execution-key-for-evaluation-only, dify-plugin-daemon-key-for-evaluation-only และ dify-inner-api-key-for-evaluation-only ผู้อ่านแค็ตตาล็อกทุกคนรู้ค่าเริ่มต้นเหล่านี้ ค่าเหล่านี้จึงมีไว้เพื่อการประเมินเท่านั้น หากต้องการแทนที่ค่าใดค่าหนึ่ง ประกาศพารามิเตอร์ชนิดสตริงสำหรับค่านั้นใน Aggregate ที่ร่างไว้ ส่งต่อลงไปในรายการ dify ใต้ parameters ภายใต้ชื่อที่ core/dify ใช้สำหรับค่านั้น — db_password, code_execution_key, plugin_daemon_key หรือ inner_api_key — เหมือนที่ฉบับร่างส่ง secret_key และระบุค่าภายใต้ parameters ของ Release Release ที่เขียน db_password: "${DIFY_DB_PASSWORD}" จะบิลด์ไฟล์ Compose ที่มี DB_PASSWORD: ${DIFY_DB_PASSWORD} และ POSTGRES_PASSWORD: ${DIFY_DB_PASSWORD} ซึ่งเติมจากสภาพแวดล้อมเหมือนสองค่าข้างต้น

เริ่มสแตกจาก compose โดยใช้รหัสผ่านของเจ้าของที่ Dify รับ ดังที่ วิธีรัน อธิบาย:

Terminal window
export DIFY_SECRET_KEY='a long random value of your own'
export DIFY_OWNER_PASSWORD='a password of your own'
docker compose -p support-assistant -f ../dist/boundaries/platform/compose/docker-compose.yaml up -d --wait

--wait คืนค่าในเวลาประมาณหนึ่งนาทีในการรัน เมื่อทุกเซิร์ฟเวอร์รายงานว่าทำงานปกติ ขั้นตอนที่นำเข้าแอปพลิเคชันรันควบคู่กันและออกเมื่อนำเข้าเสร็จ บันทึกของขั้นตอนนั้นจึงอ่านว่า:

first-time setup done: owner account owner@example.com
imported 'Support assistant' as application 7fae73f4-826b-4918-a623-a3383aa0da8c

ทดสอบ เข้าถึงการติดตั้งที่พอร์ตที่เผยแพร่สองพอร์ต