github.com/KusionStack/kpm@v0.8.4-0.20240326033734-dc72298a30e5/docs/publish_your_kcl_packages.md (about) 1 # How to Share Your Package using kpm 2 3 [kpm](https://github.com/KusionStack/kpm) is a tool for managing kcl packages. This article will guide you on how to use kpm to push your kcl package to an OCI Registry for publication. kpm uses [ghcr.io](https://ghcr.io) as the default OCI Registry, and you can change the default OCI Registry by modifying the kpm configuration file. For information on how to modify the kpm configuration file, see [kpm oci registry](./kpm_oci.md#kpm-registry) 4 5 Here is a simple step-by-step guide on how to use kpm to push your kcl package to ghcr.io. 6 7 ## Step 1: Install kpm 8 9 First, you need to install kpm on your computer. You can follow the instructions in the [kpm installation documentation](https://kcl-lang.io/docs/user_docs/guides/package-management/installation). 10 11 ## Step 2: Create a ghcr.io token 12 13 If you are using the default OCI Registry of kpm, to push a kcl package to ghcr.io, you need to create a token for authentication. You can follow the instruction. 14 15 - [Creating a ghcr.io access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic) 16 17 ## Step 3: Log in to ghcr.io 18 19 After installing kpm and creating a ghcr.io token, you need to log in to ghcr.io using kpm. You can do this using the following command: 20 21 ```shell 22 kpm login ghcr.io -u <USERNAME> -p <TOKEN> <OCI_REGISTRY> 23 ``` 24 25 Where `<USERNAME>` is your GitHub username, `<TOKEN>` is the token you created in step 2, and `<OCI_REGISTRY>` is ghcr.io. 26 27 For more information on how to log in to ghcr.io using kpm, see [kpm login](./kpm_oci.md#kpm-login). 28 29 ## Step 4: Push your kcl package 30 31 Now, you can use kpm to push your kcl package to ghcr.io. 32 33 ### 1. A valid kcl package 34 35 First, you need to make sure that what you are pushing conforms to the specifications of a kcl package, i.e., it must contain valid kcl.mod and kcl.mod.lock files. 36 37 If you don't know how to get a valid kcl.mod and kcl.mod.lock, you can use the `kpm init` command. 38 39 ```shell 40 # Create a new kcl package named my_package 41 kpm init my_package 42 ``` 43 44 The `kpm init my_package` command will create a new kcl package `my_package` for you and create the `kcl.mod` and `kcl.mod.lock` files for this package. 45 46 If you already have a directory containing kcl files `exist_kcl_package`, you can use the following command to convert it into a kcl package and create valid `kcl.mod` and `kcl.mod.lock` files for it. 47 48 ```shell 49 # In the exist_kcl_package directory 50 $ pwd 51 /home/user/exist_kcl_package 52 53 # Run the `kpm init` command to create the `kcl.mod` and `kcl.mod.lock` files 54 $ kpm init 55 ``` 56 57 For more information on how to use `kpm init`, see [kpm init](./command-reference/1.init.md). 58 59 ### 2. Pushing the KCL Package 60 61 You can use the following command in the root directory of your `kcl` package: 62 63 ```shell 64 # In the root directory of the exist_kcl_package package 65 $ pwd 66 /home/user/exist_kcl_package 67 68 # Pushing the KCL Package to Default OCI Registry 69 $ kpm push 70 ``` 71 72 After completing these steps, you have successfully pushed your KCL Package to the default OCI Registry. 73 For more information on how to use `kpm push`, see [kpm push](./kpm_oci.md#kpm-push).