diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bdb7be6..38ae68d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,33 +1,70 @@ -on: [push] +on: + push: + branches: + - main + pull_request: + branches: + - main jobs: ci: runs-on: ubuntu-latest + services: + registry: + image: registry:2 + ports: + - 5000:5000 name: Test stacker-build action steps: - uses: actions/checkout@v2 - - name: Run stacker-build with all inputs - uses: project-stacker/stacker-build-action@main + - name: Run stacker-build with all build inputs + uses: ./ with: stackerfile: 'test/stacker.yaml' substitutes: 'SUB1=VAR1 SUB2=VAR2 SUB3=VAR3' layer-type: 'tar squashfs' - name: Run stacker-build with only substitutes - uses: project-stacker/stacker-build-action@main + uses: ./ with: stackerfile: 'test/stacker.yaml' substitutes: 'SUB1=VAR1 SUB2=VAR2 SUB3=VAR3' - name: Run stacker-build with only layer-type - uses: project-stacker/stacker-build-action@main + uses: ./ with: stackerfile: 'test/stacker_wo_subs.yaml' layer-type: 'tar squashfs' - name: Run stacker-build with only stackerfile - uses: project-stacker/stacker-build-action@main + uses: ./ with: stackerfile: 'test/stacker_wo_subs.yaml' - + + - name: Run stacker-build with push and tags + uses: ./ + with: + stackerfile: 'test/stacker_wo_subs.yaml' + tags: v1 latest + url: docker://localhost:5000/name/app + skip-tls: true + + - name: Run stacker-build with push, tags and substitutes + uses: ./ + with: + stackerfile: 'test/stacker.yaml' + substitutes: 'SUB1=VAR1 SUB2=VAR2 SUB3=VAR3' + tags: v1 latest + url: docker://localhost:5000/name/app + skip-tls: true + + - name: Run stacker-build with push, tags, substitutes and layer-type + uses: ./ + with: + stackerfile: 'test/stacker.yaml' + substitutes: 'SUB1=VAR1 SUB2=VAR2 SUB3=VAR3' + tags: v1 latest + url: docker://localhost:5000/name/app + layer-type: 'tar squashfs' + skip-tls: true diff --git a/README.md b/README.md index 2b0b02e..87c878c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# stacker-build-action -# [![ci](https://github.com/project-stacker/stacker-build-action/actions/workflows/ci.yaml/badge.svg?branch=main)](https://github.com/project-stacker/stacker-build-action/actions) +# stacker-build-push-action +# [![ci](https://github.com/project-stacker/stacker-build-push-action/actions/workflows/ci.yaml/badge.svg?branch=main)](https://github.com/project-stacker/stacker-build-push-action/actions) stacker build action builds OCI container images via a declarative yaml format. @@ -17,16 +17,48 @@ For more information about stacker tool see: https://github.com/project-stacker/ | stackerfile | the yaml file to be built as an OCI image, example: [stacker.yaml](./test/stacker.yaml) | stacker.yaml | layer-type | output layer type (supported values: tar, squashfs), ca be both separated by whitespace | tar | substitutes | variable substitution in stackerfile, see [stacker.yaml doc](https://github.com/project-stacker/stacker/blob/master/doc/stacker_yaml.md) | None -| version | stacker version to use | latest +| url | remote OCI registry | None +| tags | one or more tags to give the new image, eparated by whitespace | None +| username | used to login to registry | None +| username | used to login to registry | None +| skip-tls | used with unsecure (http) registries | false -Example: +Build only example: ``` - name: Run stacker-build - uses: project-stacker/stacker-build-action@main + uses: project-stacker/stacker-build-push-action@main with: stackerfile: 'test/stacker.yaml' substitutes: 'SUB1=VAR1 SUB2=VAR2 SUB3=VAR3' layer-type: 'tar squashfs' ``` + +Build and push example to ghcr.io: + +``` +- name: Run stacker-build + uses: project-stacker/stacker-build-push-action@main + with: + stackerfile: 'test/stacker.yaml' + substitutes: 'SUB1=VAR1 SUB2=VAR2 SUB3=VAR3' + layer-type: 'tar squashfs' + url: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + skip-tls: true +``` + +Build and push example to localhost: + +``` +- name: Run stacker-build + uses: project-stacker/stacker-build-push-action@main + with: + stackerfile: 'test/stacker.yaml' + substitutes: 'SUB1=VAR1 SUB2=VAR2 SUB3=VAR3' + layer-type: 'tar squashfs' + url: localhost:5000 + skip-tls: true +``` diff --git a/action.yml b/action.yml index 74356fa..d5f74f6 100644 --- a/action.yml +++ b/action.yml @@ -7,7 +7,7 @@ inputs: default: 'latest' stackerfile: # id of input description: 'Which stackerfile to build' - required: false + required: true default: 'stacker.yaml' layer-type: description: 'Set the output layer type (supported values: tar, squashfs) separated by whitespace' @@ -20,6 +20,21 @@ inputs: substitutes: description: 'The list of subtitutes to make in stacker file separated by whitespace, eg: ONE=1 TWO=2 THREE=3' required: false + tags: + description: 'Tags used when pushing to remote OCI registry, separated by whitespace' + required: false + url: + description: 'Remote registry URL, eg: docker://ghcr.io/myRepo' + required: false + username: + description: "Username for the remote registry" + required: false + password: + description: "Password for the remote registry" + required: false + skip-tls: + description: "Skip tls verify on unsecure http registry" + required: false runs: using: 'node16' main: 'dist/index.js' diff --git a/dist/index.js b/dist/index.js index 93e3b04..f9eba0d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -23691,6 +23691,39 @@ class StackerCLI { return res; }); } + publish(stackerfile, layerType, substitutes, url, tags, username, password, skipTLS) { + return __awaiter(this, void 0, void 0, function* () { + const args = ["--debug", "publish"]; + layerType.forEach((layerType) => { + args.push("--layer-type"); + args.push(layerType); + }); + substitutes.forEach((substitute) => { + args.push("--substitute"); + args.push(substitute); + }); + args.push("--url"); + args.push(url); + tags.forEach((tag) => { + args.push("--tag"); + args.push(tag); + }); + if (username) { + args.push("--username"); + args.push(username); + } + if (password) { + args.push("--password"); + args.push(password); + } + if (skipTLS) { + args.push("--skip-tls"); + } + args.push("-f"); + args.push(stackerfile); + return this.execute(args); + }); + } execute(args, execOptions = {}) { return __awaiter(this, void 0, void 0, function* () { let stdout = ""; @@ -23858,6 +23891,18 @@ function run() { layerTypeList = layerType.trim().split(/\s+/); } yield cli.build(stackerfile, layerTypeList, substitutesList); + var tagsList = []; + const tags = core.getInput("tags"); + if (tags != "") { + tagsList = tags.trim().split(/\s+/); + } + const registryURL = core.getInput("url"); + const username = core.getInput("username"); + const password = core.getInput("password"); + const skipTLS = core.getInput("skip-tls") === "true"; + if (registryURL) { + yield cli.publish(stackerfile, layerTypeList, substitutesList, registryURL, tagsList, username, password, skipTLS); + } }); } run().catch(core.setFailed); diff --git a/package.json b/package.json index 82707a0..058e5b5 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "stacker-build-action", + "name": "stacker-build-push-action", "version": "1.0.0", "description": "github action build OCI container images", "main": "index.js", @@ -8,15 +8,15 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/project-stacker/stacker-build-action.git" + "url": "git+https://github.com/project-stacker/stacker-build-push-action.git" }, "keywords": [], "author": "", "license": "ISC", "bugs": { - "url": "https://github.com/project-stacker/stacker-build-action/issues" + "url": "https://github.com/project-stacker/stacker-build-push-action/issues" }, - "homepage": "https://github.com/project-stacker/stacker-build-action#readme", + "homepage": "https://github.com/project-stacker/stacker-build-push-action#readme", "dependencies": { "@actions/core": "^1.6.0", "@actions/exec": "^1.1.1", diff --git a/src/index.ts b/src/index.ts index 43e9ee6..6a427fa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -54,7 +54,21 @@ export async function run(): Promise { await cli.build(stackerfile, layerTypeList, substitutesList); - + var tagsList: string[] = []; + const tags = core.getInput("tags"); + if (tags != "") { + tagsList = tags.trim().split(/\s+/); + } + + const registryURL = core.getInput("url"); + const username = core.getInput("username"); + const password = core.getInput("password"); + const skipTLS = core.getInput("skip-tls") === "true"; + + if (registryURL) { + await cli.publish(stackerfile, layerTypeList, substitutesList, + registryURL, tagsList, username, password, skipTLS); + } } run().catch(core.setFailed); diff --git a/src/installer.ts b/src/installer.ts index 3585d2b..2b4d742 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -65,4 +65,3 @@ export async function makeAvailableInPath(download, version) { core.info(`Make ${cachedPath} available in path`); core.addPath(cachedPath); } - diff --git a/src/stacker.ts b/src/stacker.ts index b844010..dc33a97 100644 --- a/src/stacker.ts +++ b/src/stacker.ts @@ -38,14 +38,56 @@ export class StackerCLI { const res = this.execute(args).then((res) => { if (res.exitCode == 0) { - core.info("printing oci layout index.json") - exec.exec('/bin/bash -c "cat oci/index.json | jq"', []) + core.info("printing oci layout index.json"); + exec.exec('/bin/bash -c "cat oci/index.json | jq"', []); } - return res + return res; }) - return res + return res; + } + + async publish(stackerfile: string, layerType: string[], substitutes: string[], + url: string, tags: string[], username: string, password: string, skipTLS: boolean): Promise { + const args: string[] = ["--debug", "publish"]; + + layerType.forEach((layerType) => { + args.push("--layer-type"); + args.push(layerType); + }) + + substitutes.forEach((substitute) => { + args.push("--substitute"); + args.push(substitute); + }); + + args.push("--url"); + args.push(url); + + tags.forEach((tag) => { + args.push("--tag"); + args.push(tag); + }) + + if (username) { + args.push("--username"); + args.push(username); + } + + if (password) { + args.push("--password"); + args.push(password); + } + + if (skipTLS) { + args.push("--skip-tls"); + } + + args.push("-f"); + args.push(stackerfile); + + return this.execute(args); } async execute( diff --git a/test/stacker.yaml b/test/stacker.yaml index d56dada..be120dc 100644 --- a/test/stacker.yaml +++ b/test/stacker.yaml @@ -1,3 +1,4 @@ +# container name test: from: type: docker