From 267e9c240cb2e1475a27ae838ff413364f5d1798 Mon Sep 17 00:00:00 2001 From: Jordon Leach Date: Tue, 3 Dec 2024 05:15:04 -0500 Subject: [PATCH] [Backport 2.8] Extension creator upgrade paths (#12740) * Fix upgrade path for extension creators * Add .nvmrc to app creator * Bump extension creator 1.0.3 * Clean up extension creator - add rancher annotations to pkg.package.json Remove annotations from helm chart --- creators/extension/app/files/.nvmrc | 1 + creators/extension/app/init | 3 +- creators/extension/init | 40 ++++++++++++++++--- creators/extension/package.json | 6 +-- creators/extension/pkg/init | 4 -- creators/extension/pkg/package.json | 24 +---------- creators/extension/pkg/pkg.package.json | 28 ++++--------- creators/extension/update/init | 25 +++++------- creators/extension/update/upgrade | 17 ++++---- .../helm/charts/ui-plugin-server/Chart.yaml | 2 - 10 files changed, 68 insertions(+), 82 deletions(-) create mode 100644 creators/extension/app/files/.nvmrc diff --git a/creators/extension/app/files/.nvmrc b/creators/extension/app/files/.nvmrc new file mode 100644 index 00000000000..19c7bdba7b1 --- /dev/null +++ b/creators/extension/app/files/.nvmrc @@ -0,0 +1 @@ +16 \ No newline at end of file diff --git a/creators/extension/app/init b/creators/extension/app/init index 570908587ea..c0e5f2cfd42 100755 --- a/creators/extension/app/init +++ b/creators/extension/app/init @@ -15,6 +15,7 @@ const files = [ 'gitignore', '.eslintignore', '.eslintrc.js', + '.nvmrc', '.yarnrc.yml', 'babel.config.js', '.vscode/settings.json' @@ -27,7 +28,7 @@ const args = process.argv; let appFolder = path.resolve('.'); let shellVersion = ''; -if (args.length === 3) { +if (args.length >= 3 && !args[2].includes('@rancher/create-extension/app/init')) { const name = args[2]; const folder = path.resolve('.'); diff --git a/creators/extension/init b/creators/extension/init index 80683293aae..d4a8e85fc8d 100755 --- a/creators/extension/init +++ b/creators/extension/init @@ -1,7 +1,7 @@ #!/usr/bin/env node /* eslint-disable no-console */ -const { execSync } = require('child_process'); +const { execSync, spawnSync } = require('child_process'); const fs = require('fs'); const path = require('path'); const creatorPkg = require('./package.json'); @@ -124,7 +124,14 @@ try { if ( updateOnly ) { // Run the update script directly console.log('Updating applications...'); - execSync(`node ${ path.join(updatePath, 'init') }`, { stdio: 'inherit' }); + const updateInitPath = path.join(updatePath, 'init'); + const updateArgs = [updateInitPath, shellVersion, tagUsed, ...args]; + + const result = spawnSync('node', updateArgs, { stdio: 'inherit' }); + + if (result.status !== 0) { + throw new Error('Failed to create skeleton application.'); + } console.log('Update completed successfully.'); process.exit(0); @@ -139,7 +146,14 @@ try { if ( !isInsideSkeleton && !skeletonExists ) { console.log(`Creating skeleton application: ${ appName }...`); // Pass all arguments to the app/init script - execSync(`node ${ path.join(__dirname, 'app', 'init') } ${ appName } ${ shellVersion } ${ args.join(' ') }`, { stdio: 'inherit' }); + const appInitPath = path.join(__dirname, 'app', 'init'); + const appArgs = [appInitPath, appName, shellVersion, ...args]; + + const result = spawnSync('node', appArgs, { stdio: 'inherit' }); + + if (result.status !== 0) { + throw new Error('Failed to create skeleton application.'); + } // Ensure the skeleton path directory is created before attempting to change directory if ( !fs.existsSync(skeletonPath) ) { @@ -165,16 +179,30 @@ try { // Check for package existence and create it if necessary if ( !pkgExists ) { console.log(`Creating package: ${ extensionName }...`); - execSync(`node ${ path.join(__dirname, 'pkg', 'init') } ${ extensionName } ${ shellVersion } ${ args.join(' ') }`, { stdio: 'inherit' }); + const pkgInitPath = path.join(__dirname, 'pkg', 'init'); + const pkgArgs = [pkgInitPath, extensionName, shellVersion, ...args]; + + const result = spawnSync('node', pkgArgs, { stdio: 'inherit' }); + + if (result.status !== 0) { + throw new Error('Failed to create package.'); + } } if ( args.includes('--update') || args.includes('-u') ) { // Run the update script console.log('Updating applications...'); - execSync(`node ${ path.join(updatePath, 'init') } ${ extensionName }`, { stdio: 'inherit' }); + const updatePath = path.join(__dirname, 'update'); + const updateArgs = [updatePath, ...args]; + + const result = spawnSync('node', updateArgs, { stdio: 'inherit' }); + + if (result.status !== 0) { + throw new Error('Failed to update applications.'); + } } - console.log('Extension created successfully.'); + // console.log('Extension created successfully.'); if ( skeletonOnly || !isInsideSkeleton ) { console.log(`To begin, run: \n\n\tcd ${ appName } && yarn install\n`); diff --git a/creators/extension/package.json b/creators/extension/package.json index 0f14b6902c8..e64129beede 100644 --- a/creators/extension/package.json +++ b/creators/extension/package.json @@ -1,12 +1,12 @@ { "name": "@rancher/create-extension", "description": "Rancher UI Extension generator", - "version": "1.0.2", + "version": "1.0.3", "license": "Apache-2.0", "author": "SUSE", "packageManager": "yarn@4.4.1", "bin": { - "create-extension": "./init" + "create-extension": "init" }, "files": [ "**/*", @@ -24,4 +24,4 @@ "dependencies": { "fs-extra": "^10.0.0" } -} \ No newline at end of file +} diff --git a/creators/extension/pkg/init b/creators/extension/pkg/init index 51d4652927c..4d2a111ff21 100755 --- a/creators/extension/pkg/init +++ b/creators/extension/pkg/init @@ -2,7 +2,6 @@ const fs = require('fs-extra'); const path = require('path'); -const https = require('https'); const targets = { dev: './node_modules/.bin/nuxt dev', @@ -43,14 +42,11 @@ if (args.length !== 3) { const name = args[2]; const folder = path.resolve('.'); const pkgFolder = path.join(folder, 'pkg', name); -let shellVersion = ''; let addTypeFolders = false; let addWorkflowFolder = false; if ( args.length >= 3 ) { - shellVersion = args[3]; - for ( let i = 3; i < args.length; i++ ) { switch (args[i]) { case '-t': diff --git a/creators/extension/pkg/package.json b/creators/extension/pkg/package.json index 7672d2baed9..da5863b01fd 100644 --- a/creators/extension/pkg/package.json +++ b/creators/extension/pkg/package.json @@ -10,30 +10,8 @@ "**/*.*", "init" ], - "rancher": { - "annotations": { - "catalog.cattle.io/rancher-version": "< 2.9.0", - "catalog.cattle.io/ui-extensions-version": "< 3.0.0" - } - }, "engines": { - "node": ">=16.0.0" - }, - "resolutions": { - "d3-color": "3.1.0", - "ejs": "3.1.9", - "follow-redirects": "1.15.2", - "glob": "7.2.3", - "glob-parent": "6.0.2", - "json5": "2.2.3", - "@types/lodash": "4.17.5", - "merge": "2.1.1", - "node-forge": "1.3.1", - "nth-check": "2.1.1", - "qs": "6.11.1", - "roarr": "7.0.4", - "semver": "7.5.4", - "@vue/cli-service/html-webpack-plugin": "^5.0.0" + "node": ">=20.0.0" }, "dependencies": { "fs-extra": "^10.0.0" diff --git a/creators/extension/pkg/pkg.package.json b/creators/extension/pkg/pkg.package.json index 988b17589e1..c839d354033 100644 --- a/creators/extension/pkg/pkg.package.json +++ b/creators/extension/pkg/pkg.package.json @@ -3,7 +3,12 @@ "description": "NAME plugin", "version": "0.1.0", "private": false, - "rancher": true, + "rancher": { + "annotations": { + "catalog.cattle.io/rancher-version": "< 2.9.0", + "catalog.cattle.io/ui-extensions-version": "< 3.0.0" + } + }, "scripts": {}, "engines": { "node": ">=16" @@ -11,26 +16,7 @@ "devDependencies": { "@vue/cli-plugin-babel": "~5.0.0", "@vue/cli-service": "~5.0.0", - "@vue/cli-plugin-typescript": "~5.0.0", - "cache-loader": "^4.1.0", - "color": "4.2.3", - "ip": "2.0.1", - "node-polyfill-webpack-plugin": "^3.0.0" - }, - "resolutions": { - "d3-color": "3.1.0", - "ejs": "3.1.9", - "follow-redirects": "1.15.2", - "glob": "7.2.3", - "glob-parent": "6.0.2", - "json5": "2.2.3", - "merge": "2.1.1", - "node-forge": "1.3.1", - "nth-check": "2.1.1", - "qs": "6.11.1", - "roarr": "7.0.4", - "semver": "7.5.4", - "@vue/cli-service/html-webpack-plugin": "^5.0.0" + "@vue/cli-plugin-typescript": "~5.0.0" }, "browserslist": [ "> 1%", diff --git a/creators/extension/update/init b/creators/extension/update/init index 213d0572898..890bfc5ecb9 100755 --- a/creators/extension/update/init +++ b/creators/extension/update/init @@ -4,17 +4,18 @@ const path = require('path'); const fs = require('fs-extra'); const { spawnSync } = require('child_process'); -const scriptFolder = __dirname; +const baseFolder = path.resolve(path.join(__dirname, '..')); const dest = path.resolve('.'); // Remove first two args -let args = process.argv; +const args = process.argv; + args.splice(0, 2); -const res = spawnSync(`${__dirname}/upgrade`, args, { - cwd: dest, +const res = spawnSync(`${ __dirname }/upgrade`, args, { + cwd: dest, shell: false, - stdio: [ 'ignore', process.stdout, process.stderr ], + stdio: ['ignore', process.stdout, process.stderr], }); if (res.status !== 0) { @@ -26,13 +27,9 @@ let rawdata = fs.readFileSync(path.join(dest, 'package.json')); const appPackage = JSON.parse(rawdata); // Read the package.json from the app creator -rawdata = fs.readFileSync(path.join(scriptFolder, 'app', 'package.json')); +rawdata = fs.readFileSync(path.join(baseFolder, 'app', 'package.json')); const latestPackage = JSON.parse(rawdata); -// Read the package.json from the upgrade creator -rawdata = fs.readFileSync(path.join(scriptFolder, 'package.json')); -const upgradePackage = JSON.parse(rawdata); - // Update dependency versions to match the latest from the creator Object.keys(latestPackage._pkgs).forEach((key) => { appPackage.dependencies[key] = latestPackage._pkgs[key]; @@ -43,14 +40,14 @@ appPackage.resolutions = appPackage.resolutions || {}; appPackage.resolutions['**/webpack'] = '4'; // Update the version of @rancher/shell -const shellVersion = upgradePackage.version; +const shellVersion = args[0]; appPackage.dependencies['@rancher/shell'] = shellVersion; -fs.writeFileSync(path.join(dest, 'package.json'), JSON.stringify(appPackage, null, 2) + '\n'); +fs.writeFileSync(path.join(dest, 'package.json'), `${ JSON.stringify(appPackage, null, 2) }\n`); spawnSync(`yarn`, ['install'], { - cwd: dest, + cwd: dest, shell: false, - stdio: [ 'ignore', process.stdout, process.stderr ], + stdio: ['ignore', process.stdout, process.stderr], }); diff --git a/creators/extension/update/upgrade b/creators/extension/update/upgrade index 7fccc0ef97e..f8e9174df27 100755 --- a/creators/extension/update/upgrade +++ b/creators/extension/update/upgrade @@ -1,20 +1,21 @@ #!/usr/bin/env sh SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +BASE_DIR="$(cd $SCRIPT_DIR && cd .. && pwd)" echo "Upgrading Rancher Shell" # Get the version number from the package.json file -VERSION=$(node -p -e "require('${SCRIPT_DIR}/package.json').version") - +VERSION=$1 echo "Updating to version: ${VERSION}" -echo "" FORCE="false" -if [ "$1" == "-f" ]; then - FORCE="true" -fi +for i in "$@"; do + if [ "$i" == "-f" ]; then + FORCE="true" + fi +done # Check for a clean git repository if [ ! -d ".git" ] && [ "${FORCE}" == "false" ]; then @@ -42,7 +43,7 @@ if [ "${HAS_SHELL}" != "1" ]; then fi # Copy files for the top-level folder (from the app creator) -rsync --exclude nuxt.config.js ${SCRIPT_DIR}/app/files/* . +rsync --exclude nuxt.config.js --exclude .gitlab-ci.yml ${BASE_DIR}/app/files/* . # Go through each folder in the pkg folder and update their files for pkg in ./pkg/* @@ -51,6 +52,6 @@ do pkgName=$(basename $pkg) echo "Updating package ${pkgName}" - cp ${SCRIPT_DIR}/pkg/files/* ${pkg} + cp ${BASE_DIR}/pkg/files/* ${pkg} fi done diff --git a/shell/scripts/extension/helm/charts/ui-plugin-server/Chart.yaml b/shell/scripts/extension/helm/charts/ui-plugin-server/Chart.yaml index cd724ae6cc0..63d91d64404 100644 --- a/shell/scripts/extension/helm/charts/ui-plugin-server/Chart.yaml +++ b/shell/scripts/extension/helm/charts/ui-plugin-server/Chart.yaml @@ -1,10 +1,8 @@ annotations: catalog.cattle.io/certified: rancher # Any application we are adding as a helm chart - catalog.cattle.io/kube-version: '>= 1.16.0-0 < 1.29.0-0' catalog.cattle.io/namespace: cattle-ui-plugin-system # Must prefix with cattle- and suffix with -system= catalog.cattle.io/os: linux catalog.cattle.io/permits-os: linux, windows - catalog.cattle.io/rancher-version: '>= 2.7.0-0 < 2.9.0-0' catalog.cattle.io/scope: management catalog.cattle.io/ui-component: plugins apiVersion: v2