@ibm-cloud/cd-tools 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +151 -23
- package/cmd/copy-toolchain.js +3 -0
- package/cmd/utils/validate.js +5 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,32 +1,20 @@
|
|
|
1
1
|
# Continuous Delivery tools
|
|
2
2
|
|
|
3
|
-
Provides tools to work with IBM Cloud Continuous Delivery resources, including
|
|
3
|
+
Provides tools to work with IBM Cloud [Continuous Delivery](https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-getting-started) resources, including [Toolchains](https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-toolchains-using), [Delivery Pipelines](https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-tekton-pipelines), and [Git Repos and Issue Tracking](https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-git_working) projects.
|
|
4
4
|
|
|
5
5
|
#### Supported resources
|
|
6
6
|
| Resource | Supported |
|
|
7
7
|
| :- | :- |
|
|
8
|
-
| Toolchains | Yes <sup>1</sup> |
|
|
9
|
-
| Git Repos and Issue Tracking
|
|
10
|
-
| Delivery Pipelines (Tekton) | Yes <sup>1</sup>
|
|
11
|
-
| Delivery Pipelines (Classic) | No |
|
|
12
|
-
| DevOps Insights | No |
|
|
13
|
-
| Other Tool Integrations | Yes |
|
|
14
|
-
|
|
15
|
-
#### Limitations
|
|
16
|
-
1. Secrets stored directly in Toolchains or Delivery Pipelines (environment properties or trigger properties) will not be copied. A `check-secrets` tool is provided to export secrets into a Secrets Manager instance, replacing the stored secrets with secret references. Secret references are supported in the migration.
|
|
17
|
-
2. Personal Access Tokens will not be copied.
|
|
18
|
-
3. Pipeline run history, logs, and assets will not be copied to the new region. You can keep the original pipelines for some time to retain history.
|
|
19
|
-
4. Classic pipelines are not supported.
|
|
20
|
-
5. DevOps Insights is not supported.
|
|
8
|
+
| [Toolchains](https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-toolchains-using) | Yes <sup>[1](#limitations-1)</sup> |
|
|
9
|
+
| [Git Repos and Issue Tracking](https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-git_working) | Yes <sup>[2](#limitations)</sup> |
|
|
10
|
+
| [Delivery Pipelines (Tekton)](https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-tekton-pipelines) | Yes <sup>[3](#limitations-1)</sup> |
|
|
11
|
+
| [Delivery Pipelines (Classic)](https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-deliverypipeline_about) | No |
|
|
12
|
+
| [DevOps Insights](https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-di_working) | No |
|
|
13
|
+
| [Other Tool Integrations](https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-integrations) | Yes |
|
|
21
14
|
|
|
22
15
|
## Prerequisites
|
|
23
16
|
- Node.js v20 (or later)
|
|
24
17
|
- Terraform v1.13.3 (or later)
|
|
25
|
-
- An **IBM Cloud API key** with the following IAM access permissions:
|
|
26
|
-
- **Viewer** for the source Toolchain(s) being copied
|
|
27
|
-
- **Editor** for create new Toolchains in the target region
|
|
28
|
-
- **Administrator** for other IBM Cloud service instances that have a tool integration with IAM service-to-service authorizations, such as Secrets Manager, Event Notifications, etc.
|
|
29
|
-
- For Git Repos and Issue Tracking projects, Personal Access Tokens (PAT) for the source and destination regions are required, with the `api` scope.
|
|
30
18
|
|
|
31
19
|
## Install
|
|
32
20
|
### Install Node.js, Terraform
|
|
@@ -44,7 +32,7 @@ brew install hashicorp/tap/terraform
|
|
|
44
32
|
|
|
45
33
|
## Usage
|
|
46
34
|
|
|
47
|
-
The tools are provided as an [npx](https://docs.npmjs.com/cli/commands/npx) command which automatically downloads and runs
|
|
35
|
+
The tools are provided as an [npx](https://docs.npmjs.com/cli/commands/npx) command. [npx](https://docs.npmjs.com/cli/commands/npx) (Node Package Execute) is a utility provided with [Node.js](https://nodejs.org/) which automatically downloads a module and its dependencies, and runs it. To see the available commands, run `npx @ibm-cloud/cd-tools` on your command line.
|
|
48
36
|
|
|
49
37
|
```shell-session
|
|
50
38
|
$ npx @ibm-cloud/cd-tools
|
|
@@ -58,10 +46,150 @@ Options:
|
|
|
58
46
|
|
|
59
47
|
Commands:
|
|
60
48
|
copy-project-group [options] Bulk migrate GitLab group projects
|
|
61
|
-
|
|
62
|
-
|
|
49
|
+
copy-toolchain [options] Copies a toolchain, including tool integrations and Tekton pipelines, to another region or resource group
|
|
50
|
+
export-secrets [options] Checks if you have any stored secrets in your toolchain or pipelines, and exports them to Secrets Manager
|
|
63
51
|
help [command] display help for command
|
|
64
52
|
```
|
|
65
53
|
|
|
54
|
+
## copy-project-group
|
|
55
|
+
|
|
56
|
+
### Overview
|
|
57
|
+
The `copy-project-group` command copies a [group](https://docs.gitlab.com/user/group/) of projects in IBM Cloud Continuous Delivery's [Git Repos and Issue Tracking](https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-git_working) from one region to another. This includes the project group, projects, Git repositories, issues, merge requests, wiki, and most other resources. See the [full list](https://docs.gitlab.com/user/group/import/migrated_items/) of items included in the copy. In addition to copying the project group, the command will also ensure that project members exist in the destination region and are added to the newly copied project group, preserving existing permissions.
|
|
58
|
+
|
|
59
|
+
### Limitations
|
|
60
|
+
1. Personal projects are not supported. If you created a project under a [personal namespace](https://docs.gitlab.com/user/namespace/), you can either [move your personal project to a group](https://docs.gitlab.com/tutorials/move_personal_project_to_group/), or [convert your personal namespace into a group](https://docs.gitlab.com/tutorials/convert_personal_namespace_to_group/). It is recommended that you store projects in groups, as they allow multiple administrators and allow better continuity of a project over time.
|
|
61
|
+
2. This command requests a GitLab direct transfer and is subject to the [limitations of using direct transfer](https://docs.gitlab.com/user/group/import/#known-issues).
|
|
62
|
+
3. Copying large projects, or projects with large files or many resources, can take time.
|
|
63
|
+
4. As each region of Git Repos and Issue Tracking is independent, your projects' users may not yet exist in the destination region. The `copy-project-group` will ensure that the users exist in the new region, however there may be user name conflicts with other users in the destination region. In the event of a user name conflict, the user name in the destination region may be changed slightly by adding a suffix.
|
|
64
|
+
|
|
65
|
+
### Prerequisites
|
|
66
|
+
- Personal Access Tokens (PAT) for the source and destination regions are required
|
|
67
|
+
- Both PATs must have the `api` scope.
|
|
68
|
+
|
|
69
|
+
### Recommendations
|
|
70
|
+
- Be patient. Copying large projects may take some time. Allow the command to run to completion.
|
|
71
|
+
|
|
72
|
+
### Usage
|
|
73
|
+
```shell-session
|
|
74
|
+
$ npx @ibm-cloud/cd-tools copy-project-group -h
|
|
75
|
+
Usage: @ibm-cloud/cd-tools copy-project-group [options]
|
|
76
|
+
|
|
77
|
+
Bulk migrate GitLab group projects
|
|
78
|
+
|
|
79
|
+
Options:
|
|
80
|
+
-s, --source-region <region> Source GitLab instance region
|
|
81
|
+
-d, --dest-region <region> Destination GitLab instance region
|
|
82
|
+
--st, --source-token <token> Source GitLab access token
|
|
83
|
+
--dt, --dest-token <token> Destination GitLab access token
|
|
84
|
+
-g, --group-id <id> Source group ID to migrate
|
|
85
|
+
-n, --new-name <n> New group path (optional)
|
|
86
|
+
-h, --help display help for command
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## copy-toolchain
|
|
90
|
+
|
|
91
|
+
### Overview
|
|
92
|
+
The `copy-toolchain` command copies a [toolchain](https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-toolchains-using), including tool integrations and Tekton pipelines, to another region or resource group, in the same account. The copy works by first serializing the existing toolchain into Terraform (.tf) files, then applying the Terraform on the destination.
|
|
93
|
+
|
|
94
|
+
### Limitations
|
|
95
|
+
1. [Classic pipelines](https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-deliverypipeline_about) are not supported.
|
|
96
|
+
2. [DevOps Insights](https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-di_working) is not supported.
|
|
97
|
+
3. Secrets stored directly in Toolchains or Delivery Pipelines (environment properties or trigger properties) will not be copied. An `export-secrets` command is provided to export secrets into a [Secrets Manager](https://cloud.ibm.com/docs/secrets-manager?topic=secrets-manager-getting-started) instance, replacing the stored secrets with secret references. Secret references are supported. It is recommended to store secrets in [Secrets Manager](https://cloud.ibm.com/docs/secrets-manager?topic=secrets-manager-getting-started).
|
|
98
|
+
4. Tekton pipeline webhook trigger secrets will not be copied, as references are not supported for webhook trigger secrets. You will need to add the secret after copying the toolchain.
|
|
99
|
+
5. Tekton pipeline run history, logs, and assets will not be copied. You can keep the original pipelines for some time to retain history.
|
|
100
|
+
6. GitHub and Git Repos and Issue Tracking tool integrations configured with OAuth type authentication will automatically be converted to use the OAuth identity of the user performing the copy (the owner of the API key) rather than the original user. This is to simplify the copy operation. You can re-configure the tool integrations after copying to use a different user.
|
|
101
|
+
7. Git Repos and Issue Tracking tool integrations that use Personal Access Tokens (PATs) for authentication will automatically be converted to use OAuth. You can re-configure the tool integrations after copying to use a PAT again.
|
|
102
|
+
|
|
103
|
+
### Prerequisites
|
|
104
|
+
- An [IBM Cloud API key](https://cloud.ibm.com/docs/account?topic=account-manapikey) with the IAM access listed below.
|
|
105
|
+
- **Viewer** access for the source Toolchain(s) being copied
|
|
106
|
+
- **Editor** access for creating new Toolchains in the target region
|
|
107
|
+
- **Administrator** access for other IBM Cloud service instances that have a tool integration with IAM service-to-service authorizations, such as [Secrets Manager](https://cloud.ibm.com/docs/secrets-manager?topic=secrets-manager-getting-started), [Event Notifications](https://cloud.ibm.com/docs/event-notifications?topic=event-notifications-getting-started), etc.
|
|
108
|
+
- Access to any GitHub or Git Repos and Issue Tracking **repositories** referenced by tool integrations in the toolchain, with permission to **read the repository** and **create webhooks**. This is required in order to create pipeline Git type triggers, which require a webhook to be added on the repository to trigger the pipeline, and for the pipeline to be able to clone the repositories during execution.
|
|
109
|
+
- A [Continuous Delivery](https://cloud.ibm.com/catalog/services/continuous-delivery) service instance is required in the target region and resource group in order to properly create the toolchain copy. Note that Continuous Delivery capabilities (Delivery Pipelines, Git Repos and Issue Tracking, etc) are subject to the plan of the Continuous Delivery instance in the same region and resource group as the toolchain. [Learn more](https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-limitations_usage)
|
|
110
|
+
|
|
111
|
+
### Recommendations
|
|
112
|
+
- Ensure that all tool integrations in the toolchains are correctly configured and showing no errors in the toolchain page before proceeding. If there are misconfigured tool integrations, the tool will prompt you before proceeding.
|
|
113
|
+
|
|
114
|
+
### CRN
|
|
115
|
+
|
|
116
|
+
IBM Cloud resources are uniquely identified by a [Cloud Resource Name (CRN)](https://cloud.ibm.com/docs/account?topic=account-crn). You will need the CRN of the toolchain you want to copy. You can get the CRN of a toolchain a few ways:
|
|
117
|
+
|
|
118
|
+
1. Locate the toolchain in the [Platform Automation](https://cloud.ibm.com/automation) > [Toolchains](https://cloud.ibm.com/automation/toolchains) page, open the toolchain, and click **Details** to see the toolchain details, which shows the CRN.
|
|
119
|
+
2. Locate the toolchain in the [Resource list](https://cloud.ibm.com/resources) page, click on the toolchain row to expand the details panel, which shows the CRN.
|
|
120
|
+
3. Using the [ibmcloud cli](https://cloud.ibm.com/docs/cli?topic=cli-getting-started), you can list toolchains and their CRNs via
|
|
121
|
+
```shell-session
|
|
122
|
+
$ ibmcloud resource service-instances --service-name toolchain --long
|
|
123
|
+
```
|
|
124
|
+
4. Using the [CD Toolchain API](https://cloud.ibm.com/apidocs/toolchain).
|
|
125
|
+
|
|
126
|
+
### Usage
|
|
127
|
+
```shell-session
|
|
128
|
+
$ npx @ibm-cloud/cd-tools copy-toolchain -h
|
|
129
|
+
Usage: @ibm-cloud/cd-tools copy-toolchain [options]
|
|
130
|
+
|
|
131
|
+
Copies a toolchain, including tool integrations and Tekton pipelines, to another region or resource group.
|
|
132
|
+
|
|
133
|
+
Examples:
|
|
134
|
+
export IBMCLOUD_API_KEY='...'
|
|
135
|
+
npx @ibm-cloud/cd-migration-tools copy-toolchain -c ${TOOLCHAIN_CRN} -r us-south
|
|
136
|
+
Copy a toolchain to the Dallas region with the same name, in the same resource group.
|
|
137
|
+
npx @ibm-cloud/cd-migration-tools copy-toolchain -c ${TOOLCHAIN_CRN} -r eu-de -n new-toolchain-name -g new-resource-group --apikey ${APIKEY}
|
|
138
|
+
Copy a toolchain to the Frankfurt region with the specified name and target resource group, using the given API key
|
|
139
|
+
|
|
140
|
+
Environment Variables:
|
|
141
|
+
IBMCLOUD_API_KEY API key used to authenticate. Must have IAM permission to read and create toolchains and service-to-service authorizations in source and target region / resource group
|
|
142
|
+
|
|
143
|
+
Basic options:
|
|
144
|
+
-c, --toolchain-crn <crn> The CRN of the source toolchain to copy
|
|
145
|
+
-r, --region <region> The destination region of the copied toolchain (choices: "au-syd", "br-sao", "ca-mon", "ca-tor", "eu-de", "eu-es", "eu-gb", "jp-osa", "jp-tok", "us-east", "us-south")
|
|
146
|
+
-a, --apikey <api_key> API key used to authenticate. Must have IAM permission to read and create toolchains and service-to-service authorizations in source and target region / resource group
|
|
147
|
+
-n, --name <name> (Optional) The name of the copied toolchain (default: same name as original)
|
|
148
|
+
-g, --resource-group <resource_group> (Optional) The name or ID of destination resource group of the copied toolchain (default: same resource group as original)
|
|
149
|
+
-t, --tag <tag> (Optional) The tag to add to the copied toolchain
|
|
150
|
+
-h, --help Display help for command
|
|
151
|
+
|
|
152
|
+
Advanced options:
|
|
153
|
+
-d, --terraform-dir <path> (Optional) The target local directory to store the generated Terraform (.tf) files
|
|
154
|
+
-D, --dry-run (Optional) Skip running terraform apply; only generate the Terraform (.tf) files
|
|
155
|
+
-f, --force (Optional) Force the copy toolchain command to run without user confirmation
|
|
156
|
+
-S, --skip-s2s (Optional) Skip importing toolchain-generated service-to-service authorizations
|
|
157
|
+
-T, --skip-disable-triggers (Optional) Skip disabling Tekton pipeline Git or timed triggers. Note: This may result in duplicate pipeline runs
|
|
158
|
+
-C, --compact (Optional) Generate all resources in a single resources.tf file
|
|
159
|
+
-v, --verbose (Optional) Increase log output
|
|
160
|
+
-q, --quiet (Optional) Suppress non-essential output, only errors and critical warnings are displayed
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Retrying after errors
|
|
164
|
+
|
|
165
|
+
If an error occurs while copying the toolchain, the copied toolchain may be incomplete. You may need to try the command again. To try again, you can either:
|
|
166
|
+
1. Delete the partially created toolchain and run the `copy-toolchain` command again.
|
|
167
|
+
2. Re-run the `terraform apply` command.<br/><br/>The `copy-toolchain` first serializes the source toolchain into Terraform (.tf) files. If you don't specify the `-d, --terraform-dir <path>`, the Terraform files will be placed in a folder in the current working directory named `output-{id}`, e.g. `output-1764100766410`. You can locate the most recent output folder and re-run `terraform apply`. This will continue where the previous command left off. When prompted for an API key, specify the same API key you used to run the `copy-toolchain` command.
|
|
168
|
+
```shell-session
|
|
169
|
+
$ cd output-1764102115772
|
|
170
|
+
$ terraform apply
|
|
171
|
+
var.ibmcloud_api_key
|
|
172
|
+
Enter a value: {api_key}
|
|
173
|
+
...
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Getting the Terraform code for a toolchain
|
|
177
|
+
|
|
178
|
+
You can get the Terraform (.tf) files for a toolchain by running the `copy-toolchain` command with the `-D, --dry-run` option, and specifying the directory to store the Terraform files with the `-d, --terraform-dir <path>` option.
|
|
179
|
+
|
|
180
|
+
```shell-session
|
|
181
|
+
$ npx @ibm-cloud/cd-tools copy-toolchain -c ${CRN} -r us-south --dry-run --terraform-dir ./terraform
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
The command will output a collection of `.tf` files in the `terraform` directory. If you prefer to have a single file containing all the Terraform source, you can also specify the `-C, --compact` option.
|
|
185
|
+
|
|
186
|
+
### Copying toolchains to a different account
|
|
187
|
+
|
|
188
|
+
The `copy-toolchain` command copies a toolchain within an IBM Cloud account. However it is possible to copy a toolchain to a different account with a few extra steps. Note that any tool integrations that access services in the source account, such as [Secrets Manager](https://cloud.ibm.com/docs/secrets-manager?topic=secrets-manager-getting-started), [Event Notifications](https://cloud.ibm.com/docs/event-notifications?topic=event-notifications-getting-started), etc. are not supported for cross-account copying.
|
|
189
|
+
1. Run the `copy-toolchain` command with the `-D, --dry-run` option to first generate the Terraform (.tf) files to a directory (See [Getting the Terraform code for a toolchain](#getting-the-terraform-code-for-a-toolchain)).
|
|
190
|
+
2. Edit the `cd_toolchain.tf` file, replacing the `resource_group_id` with a valid resource group id in the target account. You can find the resource group id in the IBM Cloud console under [Manage > Account > Resource groups](https://cloud.ibm.com/account/resource-groups).
|
|
191
|
+
3. Switch to the directory containing the Terraform files, and run `terraform init`, then `terraform apply`.
|
|
192
|
+
4. When prompted for the API key, provide an API key for the target account you wish to copy the toolchain to.
|
|
193
|
+
|
|
66
194
|
## Test
|
|
67
|
-
All test setup and usage instructions are documented in [test/README.md](./test/README.md).
|
|
195
|
+
All test setup and usage instructions are documented in [test/README.md](./test/README.md).
|
package/cmd/copy-toolchain.js
CHANGED
|
@@ -22,6 +22,8 @@ import { importTerraform } from './utils/import-terraform.js';
|
|
|
22
22
|
|
|
23
23
|
import { COPY_TOOLCHAIN_DESC, DOCS_URL, TARGET_REGIONS, SOURCE_REGIONS } from '../config.js';
|
|
24
24
|
|
|
25
|
+
import packageJson from '../package.json' with { type: "json" };
|
|
26
|
+
|
|
25
27
|
process.on('exit', (code) => {
|
|
26
28
|
if (code !== 0) logger.print(`Need help? Visit ${DOCS_URL} for more troubleshooting information.`);
|
|
27
29
|
});
|
|
@@ -98,6 +100,7 @@ async function main(options) {
|
|
|
98
100
|
// Validate arguments are valid and check if Terraform is installed appropriately
|
|
99
101
|
try {
|
|
100
102
|
validatePrereqsVersions();
|
|
103
|
+
logger.info(`\x1b[32m✔\x1b[0m cd-tools Version: ${packageJson.version}`, LOG_STAGES.setup);
|
|
101
104
|
|
|
102
105
|
if (!apiKey) apiKey = parseEnvVar('IBMCLOUD_API_KEY');
|
|
103
106
|
bearer = await getBearerToken(apiKey);
|
package/cmd/utils/validate.js
CHANGED
|
@@ -114,13 +114,13 @@ async function warnDuplicateName(token, accountId, tcName, srcRegion, targetRegi
|
|
|
114
114
|
// soft warning of confusion
|
|
115
115
|
logger.warn(`\nWarning! A toolchain named '${tcName}' already exists in:\n - Region: ${targetRegion}`, '', true);
|
|
116
116
|
}
|
|
117
|
-
if (hasSameResourceGroup) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
117
|
+
// if (hasSameResourceGroup) {
|
|
118
|
+
// // soft warning of confusion
|
|
119
|
+
// logger.warn(`\nWarning! A toolchain named '${tcName}' already exists in:\n - Resource Group: ${targetResourceGroupName} (${targetResourceGroupId})`, '', true);
|
|
120
|
+
// }
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
if (hasBoth || hasSameRegion
|
|
123
|
+
if (hasBoth || hasSameRegion) {
|
|
124
124
|
// suggest a tag, if one not provided
|
|
125
125
|
if (!targetTag) {
|
|
126
126
|
if (!skipPrompt) {
|