|
1 | 1 | --- |
2 | | -title: "Cloning Packages" |
| 2 | +title: "Cloning Package Revisions" |
3 | 3 | type: docs |
4 | 4 | weight: 5 |
5 | | -description: |
| 5 | +description: "A step by step guide to cloning package revisions in Porch" |
6 | 6 | --- |
7 | 7 |
|
8 | | -## Lorem Ipsum |
| 8 | +## Tutorial Overview |
9 | 9 |
|
10 | | -tutorial in cloning packges, how cloning works regarding upstream downstream, when you can and should clone, when not to clone, impacts of cloning etc etc. could again reffer back to the package-lifecycle diagram when its created. |
| 10 | +You will learn how to: |
11 | 11 |
|
12 | | -- [cloning an upstream package] deploy without any changes |
13 | | - - [cloning an upstream] with changes. |
14 | | - - ADD & Delete type changes at both file level(lines in a file getting added and removed) and also package level(files getting added and removed) |
| 12 | +1. Find a PackageRevision to clone |
| 13 | +2. Clone a PackageRevision to a different repository |
| 14 | +3. Modify the cloned PackageRevision |
| 15 | +4. Propose and approve the new revision |
| 16 | + |
| 17 | +{{% alert title="Note" color="primary" %}} |
| 18 | +Please note the tutorial assumes repositories are initialized with the "blueprints" and "deployments" names. |
| 19 | +We recommended to use these for simpler copy pasting of commands otherwise replace these values with your repository names in the below commands. |
| 20 | +{{% /alert %}} |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +## Understanding Clone Operations |
| 25 | + |
| 26 | +Cloning creates a new PackageRevision based on an existing one and works **across different repositories**. The cloned PackageRevision maintains an **upstream reference** to its source, allowing it to receive updates. |
| 27 | + |
| 28 | +--- |
| 29 | + |
| 30 | +## When to Use Clone |
| 31 | + |
| 32 | +**Use `porchctl rpkg clone` when:** |
| 33 | + |
| 34 | +- You need to import a package from a **different repository** (cross-repository operation) |
| 35 | +- You want to maintain an **upstream relationship** for future updates |
| 36 | +- You're importing blueprints from a central repository to deployment repositories |
| 37 | +- You need to pull packages from external Git or OCI repositories |
| 38 | +- You want to keep deployment packages synchronized with their upstream sources |
| 39 | +- You're following the blueprint → deployment pattern |
| 40 | + |
| 41 | +**Do NOT use clone when:** |
| 42 | + |
| 43 | +- Source and target are in the **same repository** - use `porchctl rpkg copy` instead |
| 44 | +- You want a completely independent copy with no upstream link - use `porchctl rpkg copy` instead |
| 45 | +- You're just creating a new version within the same repository - use `porchctl rpkg copy` instead |
| 46 | + |
| 47 | +{{% alert title="Note" color="primary" %}} |
| 48 | +For same-repository operations without upstream relationships, see [Copying Package Revisions Guide]({{% relref "/docs/neo-porch/4_tutorials_and_how-tos/working_with_package_revisions/copying-packages.md" %}}). |
| 49 | +{{% /alert %}} |
| 50 | + |
| 51 | +--- |
| 52 | + |
| 53 | +## Step 1: Find a PackageRevision to Clone |
| 54 | + |
| 55 | +First, list available PackageRevisions to find one to clone: |
| 56 | + |
| 57 | +```bash |
| 58 | +porchctl rpkg get --namespace default |
| 59 | +``` |
| 60 | + |
| 61 | +**Example output:** |
| 62 | + |
| 63 | +```bash |
| 64 | +NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY |
| 65 | +blueprints.nginx.main nginx main 5 true Published blueprints |
| 66 | +blueprints.wordpress.v1 wordpress v1 3 true Published blueprints |
| 67 | +deployments.my-app.v1 my-app v1 1 true Published deployments |
| 68 | +``` |
| 69 | + |
| 70 | +**What to look for:** |
| 71 | + |
| 72 | +- Published PackageRevisions from blueprint repositories are good candidates for cloning |
| 73 | +- Note the full NAME (e.g., `blueprints.nginx.main`) |
| 74 | +- Check the REPOSITORY column to identify the source repository |
| 75 | + |
| 76 | +--- |
| 77 | + |
| 78 | +## Step 2: Clone the PackageRevision |
| 79 | + |
| 80 | +Clone an existing PackageRevision to a different repository: |
| 81 | + |
| 82 | +```bash |
| 83 | +porchctl rpkg clone \ |
| 84 | + blueprints.nginx.main \ |
| 85 | + my-nginx \ |
| 86 | + --namespace default \ |
| 87 | + --repository deployments \ |
| 88 | + --workspace v1 |
| 89 | +``` |
| 90 | + |
| 91 | +**What this does:** |
| 92 | + |
| 93 | +- Creates a new PackageRevision based on `blueprints.nginx.main` |
| 94 | +- Names the new PackageRevision `my-nginx` (package name) |
| 95 | +- Places it in the `deployments` repository (different from source) |
| 96 | +- Uses `v1` as the workspace name |
| 97 | +- Starts in `Draft` lifecycle state |
| 98 | +- Maintains an upstream reference to `blueprints.nginx.main` |
| 99 | + |
| 100 | +**Verify the clone was created:** |
| 101 | + |
| 102 | +```bash |
| 103 | +porchctl rpkg get --namespace default --name my-nginx |
| 104 | +``` |
| 105 | + |
| 106 | +**Example output:** |
| 107 | + |
| 108 | +```bash |
| 109 | +NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY |
| 110 | +deployments.my-nginx.v1 my-nginx v1 0 false Draft deployments |
| 111 | +``` |
| 112 | + |
| 113 | +--- |
| 114 | + |
| 115 | +## Step 3: Modify the Cloned PackageRevision |
| 116 | + |
| 117 | +After cloning, you can modify the new PackageRevision. Pull it locally: |
| 118 | + |
| 119 | +```bash |
| 120 | +porchctl rpkg pull deployments.my-nginx.v1 ./my-nginx --namespace default |
| 121 | +``` |
| 122 | + |
| 123 | +**Make your changes:** |
| 124 | + |
| 125 | +```bash |
| 126 | +vim ./my-nginx/Kptfile |
| 127 | +``` |
| 128 | + |
| 129 | +For example, customize the namespace: |
| 130 | + |
| 131 | +```yaml |
| 132 | +apiVersion: kpt.dev/v1 |
| 133 | +kind: Kptfile |
| 134 | +metadata: |
| 135 | + name: my-nginx |
| 136 | + annotations: |
| 137 | + config.kubernetes.io/local-config: "true" |
| 138 | +info: |
| 139 | + description: Nginx deployment for production |
| 140 | +upstream: |
| 141 | + type: git |
| 142 | + git: |
| 143 | + repo: blueprints |
| 144 | + directory: nginx |
| 145 | + ref: main |
| 146 | +pipeline: |
| 147 | + mutators: |
| 148 | + - image: gcr.io/kpt-fn/set-namespace:v0.4.1 |
| 149 | + configMap: |
| 150 | + namespace: production |
| 151 | +``` |
| 152 | +
|
| 153 | +**Push the changes back:** |
| 154 | +
|
| 155 | +```bash |
| 156 | +porchctl rpkg push deployments.my-nginx.v1 ./my-nginx --namespace default |
| 157 | +``` |
| 158 | + |
| 159 | +--- |
| 160 | + |
| 161 | +## Step 4: Propose and Approve |
| 162 | + |
| 163 | +Once you're satisfied with the changes, propose the PackageRevision: |
| 164 | + |
| 165 | +```bash |
| 166 | +porchctl rpkg propose deployments.my-nginx.v1 --namespace default |
| 167 | +``` |
| 168 | + |
| 169 | +**Verify the state change:** |
| 170 | + |
| 171 | +```bash |
| 172 | +porchctl rpkg get deployments.my-nginx.v1 --namespace default |
| 173 | +``` |
| 174 | + |
| 175 | +**Example output:** |
| 176 | + |
| 177 | +```bash |
| 178 | +NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY |
| 179 | +deployments.my-nginx.v1 my-nginx v1 0 false Proposed deployments |
| 180 | +``` |
| 181 | + |
| 182 | +**Approve to publish:** |
| 183 | + |
| 184 | +```bash |
| 185 | +porchctl rpkg approve deployments.my-nginx.v1 --namespace default |
| 186 | +``` |
| 187 | + |
| 188 | +**Verify publication:** |
| 189 | + |
| 190 | +```bash |
| 191 | +porchctl rpkg get deployments.my-nginx.v1 --namespace default |
| 192 | +``` |
| 193 | + |
| 194 | +**Example output:** |
| 195 | + |
| 196 | +```bash |
| 197 | +NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY |
| 198 | +deployments.my-nginx.v1 my-nginx v1 1 true Published deployments |
| 199 | +``` |
| 200 | + |
| 201 | +--- |
| 202 | + |
| 203 | +{{% alert title="Note" color="primary" %}} |
| 204 | +For complete details on the `porchctl rpkg clone` command options and flags, see the [Porch CLI Guide]({{% relref "/docs/neo-porch/7_cli_api/relevant_old_docs/porchctl-cli-guide.md" %}}). |
| 205 | +{{% /alert %}} |
| 206 | + |
| 207 | +--- |
| 208 | + |
| 209 | +## Common Use Cases |
| 210 | + |
| 211 | +Here are practical scenarios where cloning PackageRevisions is useful. |
| 212 | + |
| 213 | +### Importing from Blueprint Repository |
| 214 | + |
| 215 | +Clone a blueprint package to your deployment repository: |
| 216 | + |
| 217 | +```bash |
| 218 | +# Clone from blueprints to deployments |
| 219 | +porchctl rpkg clone \ |
| 220 | + blueprints.base-app.main \ |
| 221 | + my-app \ |
| 222 | + --namespace default \ |
| 223 | + --repository deployments \ |
| 224 | + --workspace v1 |
| 225 | + |
| 226 | +# Customize and publish |
| 227 | +porchctl rpkg pull deployments.my-app.v1 ./my-app --namespace default |
| 228 | +# ... customize ... |
| 229 | +porchctl rpkg push deployments.my-app.v1 ./my-app --namespace default |
| 230 | +porchctl rpkg propose deployments.my-app.v1 --namespace default |
| 231 | +porchctl rpkg approve deployments.my-app.v1 --namespace default |
| 232 | +``` |
| 233 | + |
| 234 | +### Cloning from External Git Repository |
| 235 | + |
| 236 | +Clone directly from a Git repository URL: |
| 237 | + |
| 238 | +```bash |
| 239 | +# Clone from external Git repo |
| 240 | +porchctl rpkg clone \ |
| 241 | + https://github.com/example/blueprints.git \ |
| 242 | + external-app \ |
| 243 | + --namespace default \ |
| 244 | + --repository deployments \ |
| 245 | + --workspace v1 \ |
| 246 | + --ref main \ |
| 247 | + --directory packages/app |
| 248 | + |
| 249 | +# Publish |
| 250 | +porchctl rpkg propose deployments.external-app.v1 --namespace default |
| 251 | +porchctl rpkg approve deployments.external-app.v1 --namespace default |
| 252 | +``` |
| 253 | + |
| 254 | +--- |
| 255 | + |
| 256 | +## Troubleshooting |
| 257 | + |
| 258 | +Common issues when cloning PackageRevisions and how to resolve them. |
| 259 | + |
| 260 | +**Clone fails with "repository not found"?** |
| 261 | + |
| 262 | +- Verify the target repository exists: `porchctl repo get --namespace default` |
| 263 | +- Check the repository name is correct |
| 264 | +- Ensure you have permission to write to the target repository |
| 265 | + |
| 266 | +**Clone fails with "source not found"?** |
| 267 | + |
| 268 | +- Verify the source PackageRevision exists: `porchctl rpkg get --namespace default` |
| 269 | +- Check the exact name including repository, package, and workspace |
| 270 | +- Ensure you have permission to read the source PackageRevision |
| 271 | + |
| 272 | +**Clone fails with "workspace already exists"?** |
| 273 | + |
| 274 | +- The workspace name must be unique within the package in the target repository |
| 275 | +- Choose a different workspace name: `--workspace v2` or `--workspace prod` |
| 276 | +- List existing workspaces: `porchctl rpkg get --namespace default --name <package>` |
| 277 | + |
| 278 | +**Cloned PackageRevision has unexpected content?** |
| 279 | + |
| 280 | +- The clone includes all resources from the source at the time of cloning |
| 281 | +- Pull and inspect: `porchctl rpkg pull <name> ./dir --namespace default` |
| 282 | +- Make corrections and push back |
| 283 | + |
| 284 | +**Need to clone within the same repository?** |
| 285 | + |
| 286 | +- Use `porchctl rpkg copy` instead of `clone` for same-repository operations |
| 287 | +- The `copy` command is simpler and doesn't maintain upstream references |
| 288 | +- See [Copying Package Revisions Guide]({{% relref "/docs/neo-porch/4_tutorials_and_how-tos/working_with_package_revisions/copying-packages.md" %}}) |
| 289 | + |
| 290 | +--- |
| 291 | + |
| 292 | +## Key Concepts |
| 293 | + |
| 294 | +- **Clone**: Creates a new PackageRevision that can be in a different repository |
| 295 | +- **Upstream Reference**: Cloned packages maintain a link to their source for updates |
| 296 | +- **Cross-repository**: Clone works across different repositories, unlike copy |
| 297 | +- **Source Types**: Can clone from Porch packages, Git URLs, or OCI repositories |
| 298 | +- **Workspace**: Must be unique within the package in the target repository |
| 299 | +- **Blueprint Pattern**: Common pattern is blueprints repository → deployment repositories |
| 300 | + |
| 301 | +--- |
0 commit comments