From 8ddd8aabe06af9051d82795bebe617982f911283 Mon Sep 17 00:00:00 2001 From: Chris Hunt Date: Tue, 13 Aug 2024 10:31:16 +0100 Subject: [PATCH] Add new files and put static version back to 1.0 --- README.md | 2 +- build_all_branches.sh | 4 +-- processing/add_next_version.js | 48 ++++++++++++++++++++++++++++++++++ processing/get_image_sizes.js | 45 +++++++++++++++++++++++++++++++ processing/processjson.js | 8 ++++++ site/next.config.js | 2 +- 6 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 processing/add_next_version.js create mode 100644 processing/get_image_sizes.js diff --git a/README.md b/README.md index 5f83150..73a28f8 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ Click on the **Actions** tab in the top menu and check whether workflows need en | env.icon | The image to display for your registry. You can upload an image to `/site/public/` and reference that by https://domain.com/1.1/image.png or if you aren't using a {sub}domain by referencing it from https://username.github.io/repositoryname/1.1/image.png where image.png is the name of the image you uploaded. Alternatively just put the url of an image available on the web. If you just want to get the registry up and working, leave the default value in place until later. | | env.listUrl | The link to the root of your site. For example https://username.github.io/repositoryname/ it should always include a trailing slash. | | env.contactUrl | A link users can use to contact you on, such as your github issues page (right click the **Issues** tab in the top menu - next to the **Code** tab - and select `copy link address` and paste that in). | -| basePath | If you are using a domain or a subdomain, your basePath will just be `basePath: '/1.1',`, otherwise change the value to include what you chose for the repository name in step 2 `basePath: '/repositoryname/1.1',`. **The `1.1` will be replaced with the branch name automatically, so you should always keep it as 1.1.** | +| basePath | If you are using a domain or a subdomain, your basePath will just be `basePath: '/1.0',`, otherwise change the value to include what you chose for the repository name in step 2 `basePath: '/repositoryname/1.0',`. **The `1.0` will be replaced with the branch name automatically, so you should always keep it as 1.0.** | ### Commit changes image diff --git a/build_all_branches.sh b/build_all_branches.sh index f8c4955..78f9085 100755 --- a/build_all_branches.sh +++ b/build_all_branches.sh @@ -17,11 +17,11 @@ for BRANCH in $(git branch --remotes --format '%(refname:lstrip=3)' | grep -Ev ' git checkout $BRANCH node processing cp -a public/. process - sed -i "s/1.1/$SANITIZED_BRANCH/" site/next.config.js + sed -i "s/1.0/$SANITIZED_BRANCH/" site/next.config.js npm run deploy --prefix site cp -a process/. public/ # Have to run it again because the deploy wipes the file and folders out rm -rf process - sed -i "s/$SANITIZED_BRANCH/1.1/" site/next.config.js # Set it back to 1.1 so it can be changed again on the next loop + sed -i "s/$SANITIZED_BRANCH/1.0/" site/next.config.js # Set it back to 1.0 so it can be changed again on the next loop mv public base/$SANITIZED_BRANCH cp base/$SANITIZED_BRANCH/favicon.ico base/favicon.ico done diff --git a/processing/add_next_version.js b/processing/add_next_version.js new file mode 100644 index 0000000..0c41013 --- /dev/null +++ b/processing/add_next_version.js @@ -0,0 +1,48 @@ +const fs = require("fs"); +const glob = require("glob"); + +const baseversion = '1.16' +const tag = ':develop' + +const version = baseversion + '.x' +const tagversion = baseversion + '.0' + +glob("../workspaces/**/workspace.json", async function (err, files) { + if (err) { + console.log( + "cannot read the folder, something goes wrong with glob", + err + ); + } + + + for (const file of files) { + + let filedata = fs.readFileSync(file); + let parsed = JSON.parse(filedata); + + const current = parsed.compatibility[parsed.compatibility.length - 1] + const image = current.image.split(':')[0] + + const exists = parsed.compatibility.findIndex(el => el.version === version) + + let details = { + version, + image: image + tag, + uncompressed_size_mb: 0, + available_tags: [ + 'develop', + tagversion, + tagversion + '-rolling-weekly', + tagversion + '-rolling-daily' + ] + } + + if (exists === -1) { + parsed.compatibility.push(details) + fs.writeFileSync(file, JSON.stringify(parsed, null, 2)); + } + } + + +}); diff --git a/processing/get_image_sizes.js b/processing/get_image_sizes.js new file mode 100644 index 0000000..b586afd --- /dev/null +++ b/processing/get_image_sizes.js @@ -0,0 +1,45 @@ +const fs = require("fs"); +const glob = require("glob"); +const { execSync } = require('child_process'); + + +glob("../workspaces/**/workspace.json", function (err, files) { + if (err) { + console.log( + "cannot read the folder, something goes wrong with glob", + err + ); + } + + let total = 0 + for (const file of files) { + + let filedata = fs.readFileSync(file); + let parsed = JSON.parse(filedata); + + + parsed.compatibility.forEach((element, index) => { + total++ + if (element.uncompressed_size_mb === 0) { + execSync('docker image prune -a -f') + execSync('docker system prune --all --force --volumes') + + let pull = execSync('docker pull ' + element.image) + // console.log(pull) + let inspect = execSync('docker inspect -f "{{ .Size }}" ' + element.image) + let size = Math.round(inspect / 1000000) + let remove = execSync('docker rmi ' + element.image) + console.log(remove) + parsed.compatibility[index].uncompressed_size_mb = size + console.log('Write file: ' + parsed.friendly_name + ' - ' + element.version + ': ' + size) + fs.writeFileSync(file, JSON.stringify(parsed, null, 2)); + } else { + console.log(parsed.friendly_name + ' - ' + element.version + ': skipped') + } + + }) + + } + console.log(total + ' entries processed') + +}); diff --git a/processing/processjson.js b/processing/processjson.js index 14584fe..c934fc3 100644 --- a/processing/processjson.js +++ b/processing/processjson.js @@ -40,6 +40,13 @@ glob("**/workspace.json", async function (err, files) { let parsed = JSON.parse(filedata); parsed.sha = hash.hash; console.log(parsed.name + ' added') + parsed.compatibility.forEach((element, index) => { + if ('available_tags' in element) { + element.available_tags.forEach((el) => { + channels.add(el) + }) + } + }) workspaces.push(parsed); if (fs.existsSync(folder + "/" + parsed.image_src)) { @@ -60,6 +67,7 @@ glob("**/workspace.json", async function (err, files) { contact_url: nextConfig.env.contactUrl || null, modified: Date.now(), workspaces: workspaces, + channels: [...channels] }; let data = JSON.stringify(json); diff --git a/site/next.config.js b/site/next.config.js index 3afed83..b1fd0a2 100644 --- a/site/next.config.js +++ b/site/next.config.js @@ -10,7 +10,7 @@ const nextConfig = { }, reactStrictMode: true, swcMinify: true, - basePath: '/kasm-registry/1.1', + basePath: '/kasm-registry/1.0', trailingSlash: true, images: { unoptimized: true,