Skip to content

Commit dac136b

Browse files
authored
Merge pull request #156 from zong-zhe/kpm-push-ci
doc: add docs for 'kpm push by github action'
2 parents 1e27769 + 1f8e39a commit dac136b

File tree

81 files changed

+1630
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1630
-10
lines changed
File renamed without changes.
File renamed without changes.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Push Your KCL Package by GitHub Action
2+
3+
[kpm](https://github.com/KusionStack/kpm) is a tool for managing kcl packages. This article will guide you how to use kpm in GitHub Action to push your kcl package to OCI registry.
4+
5+
## Step 1: Install kpm
6+
7+
At first, you need to install kpm on your computer. You can follow [kpm installation document](https://kcl-lang.io/docs/user_docs/guides/package-management/installation).
8+
9+
## Step 2: Create a GitHub account
10+
11+
If you already have a GitHub account, you can skip this step.
12+
13+
[Sign up for a new GitHub account](https://docs.github.com/en/get-started/signing-up-for-github/signing-up-for-a-new-github-account)
14+
15+
## Step 3: Create a GitHub repository for your KCL package
16+
17+
### 1. Prepare a GitHub repository for your KCL package
18+
19+
You need to prepare a GitHub repository for your KCL package.
20+
21+
[Create a GitHub repository](https://docs.github.com/en/get-started/quickstart/create-a-repo)
22+
23+
In this repository, add your KCL program, take the repository https://github.com/awesome-kusion/catalog.git as an example,
24+
25+
```bash
26+
├── .github
27+
│ └── workflows
28+
│ └── push.yaml # github action workflow
29+
├── LICENSE
30+
├── README.md
31+
├── kcl.mod # kcl.mod to define your kcl package
32+
├── kcl.mod.lock # kcl.mod.lock generated by kpm
33+
└── main.k # Your KCL program
34+
```
35+
36+
### 2. Set OCI Registry, account and password for your Github repository
37+
38+
Take docker.io as an example, you can set secrets `REG`, `REG_ACCOUNT` and `REG_TOKEN` for your repository. The value of `REG` is `docker.io`, the value of `REG_ACCOUNT` is your `docker.io` account, and the value of `REG_TOKEN` is your `docker.io` login password.
39+
40+
[Add secrets to the repository](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository)
41+
42+
If you use `ghcr.io` as `Registry`, you need to use GitHub token as secrets.
43+
44+
[Create a GitHub Token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#personal-access-tokens-classic)
45+
46+
## Step 4: Add your KCL package to the repository and write github action workflow
47+
48+
Add github action file `.github/workflows/push.yml` to this repository, the content is as follows:
49+
50+
```yaml
51+
name: KPM Push Workflow
52+
53+
on:
54+
push:
55+
branches:
56+
- main
57+
58+
jobs:
59+
build:
60+
runs-on: ubuntu-latest
61+
steps:
62+
- name: Checkout
63+
uses: actions/checkout@v2
64+
65+
- name: Set up Go 1.19
66+
uses: actions/setup-go@v2
67+
with:
68+
go-version: 1.19
69+
70+
- name: Install kpm
71+
run: go install kcl-lang.io/kpm@latest
72+
73+
- name: Login and Push
74+
env:
75+
KPM_REG: ${{ secrets.REG }}
76+
KPM_REPO: ${{ secrets.REG_ACCOUNT }}
77+
run: kpm login -u ${{ secrets.REG_ACCOUNT }} -p ${{ secrets.REG_TOKEN }} ${{ secrets.REG }} && kpm push
78+
79+
- name: Run kpm project from oci registry
80+
run: kpm run oci://${{ secrets.REG }}/${{ secrets.REG_ACCOUNT }}/catalog --tag 0.0.1
81+
82+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"label": "How to",
3+
"position": 4
4+
}

i18n/zh-CN/docusaurus-plugin-content-docs/current.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
"sidebar.user_docs.category.Package Management": {
2121
"message": "包管理工具"
2222
},
23+
"sidebar.user_docs.category.How to": {
24+
"message": "如何使用"
25+
},
2326
"sidebar.user_docs.category.Schema Definition": {
2427
"message": "模型定义"
2528
},
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# 如何在 github action 中使用 kpm 发布您的 KCL 包
2+
3+
[kpm](https://github.com/KusionStack/kpm) 是一个用于管理 kcl 包的工具。本文将指导您如何在 GitHub Action 中使用 kpm 将您的 kcl 包推送到发布到 ghcr.io 中。
4+
5+
下面是一个简单的步骤,指导您如何使用 kpm 将您的 kcl 包推送到 OCI Registry。
6+
7+
## 步骤 1:安装 kpm
8+
9+
首先,您需要在您的计算机上安装 kpm。您可以按照 [kpm 安装文档](https://kcl-lang.io/docs/user_docs/guides/package-management/installation)中的说明进行操作。
10+
11+
## 步骤 2:创建一个 GitHub 账号
12+
13+
如果您已经有 GitHub 帐号了,您可以选择跳过这一步
14+
15+
[注册新的一个 GitHub 账号](https://docs.github.com/zh/get-started/signing-up-for-github/signing-up-for-a-new-github-account)
16+
17+
## 步骤 3: 为您的 KCL 包创建一个 GitHub 仓库并进行相关配置
18+
19+
### 1. 为您的 KCL 程序包准备仓库
20+
您需要为您的 KCL 程序包准备一个 GitHub 仓库。
21+
22+
[创建一个 GitHub 仓库](https://docs.github.com/zh/get-started/quickstart/create-a-repo)
23+
24+
25+
在这个仓库中添加您的 KCL 程序,以仓库 https://github.com/awesome-kusion/catalog.git 为例,
26+
27+
```bash
28+
├── .github
29+
│ └── workflows
30+
│ └── push.yaml # github action 文件
31+
├── LICENSE
32+
├── README.md
33+
├── kcl.mod # kcl.mod 将当前仓库内容定义为一个 kcl 包
34+
├── kcl.mod.lock # kcl.mod.lock 是 kpm 自动生成的文件
35+
└── main.k # 您的 KCL 程序
36+
```
37+
38+
### 2. 为您的仓库设置 OCI Registry,账户和密码
39+
40+
以 docker.io 为例,您可以为您的仓库设置 secrets `REG`, `REG_ACCOUNT``REG_TOKEN``REG` 的值为 `docker.io``REG_ACCOUNT` 的值为您的 docker.io 账户, `REG_TOKEN` 为您的 `docker.io` 登录密码。
41+
42+
[为仓库添加 secrets](https://docs.github.com/zh/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository)
43+
44+
如果您使用 `ghcr.io` 作为 `Registry`, 您需要使用 GitHub token 作为 secrets。
45+
46+
[创建一个 GitHub Token](https://docs.github.com/zh/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#personal-access-tokens-classic)
47+
48+
49+
## 步骤 4: 将您的 KCL 包添加到仓库中并编写 github action workflow
50+
51+
为这个仓库添加 github action 文件 `.github/workflows/push.yml`,内容如下:
52+
53+
```yaml
54+
name: KPM Push Workflow
55+
56+
on:
57+
push:
58+
branches:
59+
- main
60+
61+
jobs:
62+
build:
63+
runs-on: ubuntu-latest
64+
steps:
65+
- name: Checkout
66+
uses: actions/checkout@v2
67+
68+
- name: Set up Go 1.19
69+
uses: actions/setup-go@v2
70+
with:
71+
go-version: 1.19
72+
73+
- name: Install kpm
74+
run: go install kcl-lang.io/kpm@latest
75+
76+
- name: Login and Push
77+
env:
78+
# 通过环境变量指定 OCI Registry 和账户
79+
KPM_REG: ${{ secrets.REG }}
80+
KPM_REPO: ${{ secrets.REG_ACCOUNT }}
81+
# kpm login 时使用 secrets.REG_TOKEN
82+
run: kpm login -u ${{ secrets.REG_ACCOUNT }} -p ${{ secrets.REG_TOKEN }} ${{ secrets.REG }} && kpm push
83+
84+
- name: Run kpm project from oci registry
85+
run: kpm run oci://${{ secrets.REG }}/${{ secrets.REG_ACCOUNT }}/catalog --tag 0.0.1
86+
87+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"label": "如何使用",
3+
"position": 4
4+
}

i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.0.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
"sidebar.user_docs.category.Package Management": {
2121
"message": "包管理工具"
2222
},
23+
"sidebar.user_docs.category.How to": {
24+
"message": "如何使用"
25+
},
2326
"sidebar.user_docs.category.Schema Definition": {
2427
"message": "模型定义"
2528
},

0 commit comments

Comments
 (0)