Skip to content

Commit

Permalink
[Backport 2.8] Extension creator upgrade paths (#12740)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jordojordo authored Dec 3, 2024
1 parent 1c40d23 commit 267e9c2
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 82 deletions.
1 change: 1 addition & 0 deletions creators/extension/app/files/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16
3 changes: 2 additions & 1 deletion creators/extension/app/init
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const files = [
'gitignore',
'.eslintignore',
'.eslintrc.js',
'.nvmrc',
'.yarnrc.yml',
'babel.config.js',
'.vscode/settings.json'
Expand All @@ -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('.');

Expand Down
40 changes: 34 additions & 6 deletions creators/extension/init
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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);
Expand All @@ -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) ) {
Expand All @@ -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`);
Expand Down
6 changes: 3 additions & 3 deletions creators/extension/package.json
Original file line number Diff line number Diff line change
@@ -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": [
"**/*",
Expand All @@ -24,4 +24,4 @@
"dependencies": {
"fs-extra": "^10.0.0"
}
}
}
4 changes: 0 additions & 4 deletions creators/extension/pkg/init
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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':
Expand Down
24 changes: 1 addition & 23 deletions creators/extension/pkg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
28 changes: 7 additions & 21 deletions creators/extension/pkg/pkg.package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,20 @@
"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"
},
"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%",
Expand Down
25 changes: 11 additions & 14 deletions creators/extension/update/init
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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];
Expand All @@ -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],
});
17 changes: 9 additions & 8 deletions creators/extension/update/upgrade
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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/*
Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 267e9c2

Please sign in to comment.