From 0e7444835cf54fad08cff6910b2e8c6d51c92d39 Mon Sep 17 00:00:00 2001 From: adohe Date: Tue, 5 Dec 2023 22:25:47 +0800 Subject: [PATCH] feat: update base example applications --- .gitignore | 4 +- README-zh.md | 18 -------- README.md | 12 +++-- example/multi-stack/README.md | 45 ------------------- example/multi-stack/dev/kcl.mod.lock | 8 ---- example/multi-stack/dev/main.k | 14 ------ example/multi-stack/prod/kcl.mod.lock | 8 ---- example/multi-stack/prod/main.k | 14 ------ example/nginx/dev/kcl.mod.lock | 8 ---- example/{nginx/dev => samplejob/prod}/kcl.mod | 2 +- example/samplejob/prod/main.k | 16 +++++++ .../prod/stack.yaml | 0 example/{nginx => samplejob}/project.yaml | 2 +- .../base/base.k | 10 ++--- .../prod => service-multistack/dev}/kcl.mod | 2 +- example/service-multistack/dev/main.k | 9 ++++ .../dev/stack.yaml | 0 .../dev => service-multistack/prod}/kcl.mod | 2 +- example/service-multistack/prod/main.k | 16 +++++++ .../prod}/stack.yaml | 2 +- example/service-multistack/project.yaml | 4 ++ example/simpleservice/prod/kcl.mod | 10 +++++ .../{nginx/dev => simpleservice/prod}/main.k | 16 +++---- example/simpleservice/prod/stack.yaml | 2 + .../project.yaml | 2 +- example/wordpress/dev/kcl.mod.lock | 8 ---- example/wordpress/dev/main.k | 2 + hack/lib/common.py | 1 + hack/test_correctness.py | 2 +- 29 files changed, 85 insertions(+), 154 deletions(-) delete mode 100644 README-zh.md delete mode 100644 example/multi-stack/README.md delete mode 100644 example/multi-stack/dev/kcl.mod.lock delete mode 100644 example/multi-stack/dev/main.k delete mode 100644 example/multi-stack/prod/kcl.mod.lock delete mode 100644 example/multi-stack/prod/main.k delete mode 100644 example/nginx/dev/kcl.mod.lock rename example/{nginx/dev => samplejob/prod}/kcl.mod (90%) create mode 100644 example/samplejob/prod/main.k rename example/{multi-stack => samplejob}/prod/stack.yaml (100%) rename example/{nginx => samplejob}/project.yaml (78%) rename example/{multi-stack => service-multistack}/base/base.k (71%) rename example/{multi-stack/prod => service-multistack/dev}/kcl.mod (87%) create mode 100644 example/service-multistack/dev/main.k rename example/{multi-stack => service-multistack}/dev/stack.yaml (100%) rename example/{multi-stack/dev => service-multistack/prod}/kcl.mod (87%) create mode 100644 example/service-multistack/prod/main.k rename example/{nginx/dev => service-multistack/prod}/stack.yaml (69%) create mode 100644 example/service-multistack/project.yaml create mode 100644 example/simpleservice/prod/kcl.mod rename example/{nginx/dev => simpleservice/prod}/main.k (57%) create mode 100644 example/simpleservice/prod/stack.yaml rename example/{multi-stack => simpleservice}/project.yaml (75%) delete mode 100644 example/wordpress/dev/kcl.mod.lock diff --git a/.gitignore b/.gitignore index df856c9b..5d173842 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,6 @@ report/ kusion_state.json -changed_list.txt \ No newline at end of file +changed_list.txt + +*.lock \ No newline at end of file diff --git a/README-zh.md b/README-zh.md deleted file mode 100644 index 0243ee67..00000000 --- a/README-zh.md +++ /dev/null @@ -1,18 +0,0 @@ -# Konfig - -[![用 GitHub Codespaces 打开](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=488867056&machine=standardLinux32gb&devcontainer_path=.devcontainer.json) - - -[英语](README.md) | [中文](README-zh.md) - -这是 [Kusion](https://github.com/KusionStack/kusion) 的示例仓库,你可以使用这里的示例来快速学习如何使用 Kusion - -## 快速开始 - -如果你第一次接触 Kusion,请访问 [快速开始](https://kusionstack.io/docs/user_docs/getting-started/) 页面来了解 Kusion,里面包含了安装、快速开始、以及一些基础概念。 - -所有的示例都放在了 `example` 目录下,他们都可以在[用户指南](https://kusionstack.io/docs/user_docs/guides/)中找到对应的教程。 - -## 部署示例 - -你可以在不同示例目录中执行 `kusion apply`` 命令来部署不同的示例,其中部分示例有前置条件,比如一个可访问的 Kubernetes 集群,或者某个云厂商的账号,具体前置条件需要参考[用户指南](https://kusionstack.io/docs/user_docs/guides/)中的教程。 \ No newline at end of file diff --git a/README.md b/README.md index 3f97ea68..a17483dc 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,14 @@ -# Konfig +# konfig [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=488867056&machine=standardLinux32gb&devcontainer_path=.devcontainer.json) -[English](README.md) | [Chinese](README-zh.md) - -This is a example repository for [Kusion](https://github.com/KusionStack/kusion), where you can use the examples provided to quickly learn how to use Kusion. +konfig repository contains various example applications code, you can use these example applications to quickly try out and learn how to use [Kusion](https://github.com/KusionStack/kusion). ## Getting Started -If you are new to Kusion, please visit [Getting Started](https://kusionstack.io/docs/user_docs/getting-started/) to learn about Kusion. It includes installation instructions, quick start guide, and some basic concepts. +If you're new to Kusion, start by reviewing the [Getting Started](https://www.kusionstack.io/docs/user_docs/getting-started/) page, which includes quickstart installation, guided tutorials and deployment instructions. -All the examples are located in the `example`` directory, and you can find corresponding tutorials in the [User Guide](https://kusionstack.io/docs/user_docs/guides/). +All guided tutorials use applications in this repository, located in the `example` directory. ## Deploying Examples -You can execute the `kusion apply` command in different example directories to deploy different examples. Some examples have prerequisites, such as an accessible Kubernetes cluster or an account of a specific cloud provider. Please refer to the tutorials in the [User Guide](https://kusionstack.io/docs/user_docs/guides/) for specific prerequisites. \ No newline at end of file +You can experiment with the different examples by entering each directory and running `kusion apply`. Some examples have prerequisites, e.g. accessible Kubernetes cluster or account for cloud provider. Please refer to guided tutorials in the [User Guide](https://www.kusionstack.io/docs/user_docs/guides/) for specific prerequisites. \ No newline at end of file diff --git a/example/multi-stack/README.md b/example/multi-stack/README.md deleted file mode 100644 index 77ccb330..00000000 --- a/example/multi-stack/README.md +++ /dev/null @@ -1,45 +0,0 @@ -# 前言 -> 本 README.md 包括配置代码仓库目录/文件说明及如何本地使用 Kusion+Minikube 进行测试 - -## 快速开始 -```bash -$ cd dev -$ kusion apply -SUCCESS Compiling in stack dev... - -Stack: dev Provider Type ID Plan - * ├─ kubernetes v1:Namespace demo Create - * ├─ kubernetes v1:Service frontend-service Create - * └─ kubernetes apps/v1:Deployment demodev Create - -✔ yes -Start applying diffs...... -SUCCESS Creating Namespace/demo -SUCCESS Creating Service/frontend-service -SUCCESS Creating Deployment/demodev -Creating Deployment/demodev [3/3] ████████████████████████████████ 100% | 0s - -$ minikube service frontend-service -n demo --url -http://192.168.99.102:31964 - -$ curl -s http://192.168.99.102:31964 | grep title # Or visit http://192.168.99.102:31964 in browser - Guestbook - -$ kusion destroy -``` - -## 目录和文件说明 -```bash -. -├── base // 各环境通用配置 -│ ├── base.k // 应用的环境通用配置 -├── prod // 环境目录 -│ └── ci-test // ci 测试目录,放置测试脚本和数据 -│ └── settings.yaml // 测试数据和编译文件配置 -│ └── stdout.golden.yaml // 期望的 YAML,可通过 make 更新 -│ └── kcl.yaml // 当前 Stack 的多文件编译配置 -│ └── main.k // 应用在当前环境的配置清单 -│ └── stack.yaml // Stack 元信息 -└── project.yaml // Project 元信息 -└── README.md // 说明文档 -``` \ No newline at end of file diff --git a/example/multi-stack/dev/kcl.mod.lock b/example/multi-stack/dev/kcl.mod.lock deleted file mode 100644 index faa7c9c7..00000000 --- a/example/multi-stack/dev/kcl.mod.lock +++ /dev/null @@ -1,8 +0,0 @@ -[dependencies] - [dependencies.catalog] - name = "catalog" - full_name = "catalog_0.1.0" - version = "0.1.0" - sum = "9nAzXsUVVbIJieEc+8x97Sb7AxfdU7RyEm5mNYLTP3M=" - url = "https://github.com/KusionStack/catalog.git" - git_tag = "0.1.0" diff --git a/example/multi-stack/dev/main.k b/example/multi-stack/dev/main.k deleted file mode 100644 index 805e2565..00000000 --- a/example/multi-stack/dev/main.k +++ /dev/null @@ -1,14 +0,0 @@ -import catalog.models.schema.v1 as ac - -# main.k declares customized configurations for dev stack. -helloworld: ac.AppConfiguration { - workload.replicas = 2 - workload.containers.helloworld: { - # dev stack has different app configuration - image = "nginx:1.14.2" - resources = { - "cpu": "250m" - "memory": "256Mi" - } - } -} \ No newline at end of file diff --git a/example/multi-stack/prod/kcl.mod.lock b/example/multi-stack/prod/kcl.mod.lock deleted file mode 100644 index faa7c9c7..00000000 --- a/example/multi-stack/prod/kcl.mod.lock +++ /dev/null @@ -1,8 +0,0 @@ -[dependencies] - [dependencies.catalog] - name = "catalog" - full_name = "catalog_0.1.0" - version = "0.1.0" - sum = "9nAzXsUVVbIJieEc+8x97Sb7AxfdU7RyEm5mNYLTP3M=" - url = "https://github.com/KusionStack/catalog.git" - git_tag = "0.1.0" diff --git a/example/multi-stack/prod/main.k b/example/multi-stack/prod/main.k deleted file mode 100644 index b31ca5bb..00000000 --- a/example/multi-stack/prod/main.k +++ /dev/null @@ -1,14 +0,0 @@ -import catalog.models.schema.v1 as ac - -# main.k declares customized configurations for dev stack. -helloworld: ac.AppConfiguration { - workload.replicas = 3 - workload.containers.helloworld: { - # dev stack has different app configuration - image = "nginx:1.14.2" - resources = { - "cpu": "250m" - "memory": "256Mi" - } - } -} \ No newline at end of file diff --git a/example/nginx/dev/kcl.mod.lock b/example/nginx/dev/kcl.mod.lock deleted file mode 100644 index 616536f9..00000000 --- a/example/nginx/dev/kcl.mod.lock +++ /dev/null @@ -1,8 +0,0 @@ -[dependencies] - [dependencies.catalog] - name = "catalog" - full_name = "catalog_0.1.1" - version = "0.1.1" - sum = "IYND73UKWuS/hWpVqxvZfxTxx7z8bVbTuFbEx1OuJNk=" - url = "https://github.com/KusionStack/catalog.git" - git_tag = "0.1.1" diff --git a/example/nginx/dev/kcl.mod b/example/samplejob/prod/kcl.mod similarity index 90% rename from example/nginx/dev/kcl.mod rename to example/samplejob/prod/kcl.mod index 9cfcf0c1..ce318161 100644 --- a/example/nginx/dev/kcl.mod +++ b/example/samplejob/prod/kcl.mod @@ -1,5 +1,5 @@ [package] -name = "nginx" +name = "samplejob" edition = "0.1.0" version = "0.1.0" diff --git a/example/samplejob/prod/main.k b/example/samplejob/prod/main.k new file mode 100644 index 00000000..13cecce6 --- /dev/null +++ b/example/samplejob/prod/main.k @@ -0,0 +1,16 @@ +import catalog.models.schema.v1 as ac +import catalog.models.schema.v1.workload as wl +import catalog.models.schema.v1.workload.container as c + +samplejob: ac.AppConfiguration { + workload: wl.Job { + containers: { + "busybox": c.Container { + # The target image + image: "busybox:1.28" + # Run the following command as defined + command: ["/bin/sh", "-c", "echo hello"] + } + } + } +} \ No newline at end of file diff --git a/example/multi-stack/prod/stack.yaml b/example/samplejob/prod/stack.yaml similarity index 100% rename from example/multi-stack/prod/stack.yaml rename to example/samplejob/prod/stack.yaml diff --git a/example/nginx/project.yaml b/example/samplejob/project.yaml similarity index 78% rename from example/nginx/project.yaml rename to example/samplejob/project.yaml index 3232cbbc..17219469 100644 --- a/example/nginx/project.yaml +++ b/example/samplejob/project.yaml @@ -1,4 +1,4 @@ # The project basic info -name: nginx +name: samplejob generator: type: AppConfiguration \ No newline at end of file diff --git a/example/multi-stack/base/base.k b/example/service-multistack/base/base.k similarity index 71% rename from example/multi-stack/base/base.k rename to example/service-multistack/base/base.k index 31302774..f786d502 100644 --- a/example/multi-stack/base/base.k +++ b/example/service-multistack/base/base.k @@ -3,21 +3,21 @@ import catalog.models.schema.v1.workload as wl import catalog.models.schema.v1.workload.network as n import catalog.models.schema.v1.workload.container as c -helloworld: ac.AppConfiguration { +echoserver: ac.AppConfiguration { workload: wl.Service { containers: { - "helloworld": c.Container { + "server": c.Container { image = "" resources: { - "cpu": "500m" - "memory": "512Mi" + "cpu": "250m" + "memory": "256Mi" } } } replicas: 1 ports: [ n.Port { - port: 8080 + port: 80 } ] } diff --git a/example/multi-stack/prod/kcl.mod b/example/service-multistack/dev/kcl.mod similarity index 87% rename from example/multi-stack/prod/kcl.mod rename to example/service-multistack/dev/kcl.mod index bf9b4c6a..87e91525 100644 --- a/example/multi-stack/prod/kcl.mod +++ b/example/service-multistack/dev/kcl.mod @@ -1,5 +1,5 @@ [package] -name = "multi-stack" +name = "service-multistack" edition = "0.5.0" version = "0.1.0" diff --git a/example/service-multistack/dev/main.k b/example/service-multistack/dev/main.k new file mode 100644 index 00000000..a58d21e3 --- /dev/null +++ b/example/service-multistack/dev/main.k @@ -0,0 +1,9 @@ +import catalog.models.schema.v1 as ac + +# main.k declares customized configurations for dev stack. +echoserver: ac.AppConfiguration { + workload.containers.server: { + # dev stack use latest echoserver image + image = "cilium/echoserver" + } +} \ No newline at end of file diff --git a/example/multi-stack/dev/stack.yaml b/example/service-multistack/dev/stack.yaml similarity index 100% rename from example/multi-stack/dev/stack.yaml rename to example/service-multistack/dev/stack.yaml diff --git a/example/multi-stack/dev/kcl.mod b/example/service-multistack/prod/kcl.mod similarity index 87% rename from example/multi-stack/dev/kcl.mod rename to example/service-multistack/prod/kcl.mod index bf9b4c6a..87e91525 100644 --- a/example/multi-stack/dev/kcl.mod +++ b/example/service-multistack/prod/kcl.mod @@ -1,5 +1,5 @@ [package] -name = "multi-stack" +name = "service-multistack" edition = "0.5.0" version = "0.1.0" diff --git a/example/service-multistack/prod/main.k b/example/service-multistack/prod/main.k new file mode 100644 index 00000000..d6ba9317 --- /dev/null +++ b/example/service-multistack/prod/main.k @@ -0,0 +1,16 @@ +import catalog.models.schema.v1 as ac + +# main.k declares customized configurations for prod stack. +helloworld: ac.AppConfiguration { + # replicas is 2 for prod + workload.replicas = 2 + workload.containers.server: { + # prod stack use older stable echoserver image + image = "cilium/echoserver:1.10.3" + # also prod stack require more resources + resources = { + "cpu": "500m" + "memory": "512Mi" + } + } +} \ No newline at end of file diff --git a/example/nginx/dev/stack.yaml b/example/service-multistack/prod/stack.yaml similarity index 69% rename from example/nginx/dev/stack.yaml rename to example/service-multistack/prod/stack.yaml index 2b0941bc..0db97e71 100644 --- a/example/nginx/dev/stack.yaml +++ b/example/service-multistack/prod/stack.yaml @@ -1,2 +1,2 @@ # The stack basic info -name: dev \ No newline at end of file +name: prod \ No newline at end of file diff --git a/example/service-multistack/project.yaml b/example/service-multistack/project.yaml new file mode 100644 index 00000000..83874226 --- /dev/null +++ b/example/service-multistack/project.yaml @@ -0,0 +1,4 @@ +# The project basic info +name: service-multistack +generator: + type: AppConfiguration \ No newline at end of file diff --git a/example/simpleservice/prod/kcl.mod b/example/simpleservice/prod/kcl.mod new file mode 100644 index 00000000..2767bf68 --- /dev/null +++ b/example/simpleservice/prod/kcl.mod @@ -0,0 +1,10 @@ +[package] +name = "simpleservice" +edition = "0.1.0" +version = "0.1.0" + +[dependencies] +catalog = { git = "https://github.com/KusionStack/catalog.git", tag = "0.1.1" } +[profile] +entries = ["main.k"] + diff --git a/example/nginx/dev/main.k b/example/simpleservice/prod/main.k similarity index 57% rename from example/nginx/dev/main.k rename to example/simpleservice/prod/main.k index 89cc8da6..20a14bda 100644 --- a/example/nginx/dev/main.k +++ b/example/simpleservice/prod/main.k @@ -1,13 +1,15 @@ import catalog.models.schema.v1 as ac import catalog.models.schema.v1.workload as wl import catalog.models.schema.v1.workload.container as c -import catalog.models.schema.v1.workload.network as n -nginx: ac.AppConfiguration { +# main.k declares desired configurations for prod stack. +simplesvc: ac.AppConfiguration { workload: wl.Service { containers: { - nginx: c.Container { + "nginx": c.Container { + # use nginx:1.25.2 as target image image = "nginx:1.25.2" + # resource requirements for nginx container resources: { "cpu": "500m" "memory": "512Mi" @@ -15,13 +17,5 @@ nginx: ac.AppConfiguration { } } replicas: 1 - ports: [ - n.Port { - type: "aliyun" - port: 80 - protocol: "TCP" - public: True - } - ] } } \ No newline at end of file diff --git a/example/simpleservice/prod/stack.yaml b/example/simpleservice/prod/stack.yaml new file mode 100644 index 00000000..0db97e71 --- /dev/null +++ b/example/simpleservice/prod/stack.yaml @@ -0,0 +1,2 @@ +# The stack basic info +name: prod \ No newline at end of file diff --git a/example/multi-stack/project.yaml b/example/simpleservice/project.yaml similarity index 75% rename from example/multi-stack/project.yaml rename to example/simpleservice/project.yaml index effacf39..a3123d9f 100644 --- a/example/multi-stack/project.yaml +++ b/example/simpleservice/project.yaml @@ -1,4 +1,4 @@ # The project basic info -name: multi-stack +name: simpleservice generator: type: AppConfiguration \ No newline at end of file diff --git a/example/wordpress/dev/kcl.mod.lock b/example/wordpress/dev/kcl.mod.lock deleted file mode 100644 index faa7c9c7..00000000 --- a/example/wordpress/dev/kcl.mod.lock +++ /dev/null @@ -1,8 +0,0 @@ -[dependencies] - [dependencies.catalog] - name = "catalog" - full_name = "catalog_0.1.0" - version = "0.1.0" - sum = "9nAzXsUVVbIJieEc+8x97Sb7AxfdU7RyEm5mNYLTP3M=" - url = "https://github.com/KusionStack/catalog.git" - git_tag = "0.1.0" diff --git a/example/wordpress/dev/main.k b/example/wordpress/dev/main.k index 32024a74..d7344f6c 100644 --- a/example/wordpress/dev/main.k +++ b/example/wordpress/dev/main.k @@ -10,6 +10,7 @@ import catalog.models.schema.v1.accessories.database as db # main.k declares reusable configurations for all stacks. wordpress: ac.AppConfiguration { + # the main workload configurations workload: wl.Service { containers: { wordpress: c.Container { @@ -31,6 +32,7 @@ wordpress: ac.AppConfiguration { } ] } + # database accessory configurations database: db.Database { type: "alicloud" engine: "MySQL" diff --git a/hack/lib/common.py b/hack/lib/common.py index 263c578b..efcdb944 100644 --- a/hack/lib/common.py +++ b/hack/lib/common.py @@ -15,6 +15,7 @@ NAME = "name" KUSION_CMD = "kusion" COMPILE_CMD = "compile" +BUILD_CMD = "build" PREVIEW_CMD = "preview" APPLY_CMD = "apply" NO_STYLE_FLAG = "--no-style" diff --git a/hack/test_correctness.py b/hack/test_correctness.py index 760ad677..d21f4767 100644 --- a/hack/test_correctness.py +++ b/hack/test_correctness.py @@ -14,7 +14,7 @@ def test_correctness(stack_dir): print(f"Ignore stack {stack_dir}.") return print(f"Test correctness of stack {stack_dir}...") - cmd = [KUSION_CMD, COMPILE_CMD] + cmd = [KUSION_CMD, BUILD_CMD] process = subprocess.run( cmd, capture_output=True, cwd=Path(stack_dir), env=dict(os.environ) )