From dd7a71cffe3f3c439c23a926fb8016042d947fb5 Mon Sep 17 00:00:00 2001 From: Andrew Liaw <43424755+yhaliaw@users.noreply.github.com> Date: Mon, 11 Dec 2023 16:53:27 +0800 Subject: [PATCH 01/10] Draft for adding microk8s-docker-registry input --- action.yaml | 2 ++ src/bootstrap/index.ts | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/action.yaml b/action.yaml index f1b6dd8..7bde60e 100644 --- a/action.yaml +++ b/action.yaml @@ -60,6 +60,8 @@ inputs: description: "microk8s addons to enable" required: false default: "storage dns rbac" + microk8s-docker-registry: + description: "URL of docker registry for microk8s to use" runs: using: "node16" main: "dist/bootstrap/index.js" diff --git a/src/bootstrap/index.ts b/src/bootstrap/index.ts index d24536f..9474572 100644 --- a/src/bootstrap/index.ts +++ b/src/bootstrap/index.ts @@ -71,8 +71,24 @@ async function retry_until_rc(cmd: string, expected_rc=0, maxRetries=12, timeout return false; } -async function microk8s_init(addons) { +async function microk8s_init(addons, docker_registry) { // microk8s needs some additional things done to ensure it's ready for Juju. + // Add docker registry configuration if given. + if (docker_registry) { + let hostname; + let port; + try { + const docker_registry_url = new URL(docker_registry); + hostname = docker_registry_url.hostname; + port = docker_registry_url.port; + } catch(err) { + console.log(`Failed to parse docker registry URL for microk8s: ${err}`); + } + await exec.exec("bash", ["-c", `cat <> /var/snap/microk8s/current/args/certs.d/docker.io/hosts.toml\nserver = "${docker_registry}"\n\n[host."${hostname}:${port}"]\ncapabilities = ["pull", "resolve"]\nEOT`]); + await exec.exec("microk8s stop") + await exec.exec("microk8s start") + } + // Add the given addons if any were given. await exec_as_microk8s("microk8s status --wait-ready"); if (addons) { @@ -151,6 +167,7 @@ async function run() { const microk8s_group = get_microk8s_group(); let bootstrap_constraints = core.getInput("bootstrap-constraints"); const microk8s_addons = core.getInput("microk8s-addons") + const microk8s_docker_registry = core.getInput("microk8s-docker_registry") let group = ""; try { core.addPath('/snap/bin'); @@ -218,7 +235,7 @@ async function run() { core.endGroup(); core.startGroup("Initialize microk8s"); await exec.exec('bash', ['-c', `sudo usermod -a -G ${microk8s_group} $USER`]); - if(!await microk8s_init(microk8s_addons)) { + if(!await microk8s_init(microk8s_addons, microk8s_docker_registry)) { return; } group = microk8s_group; From d1299484370f38bb996ef157b3d66df8df2c7fb0 Mon Sep 17 00:00:00 2001 From: Andrew Liaw <43424755+yhaliaw@users.noreply.github.com> Date: Mon, 11 Dec 2023 19:14:05 +0800 Subject: [PATCH 02/10] Update the error handling --- src/bootstrap/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/index.ts b/src/bootstrap/index.ts index 9474572..d08f6c9 100644 --- a/src/bootstrap/index.ts +++ b/src/bootstrap/index.ts @@ -82,7 +82,8 @@ async function microk8s_init(addons, docker_registry) { hostname = docker_registry_url.hostname; port = docker_registry_url.port; } catch(err) { - console.log(`Failed to parse docker registry URL for microk8s: ${err}`); + core.setFailed(`Failed to parse URL of docker registry for microk8s: ${err}`); + return false; } await exec.exec("bash", ["-c", `cat <> /var/snap/microk8s/current/args/certs.d/docker.io/hosts.toml\nserver = "${docker_registry}"\n\n[host."${hostname}:${port}"]\ncapabilities = ["pull", "resolve"]\nEOT`]); await exec.exec("microk8s stop") From 874d5c4be207f32c3327e88f1e99656817d38a4b Mon Sep 17 00:00:00 2001 From: yhaliaw <43424755+yhaliaw@users.noreply.github.com> Date: Tue, 12 Dec 2023 16:01:24 +0800 Subject: [PATCH 03/10] Build from source --- dist/bootstrap/index.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/dist/bootstrap/index.js b/dist/bootstrap/index.js index 4700ac3..cb4547b 100644 --- a/dist/bootstrap/index.js +++ b/dist/bootstrap/index.js @@ -5505,9 +5505,26 @@ function retry_until_rc(cmd, expected_rc = 0, maxRetries = 12, timeout = 10000) return false; }); } -function microk8s_init(addons) { +function microk8s_init(addons, docker_registry) { return __awaiter(this, void 0, void 0, function* () { // microk8s needs some additional things done to ensure it's ready for Juju. + // Add docker registry configuration if given. + if (docker_registry) { + let hostname; + let port; + try { + const docker_registry_url = new URL(docker_registry); + hostname = docker_registry_url.hostname; + port = docker_registry_url.port; + } + catch (err) { + core.setFailed(`Failed to parse URL of docker registry for microk8s: ${err}`); + return false; + } + yield exec.exec("bash", ["-c", `cat <> /var/snap/microk8s/current/args/certs.d/docker.io/hosts.toml\nserver = "${docker_registry}"\n\n[host."${hostname}:${port}"]\ncapabilities = ["pull", "resolve"]\nEOT`]); + yield exec.exec("microk8s stop"); + yield exec.exec("microk8s start"); + } // Add the given addons if any were given. yield exec_as_microk8s("microk8s status --wait-ready"); if (addons) { @@ -5583,6 +5600,7 @@ function run() { const microk8s_group = get_microk8s_group(); let bootstrap_constraints = core.getInput("bootstrap-constraints"); const microk8s_addons = core.getInput("microk8s-addons"); + const microk8s_docker_registry = core.getInput("microk8s-docker_registry"); let group = ""; try { core.addPath('/snap/bin'); @@ -5650,7 +5668,7 @@ function run() { core.endGroup(); core.startGroup("Initialize microk8s"); yield exec.exec('bash', ['-c', `sudo usermod -a -G ${microk8s_group} $USER`]); - if (!(yield microk8s_init(microk8s_addons))) { + if (!(yield microk8s_init(microk8s_addons, microk8s_docker_registry))) { return; } group = microk8s_group; @@ -5829,4 +5847,4 @@ module.exports = require("util");; /******/ // Load entry module and return exports /******/ return __nccwpck_require__(1098); /******/ })() -; +; \ No newline at end of file From 500ab08c8647c2d4f4b6a1835f0c1ff3db2df426 Mon Sep 17 00:00:00 2001 From: Adam Dyess Date: Tue, 12 Dec 2023 11:18:26 -0600 Subject: [PATCH 04/10] Use ts-dedent and fs to write file --- dist/bootstrap/index.js | 63 ++++++++++++++++++++++++++++++++++--- dist/bootstrap/licenses.txt | 25 +++++++++++++++ package-lock.json | 14 +++++++++ package.json | 1 + src/bootstrap/index.ts | 16 +++++++--- 5 files changed, 110 insertions(+), 9 deletions(-) diff --git a/dist/bootstrap/index.js b/dist/bootstrap/index.js index cb4547b..9355f31 100644 --- a/dist/bootstrap/index.js +++ b/dist/bootstrap/index.js @@ -4317,6 +4317,55 @@ const validRange = (range, options) => { module.exports = validRange +/***/ }), + +/***/ 3604: +/***/ ((__unused_webpack_module, exports) => { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.dedent = void 0; +function dedent(templ) { + var values = []; + for (var _i = 1; _i < arguments.length; _i++) { + values[_i - 1] = arguments[_i]; + } + var strings = Array.from(typeof templ === 'string' ? [templ] : templ); + strings[strings.length - 1] = strings[strings.length - 1].replace(/\r?\n([\t ]*)$/, ''); + var indentLengths = strings.reduce(function (arr, str) { + var matches = str.match(/\n([\t ]+|(?!\s).)/g); + if (matches) { + return arr.concat(matches.map(function (match) { var _a, _b; return (_b = (_a = match.match(/[\t ]/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0; })); + } + return arr; + }, []); + if (indentLengths.length) { + var pattern_1 = new RegExp("\n[\t ]{" + Math.min.apply(Math, indentLengths) + "}", 'g'); + strings = strings.map(function (str) { return str.replace(pattern_1, '\n'); }); + } + strings[0] = strings[0].replace(/^\r?\n/, ''); + var string = strings[0]; + values.forEach(function (value, i) { + var endentations = string.match(/(?:^|\n)( *)$/); + var endentation = endentations ? endentations[1] : ''; + var indentedValue = value; + if (typeof value === 'string' && value.includes('\n')) { + indentedValue = String(value) + .split('\n') + .map(function (str, i) { + return i === 0 ? str : "" + endentation + str; + }) + .join('\n'); + } + string += indentedValue + strings[i + 1]; + }); + return string; +} +exports.dedent = dedent; +exports.default = dedent; +//# sourceMappingURL=index.js.map + /***/ }), /***/ 2467: @@ -5443,8 +5492,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", ({ value: true })); const core = __importStar(__nccwpck_require__(2186)); const exec = __importStar(__nccwpck_require__(1514)); +const fs = __importStar(__nccwpck_require__(5747)); const utils_1 = __nccwpck_require__(2828); const semver_1 = __importDefault(__nccwpck_require__(1383)); +const ts_dedent_1 = __importDefault(__nccwpck_require__(3604)); const ignoreFail = { "ignoreReturnCode": true }; const os_release = () => __awaiter(void 0, void 0, void 0, function* () { // Read os-release file into an object @@ -5521,9 +5572,13 @@ function microk8s_init(addons, docker_registry) { core.setFailed(`Failed to parse URL of docker registry for microk8s: ${err}`); return false; } - yield exec.exec("bash", ["-c", `cat <> /var/snap/microk8s/current/args/certs.d/docker.io/hosts.toml\nserver = "${docker_registry}"\n\n[host."${hostname}:${port}"]\ncapabilities = ["pull", "resolve"]\nEOT`]); - yield exec.exec("microk8s stop"); - yield exec.exec("microk8s start"); + let content = ts_dedent_1.default ` + server = "${docker_registry}" + + [host."${hostname}:${port}"] + capabilities = ["pull", "resolve"] + `; + fs.writeFileSync("/var/snap/microk8s/current/args/certs.d/docker.io/hosts.toml", content); } // Add the given addons if any were given. yield exec_as_microk8s("microk8s status --wait-ready"); @@ -5600,7 +5655,7 @@ function run() { const microk8s_group = get_microk8s_group(); let bootstrap_constraints = core.getInput("bootstrap-constraints"); const microk8s_addons = core.getInput("microk8s-addons"); - const microk8s_docker_registry = core.getInput("microk8s-docker_registry"); + const microk8s_docker_registry = core.getInput("microk8s-docker-registry"); let group = ""; try { core.addPath('/snap/bin'); diff --git a/dist/bootstrap/licenses.txt b/dist/bootstrap/licenses.txt index a2724fe..9a8fa74 100644 --- a/dist/bootstrap/licenses.txt +++ b/dist/bootstrap/licenses.txt @@ -54,6 +54,31 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +ts-dedent +MIT +MIT License + +Copyright (c) 2018 Tamino Martinius + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + ts-retry MIT MIT License diff --git a/package-lock.json b/package-lock.json index ee2e49f..258a7c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "@actions/glob": "^0.2.0", "@types/semver": "^7.3.9", "semver": "^7.3.7", + "ts-dedent": "^2.2.0", "ts-retry": "^4.1.1" }, "devDependencies": { @@ -380,6 +381,14 @@ "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=" }, + "node_modules/ts-dedent": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/ts-dedent/-/ts-dedent-2.2.0.tgz", + "integrity": "sha512-q5W7tVM71e2xjHZTlgfTDoPF/SmqKG5hddq9SzR49CH2hayqRKJtQ4mtRlSxKaJlR/+9rEM+mnBHf7I2/BQcpQ==", + "engines": { + "node": ">=6.10" + } + }, "node_modules/ts-retry": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/ts-retry/-/ts-retry-4.1.1.tgz", @@ -747,6 +756,11 @@ "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=" }, + "ts-dedent": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/ts-dedent/-/ts-dedent-2.2.0.tgz", + "integrity": "sha512-q5W7tVM71e2xjHZTlgfTDoPF/SmqKG5hddq9SzR49CH2hayqRKJtQ4mtRlSxKaJlR/+9rEM+mnBHf7I2/BQcpQ==" + }, "ts-retry": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/ts-retry/-/ts-retry-4.1.1.tgz", diff --git a/package.json b/package.json index 0290a0f..32e1463 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "@actions/glob": "^0.2.0", "@types/semver": "^7.3.9", "semver": "^7.3.7", + "ts-dedent": "^2.2.0", "ts-retry": "^4.1.1" }, "devDependencies": { diff --git a/src/bootstrap/index.ts b/src/bootstrap/index.ts index d08f6c9..dba5d60 100644 --- a/src/bootstrap/index.ts +++ b/src/bootstrap/index.ts @@ -1,7 +1,9 @@ import * as core from '@actions/core'; import * as exec from '@actions/exec'; +import * as fs from 'fs'; import { retryAsyncDecorator } from 'ts-retry/lib/cjs/retry/utils'; import semver from 'semver'; +import dedent from 'ts-dedent'; declare var process : { env: { @@ -71,7 +73,7 @@ async function retry_until_rc(cmd: string, expected_rc=0, maxRetries=12, timeout return false; } -async function microk8s_init(addons, docker_registry) { +async function microk8s_init(addons, docker_registry:string) { // microk8s needs some additional things done to ensure it's ready for Juju. // Add docker registry configuration if given. if (docker_registry) { @@ -85,9 +87,13 @@ async function microk8s_init(addons, docker_registry) { core.setFailed(`Failed to parse URL of docker registry for microk8s: ${err}`); return false; } - await exec.exec("bash", ["-c", `cat <> /var/snap/microk8s/current/args/certs.d/docker.io/hosts.toml\nserver = "${docker_registry}"\n\n[host."${hostname}:${port}"]\ncapabilities = ["pull", "resolve"]\nEOT`]); - await exec.exec("microk8s stop") - await exec.exec("microk8s start") + let content = dedent` + server = "${docker_registry}" + + [host."${hostname}:${port}"] + capabilities = ["pull", "resolve"] + `; + fs.writeFileSync("/var/snap/microk8s/current/args/certs.d/docker.io/hosts.toml", content) } // Add the given addons if any were given. @@ -168,7 +174,7 @@ async function run() { const microk8s_group = get_microk8s_group(); let bootstrap_constraints = core.getInput("bootstrap-constraints"); const microk8s_addons = core.getInput("microk8s-addons") - const microk8s_docker_registry = core.getInput("microk8s-docker_registry") + const microk8s_docker_registry = core.getInput("microk8s-docker-registry") let group = ""; try { core.addPath('/snap/bin'); From 38aa3bfd837212f79a162cf5783563db4c4b179f Mon Sep 17 00:00:00 2001 From: Adam Dyess Date: Tue, 12 Dec 2023 13:41:55 -0600 Subject: [PATCH 05/10] use env variable MICROK8S_DOCKER_REGISTRY if available --- dist/bootstrap/index.js | 2 +- src/bootstrap/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/bootstrap/index.js b/dist/bootstrap/index.js index 9355f31..25a5350 100644 --- a/dist/bootstrap/index.js +++ b/dist/bootstrap/index.js @@ -5655,7 +5655,7 @@ function run() { const microk8s_group = get_microk8s_group(); let bootstrap_constraints = core.getInput("bootstrap-constraints"); const microk8s_addons = core.getInput("microk8s-addons"); - const microk8s_docker_registry = core.getInput("microk8s-docker-registry"); + const microk8s_docker_registry = core.getInput("microk8s-docker-registry") || process.env["MICROK8S_DOCKER_REGISTRY"]; let group = ""; try { core.addPath('/snap/bin'); diff --git a/src/bootstrap/index.ts b/src/bootstrap/index.ts index dba5d60..ec4ce92 100644 --- a/src/bootstrap/index.ts +++ b/src/bootstrap/index.ts @@ -174,7 +174,7 @@ async function run() { const microk8s_group = get_microk8s_group(); let bootstrap_constraints = core.getInput("bootstrap-constraints"); const microk8s_addons = core.getInput("microk8s-addons") - const microk8s_docker_registry = core.getInput("microk8s-docker-registry") + const microk8s_docker_registry = core.getInput("microk8s-docker-registry") || process.env["MICROK8S_DOCKER_REGISTRY"] let group = ""; try { core.addPath('/snap/bin'); From 4d0bc50ba48dc105afb7bb5020d4f4835c5a2bf6 Mon Sep 17 00:00:00 2001 From: yhaliaw <43424755+yhaliaw@users.noreply.github.com> Date: Wed, 13 Dec 2023 11:23:55 +0800 Subject: [PATCH 06/10] Add DOCKERHUB_MIRROR env var for setting docker registry --- dist/bootstrap/index.js | 12 ++++++++---- src/bootstrap/index.ts | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/dist/bootstrap/index.js b/dist/bootstrap/index.js index 25a5350..3d41b5e 100644 --- a/dist/bootstrap/index.js +++ b/dist/bootstrap/index.js @@ -5560,20 +5560,24 @@ function microk8s_init(addons, docker_registry) { return __awaiter(this, void 0, void 0, function* () { // microk8s needs some additional things done to ensure it's ready for Juju. // Add docker registry configuration if given. + let docker_registry_url = process.env.DOCKERHUB_MIRROR; if (docker_registry) { + docker_registry_url = docker_registry; + } + if (docker_registry_url) { let hostname; let port; try { - const docker_registry_url = new URL(docker_registry); - hostname = docker_registry_url.hostname; - port = docker_registry_url.port; + const url = new URL(docker_registry_url); + hostname = url.hostname; + port = url.port; } catch (err) { core.setFailed(`Failed to parse URL of docker registry for microk8s: ${err}`); return false; } let content = ts_dedent_1.default ` - server = "${docker_registry}" + server = "${docker_registry_url}" [host."${hostname}:${port}"] capabilities = ["pull", "resolve"] diff --git a/src/bootstrap/index.ts b/src/bootstrap/index.ts index ec4ce92..011a43c 100644 --- a/src/bootstrap/index.ts +++ b/src/bootstrap/index.ts @@ -76,19 +76,23 @@ async function retry_until_rc(cmd: string, expected_rc=0, maxRetries=12, timeout async function microk8s_init(addons, docker_registry:string) { // microk8s needs some additional things done to ensure it's ready for Juju. // Add docker registry configuration if given. + let docker_registry_url = process.env.DOCKERHUB_MIRROR; if (docker_registry) { + docker_registry_url = docker_registry; + } + if (docker_registry_url) { let hostname; let port; try { - const docker_registry_url = new URL(docker_registry); - hostname = docker_registry_url.hostname; - port = docker_registry_url.port; + const url = new URL(docker_registry_url); + hostname = url.hostname; + port = url.port; } catch(err) { core.setFailed(`Failed to parse URL of docker registry for microk8s: ${err}`); return false; } let content = dedent` - server = "${docker_registry}" + server = "${docker_registry_url}" [host."${hostname}:${port}"] capabilities = ["pull", "resolve"] From 776fff13fb93ec2cf3659603b50263af1d324263 Mon Sep 17 00:00:00 2001 From: yhaliaw <43424755+yhaliaw@users.noreply.github.com> Date: Wed, 13 Dec 2023 11:28:42 +0800 Subject: [PATCH 07/10] Revert "Add DOCKERHUB_MIRROR env var for setting docker registry" This reverts commit 4d0bc50ba48dc105afb7bb5020d4f4835c5a2bf6. --- dist/bootstrap/index.js | 12 ++++-------- src/bootstrap/index.ts | 12 ++++-------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/dist/bootstrap/index.js b/dist/bootstrap/index.js index 3d41b5e..25a5350 100644 --- a/dist/bootstrap/index.js +++ b/dist/bootstrap/index.js @@ -5560,24 +5560,20 @@ function microk8s_init(addons, docker_registry) { return __awaiter(this, void 0, void 0, function* () { // microk8s needs some additional things done to ensure it's ready for Juju. // Add docker registry configuration if given. - let docker_registry_url = process.env.DOCKERHUB_MIRROR; if (docker_registry) { - docker_registry_url = docker_registry; - } - if (docker_registry_url) { let hostname; let port; try { - const url = new URL(docker_registry_url); - hostname = url.hostname; - port = url.port; + const docker_registry_url = new URL(docker_registry); + hostname = docker_registry_url.hostname; + port = docker_registry_url.port; } catch (err) { core.setFailed(`Failed to parse URL of docker registry for microk8s: ${err}`); return false; } let content = ts_dedent_1.default ` - server = "${docker_registry_url}" + server = "${docker_registry}" [host."${hostname}:${port}"] capabilities = ["pull", "resolve"] diff --git a/src/bootstrap/index.ts b/src/bootstrap/index.ts index 011a43c..ec4ce92 100644 --- a/src/bootstrap/index.ts +++ b/src/bootstrap/index.ts @@ -76,23 +76,19 @@ async function retry_until_rc(cmd: string, expected_rc=0, maxRetries=12, timeout async function microk8s_init(addons, docker_registry:string) { // microk8s needs some additional things done to ensure it's ready for Juju. // Add docker registry configuration if given. - let docker_registry_url = process.env.DOCKERHUB_MIRROR; if (docker_registry) { - docker_registry_url = docker_registry; - } - if (docker_registry_url) { let hostname; let port; try { - const url = new URL(docker_registry_url); - hostname = url.hostname; - port = url.port; + const docker_registry_url = new URL(docker_registry); + hostname = docker_registry_url.hostname; + port = docker_registry_url.port; } catch(err) { core.setFailed(`Failed to parse URL of docker registry for microk8s: ${err}`); return false; } let content = dedent` - server = "${docker_registry_url}" + server = "${docker_registry}" [host."${hostname}:${port}"] capabilities = ["pull", "resolve"] From 449d10454cdb3c96fa3c78b331820ca20bb2909e Mon Sep 17 00:00:00 2001 From: yhaliaw <43424755+yhaliaw@users.noreply.github.com> Date: Wed, 13 Dec 2023 11:29:45 +0800 Subject: [PATCH 08/10] Change the env var input for microk8s to DOCKERHUB_MIRROR --- src/bootstrap/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/index.ts b/src/bootstrap/index.ts index ec4ce92..015c97c 100644 --- a/src/bootstrap/index.ts +++ b/src/bootstrap/index.ts @@ -174,7 +174,7 @@ async function run() { const microk8s_group = get_microk8s_group(); let bootstrap_constraints = core.getInput("bootstrap-constraints"); const microk8s_addons = core.getInput("microk8s-addons") - const microk8s_docker_registry = core.getInput("microk8s-docker-registry") || process.env["MICROK8S_DOCKER_REGISTRY"] + const microk8s_docker_registry = core.getInput("microk8s-docker-registry") || process.env["DOCKERHUB_MIRROR"] let group = ""; try { core.addPath('/snap/bin'); From 3e90dc7b4785ca6ceaacbcedf358ab62017f7867 Mon Sep 17 00:00:00 2001 From: yhaliaw <43424755+yhaliaw@users.noreply.github.com> Date: Wed, 13 Dec 2023 14:49:06 +0800 Subject: [PATCH 09/10] Build the src --- dist/bootstrap/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/bootstrap/index.js b/dist/bootstrap/index.js index 25a5350..4c4960b 100644 --- a/dist/bootstrap/index.js +++ b/dist/bootstrap/index.js @@ -5655,7 +5655,7 @@ function run() { const microk8s_group = get_microk8s_group(); let bootstrap_constraints = core.getInput("bootstrap-constraints"); const microk8s_addons = core.getInput("microk8s-addons"); - const microk8s_docker_registry = core.getInput("microk8s-docker-registry") || process.env["MICROK8S_DOCKER_REGISTRY"]; + const microk8s_docker_registry = core.getInput("microk8s-docker-registry") || process.env["DOCKERHUB_MIRROR"]; let group = ""; try { core.addPath('/snap/bin'); From c7c0c27b6cc34acd8c113c5412e559f88d5ea07d Mon Sep 17 00:00:00 2001 From: yhaliaw <43424755+yhaliaw@users.noreply.github.com> Date: Thu, 14 Dec 2023 10:22:03 +0800 Subject: [PATCH 10/10] Update microk8s-docker-registry to container-registry-url --- action.yaml | 4 ++-- dist/bootstrap/index.js | 20 ++++++++++---------- src/bootstrap/index.ts | 20 ++++++++++---------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/action.yaml b/action.yaml index 7bde60e..ae5f63f 100644 --- a/action.yaml +++ b/action.yaml @@ -60,8 +60,8 @@ inputs: description: "microk8s addons to enable" required: false default: "storage dns rbac" - microk8s-docker-registry: - description: "URL of docker registry for microk8s to use" + container-registry-url: + description: "Container registry to use" runs: using: "node16" main: "dist/bootstrap/index.js" diff --git a/dist/bootstrap/index.js b/dist/bootstrap/index.js index 4c4960b..12fbfa6 100644 --- a/dist/bootstrap/index.js +++ b/dist/bootstrap/index.js @@ -5556,24 +5556,24 @@ function retry_until_rc(cmd, expected_rc = 0, maxRetries = 12, timeout = 10000) return false; }); } -function microk8s_init(addons, docker_registry) { +function microk8s_init(addons, container_registry_url) { return __awaiter(this, void 0, void 0, function* () { // microk8s needs some additional things done to ensure it's ready for Juju. - // Add docker registry configuration if given. - if (docker_registry) { + // Add container registry configuration if given. + if (container_registry_url) { let hostname; let port; try { - const docker_registry_url = new URL(docker_registry); - hostname = docker_registry_url.hostname; - port = docker_registry_url.port; + const url = new URL(container_registry_url); + hostname = url.hostname; + port = url.port; } catch (err) { - core.setFailed(`Failed to parse URL of docker registry for microk8s: ${err}`); + core.setFailed(`Failed to parse URL of container registry for microk8s: ${err}`); return false; } let content = ts_dedent_1.default ` - server = "${docker_registry}" + server = "${container_registry_url}" [host."${hostname}:${port}"] capabilities = ["pull", "resolve"] @@ -5655,7 +5655,7 @@ function run() { const microk8s_group = get_microk8s_group(); let bootstrap_constraints = core.getInput("bootstrap-constraints"); const microk8s_addons = core.getInput("microk8s-addons"); - const microk8s_docker_registry = core.getInput("microk8s-docker-registry") || process.env["DOCKERHUB_MIRROR"]; + const container_registry_url = core.getInput("container-registry-url") || process.env["CONTAINER_REGISTRY_URL"]; let group = ""; try { core.addPath('/snap/bin'); @@ -5723,7 +5723,7 @@ function run() { core.endGroup(); core.startGroup("Initialize microk8s"); yield exec.exec('bash', ['-c', `sudo usermod -a -G ${microk8s_group} $USER`]); - if (!(yield microk8s_init(microk8s_addons, microk8s_docker_registry))) { + if (!(yield microk8s_init(microk8s_addons, container_registry_url))) { return; } group = microk8s_group; diff --git a/src/bootstrap/index.ts b/src/bootstrap/index.ts index 015c97c..75a26e0 100644 --- a/src/bootstrap/index.ts +++ b/src/bootstrap/index.ts @@ -73,22 +73,22 @@ async function retry_until_rc(cmd: string, expected_rc=0, maxRetries=12, timeout return false; } -async function microk8s_init(addons, docker_registry:string) { +async function microk8s_init(addons, container_registry_url:string) { // microk8s needs some additional things done to ensure it's ready for Juju. - // Add docker registry configuration if given. - if (docker_registry) { + // Add container registry configuration if given. + if (container_registry_url) { let hostname; let port; try { - const docker_registry_url = new URL(docker_registry); - hostname = docker_registry_url.hostname; - port = docker_registry_url.port; + const url = new URL(container_registry_url); + hostname = url.hostname; + port = url.port; } catch(err) { - core.setFailed(`Failed to parse URL of docker registry for microk8s: ${err}`); + core.setFailed(`Failed to parse URL of container registry for microk8s: ${err}`); return false; } let content = dedent` - server = "${docker_registry}" + server = "${container_registry_url}" [host."${hostname}:${port}"] capabilities = ["pull", "resolve"] @@ -174,7 +174,7 @@ async function run() { const microk8s_group = get_microk8s_group(); let bootstrap_constraints = core.getInput("bootstrap-constraints"); const microk8s_addons = core.getInput("microk8s-addons") - const microk8s_docker_registry = core.getInput("microk8s-docker-registry") || process.env["DOCKERHUB_MIRROR"] + const container_registry_url = core.getInput("container-registry-url") || process.env["CONTAINER_REGISTRY_URL"] let group = ""; try { core.addPath('/snap/bin'); @@ -242,7 +242,7 @@ async function run() { core.endGroup(); core.startGroup("Initialize microk8s"); await exec.exec('bash', ['-c', `sudo usermod -a -G ${microk8s_group} $USER`]); - if(!await microk8s_init(microk8s_addons, microk8s_docker_registry)) { + if(!await microk8s_init(microk8s_addons, container_registry_url)) { return; } group = microk8s_group;