kcl-lang.io/kpm@v0.8.7-0.20240520061008-9fc4c5efc8c7/docs/publish_to_docker_reg.md (about)

     1  # How to Share Your Package using kpm on docker.io
     2  
     3  [kpm](https://github.com/KusionStack/kpm) is a tool for managing kcl packages. This article will show you how to use kpm to push your kcl packages to docker.io.
     4  
     5  Here is a simple step-by-step guide on how to use kpm to push your kcl package to docker.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 docker.io account
    12  
    13  If you want to use `docker.io` as the OCI registry to share your kcl package with others, you need to create a `docker.io` account to support the push of your kcl package.
    14  
    15  ## Step 3: Log in to docker.io
    16  
    17  You can use the following command to log in to docker.io.
    18  
    19  ```shell
    20  kpm login -u <USERNAME> -p <PASSWORD> docker.io
    21  ```
    22  
    23  Where `<USERNAME>` is your `docker.io` username, and `<PASSWORD>` is your `docker.io` password.
    24  
    25  For more information on how to log in to docker.io using kpm, see [kpm login](./kpm_oci.md#kpm-login).
    26  
    27  ## Step 4: Push your kcl package
    28  
    29  Now, you can use kpm to push your kcl package to `docker.io`.
    30  
    31  ### 1. A valid kcl package
    32  
    33  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.
    34  
    35  If you don't know how to get a valid kcl.mod and kcl.mod.lock, you can use the `kpm init` command.
    36  
    37  ```shell
    38  # Create a new kcl package named my_package
    39  kpm init my_package
    40  ```
    41  
    42  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.
    43  
    44  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.
    45  
    46  ```shell
    47  # In the exist_kcl_package directory
    48  $ pwd 
    49  /home/user/exist_kcl_package
    50  
    51  # Run the `kpm init` command to create the `kcl.mod` and `kcl.mod.lock` files
    52  $ kpm init 
    53  ```
    54  
    55  For more information on how to use `kpm init`, see [kpm init](./command-reference/1.init.md).
    56  
    57  ### 2. Pushing the KCL Package
    58  
    59  You can use the following command in the root directory of your `kcl` package:
    60  
    61  ```shell
    62  # In the root directory of the exist_kcl_package package
    63  $ pwd 
    64  /home/user/exist_kcl_package
    65  
    66  # Pushing the KCL Package to Default OCI Registry
    67  $ kpm push oci://docker.io/<USERNAME>/exist_kcl_package
    68  ```
    69  
    70  After completing these steps, you have successfully pushed your KCL Package `exist_kcl_package` to `docker.io`.
    71  For more information on how to use `kpm push`, see [kpm push](./kpm_oci.md#kpm-push).