diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 374c334..d8ecd98 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,3 +25,20 @@ jobs: - name: Destroy cluster run: | cat /tmp/cluster_id.txt | xargs -I % nsc cluster destroy % --force + + push_image: + runs-on: ubuntu-latest + name: Push an image to the Namespace Cloud registry + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up Namespace Cloud CLI + id: nscloud + uses: ./ # Uses an action in the root directory + - name: Push to private registry + run: | + echo "Pushing to ${{ steps.nscloud.outputs.registry-address }}..." + + docker pull alpine:3.17.2 + docker tag alpine:3.17.2 ${{ steps.nscloud.outputs.registry-address }}/nscloud-alpine + docker push ${{ steps.nscloud.outputs.registry-address }}/nscloud-alpine diff --git a/action.yml b/action.yml index f6aea0b..00b3c3b 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,8 @@ name: '"Set up Namespace Cloud CLI" Action For GitHub Actions' description: "Download and configure the Namespace Cloud CLI" +outputs: + registry-address: + description: "Endpoint address of the Namespace Cloud registry." runs: using: node16 main: dist/main/index.js diff --git a/dist/main/index.js b/dist/main/index.js index 3be080a..31ea153 100644 --- a/dist/main/index.js +++ b/dist/main/index.js @@ -6757,12 +6757,19 @@ var __webpack_exports__ = {}; (() => { "use strict"; __nccwpck_require__.r(__webpack_exports__); +/* harmony export */ __nccwpck_require__.d(__webpack_exports__, { +/* harmony export */ "tmpFile": () => (/* binding */ tmpFile) +/* harmony export */ }); /* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(2186); /* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(_actions_core__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var _actions_tool_cache__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(7784); /* harmony import */ var _actions_tool_cache__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__nccwpck_require__.n(_actions_tool_cache__WEBPACK_IMPORTED_MODULE_1__); /* harmony import */ var _actions_exec__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(1514); /* harmony import */ var _actions_exec__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__nccwpck_require__.n(_actions_exec__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_3__ = __nccwpck_require__(7147); +/* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__nccwpck_require__.n(fs__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_4__ = __nccwpck_require__(1017); +/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__nccwpck_require__.n(path__WEBPACK_IMPORTED_MODULE_4__); var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { @@ -6775,11 +6782,15 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume + + function run() { return __awaiter(this, void 0, void 0, function* () { try { yield installNsc(); yield ensureFreshTenantToken(); + const registry = yield dockerLogin(); + _actions_core__WEBPACK_IMPORTED_MODULE_0__.setOutput("registry-address", registry); } catch (error) { _actions_core__WEBPACK_IMPORTED_MODULE_0__.setFailed(error.message); @@ -6831,6 +6842,20 @@ function ensureFreshTenantToken() { yield _actions_exec__WEBPACK_IMPORTED_MODULE_2__.exec("nsc auth exchange-github-token"); }); } +function dockerLogin() { + return __awaiter(this, void 0, void 0, function* () { + const out = tmpFile("registry.txt"); + yield _actions_exec__WEBPACK_IMPORTED_MODULE_2__.exec(`nsc cluster docker-login --output_registry_to=${out}`); + return fs__WEBPACK_IMPORTED_MODULE_3__.readFileSync(out, "utf8"); + }); +} +function tmpFile(file) { + const tmpDir = path__WEBPACK_IMPORTED_MODULE_4__.join(process.env.RUNNER_TEMP, "ns"); + if (!fs__WEBPACK_IMPORTED_MODULE_3__.existsSync(tmpDir)) { + fs__WEBPACK_IMPORTED_MODULE_3__.mkdirSync(tmpDir); + } + return path__WEBPACK_IMPORTED_MODULE_4__.join(tmpDir, file); +} run(); })(); diff --git a/main.ts b/main.ts index ea4142d..3235b4c 100644 --- a/main.ts +++ b/main.ts @@ -1,12 +1,17 @@ import * as core from "@actions/core"; import * as tc from "@actions/tool-cache"; import * as exec from "@actions/exec"; +import * as fs from "fs"; +import * as path from "path"; async function run(): Promise { try { await installNsc(); await ensureFreshTenantToken(); + + const registry = await dockerLogin(); + core.setOutput("registry-address", registry); } catch (error) { core.setFailed(error.message); } @@ -62,4 +67,21 @@ async function ensureFreshTenantToken() { await exec.exec("nsc auth exchange-github-token"); } +async function dockerLogin() { + const out = tmpFile("registry.txt"); + await exec.exec(`nsc cluster docker-login --output_registry_to=${out}`); + + return fs.readFileSync(out, "utf8"); +} + +export function tmpFile(file: string): string { + const tmpDir = path.join(process.env.RUNNER_TEMP, "ns"); + + if (!fs.existsSync(tmpDir)) { + fs.mkdirSync(tmpDir); + } + + return path.join(tmpDir, file); +} + run();