diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 38ae68d..035508a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,56 +14,68 @@ jobs: image: registry:2 ports: - 5000:5000 - name: Test stacker-build action + name: Test stacker-build-push-action steps: - uses: actions/checkout@v2 - name: Run stacker-build with all build inputs uses: ./ with: - stackerfile: 'test/stacker.yaml' - substitutes: 'SUB1=VAR1 SUB2=VAR2 SUB3=VAR3' + file: 'test/stacker.yaml' + build-args: | + SUB1=VAR1 + SUB2=VAR2 + SUB3=VAR3 layer-type: 'tar squashfs' - - name: Run stacker-build with only substitutes + - name: Run stacker-build with only build-args uses: ./ with: - stackerfile: 'test/stacker.yaml' - substitutes: 'SUB1=VAR1 SUB2=VAR2 SUB3=VAR3' + file: 'test/stacker.yaml' + build-args: | + SUB1=VAR1 + SUB2=VAR2 + SUB3=VAR3 - name: Run stacker-build with only layer-type uses: ./ with: - stackerfile: 'test/stacker_wo_subs.yaml' + file: 'test/stacker_wo_subs.yaml' layer-type: 'tar squashfs' - - name: Run stacker-build with only stackerfile + - name: Run stacker-build with only file input uses: ./ with: - stackerfile: 'test/stacker_wo_subs.yaml' + file: 'test/stacker_wo_subs.yaml' - name: Run stacker-build with push and tags uses: ./ with: - stackerfile: 'test/stacker_wo_subs.yaml' + file: '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 + - name: Run stacker-build with push, tags and build-args uses: ./ with: - stackerfile: 'test/stacker.yaml' - substitutes: 'SUB1=VAR1 SUB2=VAR2 SUB3=VAR3' + file: 'test/stacker.yaml' + build-args: | + 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 + - name: Run stacker-build with push, tags, build-args and layer-type uses: ./ with: - stackerfile: 'test/stacker.yaml' - substitutes: 'SUB1=VAR1 SUB2=VAR2 SUB3=VAR3' + file: 'test/stacker.yaml' + build-args: | + SUB1=VAR1 + SUB2=VAR2 + SUB3=VAR3 tags: v1 latest url: docker://localhost:5000/name/app layer-type: 'tar squashfs' diff --git a/README.md b/README.md index e6388e0..4a81597 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # 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. +```stacker-build-push-action``` builds OCI container images via a declarative yaml format and publish them to OCI registries. -stacker only works on Linux +stacker only works on Linux! For more information about stacker tool see: https://github.com/project-stacker/stacker @@ -12,16 +12,17 @@ For more information about stacker tool see: https://github.com/project-stacker/ -| Input Name | Description | Default | -| ---------- | ----------- | ------- | -| 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 -| url | remote OCI registry + repo name eg: docker://ghcr.io/project-stacker/ | None -| tags | one or more tags to give the new image, separated by whitespace | None -| username | used to login to registry | None -| password | used to login to registry | None -| skip-tls | used with unsecure (http) registries | false +| Input Name | Type | Description | Default | +| ---------- | ---- |----------- | ------- | +| file | string |the yaml file to be built as an OCI image, example: [stacker.yaml](./test/stacker.yaml) | stacker.yaml +| layer-type | list | output layer type (supported values: tar, squashfs), ca be both separated by whitespace | tar +| build-args | list | the list of build-time arguments (subtitutes) separated by newline, see [stacker.yaml doc](https://github.com/project-stacker/stacker/blob/master/doc/stacker_yaml.md) | None +| url | string | remote OCI registry + repo name eg: docker://ghcr.io/project-stacker/ | None +| tags | list | one or more tags to give the new image, separated by whitespace | None +| username | string | used to login to registry | None +| password | string | used to login to registry | None +| skip-tls | bool | used with unsecure (http) registries | false +| token | string |github token used to authenticate against a repository for Git context | ${{ github.token }} Build only example: @@ -30,8 +31,11 @@ Build only example: - name: Run stacker-build uses: project-stacker/stacker-build-push-action@main with: - stackerfile: 'test/stacker.yaml' - substitutes: 'SUB1=VAR1 SUB2=VAR2 SUB3=VAR3' + file: 'test/stacker.yaml' + build-args: | + SUB1=VAR1 + SUB2=VAR2 + SUB3=VAR3 layer-type: 'tar squashfs' ``` @@ -47,8 +51,11 @@ 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' + file: 'test/stacker.yaml' + build-args: | + SUB1=VAR1 + SUB2=VAR2 + SUB3=VAR3 layer-type: 'tar squashfs' tags: ${{ github.event.release.tag_name }} latest url: docker://ghcr.io/${{ github.repository }} @@ -66,8 +73,11 @@ 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' + file: 'test/stacker.yaml' + build-args: | + SUB1=VAR1 + SUB2=VAR2 + SUB3=VAR3 layer-type: 'tar squashfs' url: docker://localhost:5000 skip-tls: true diff --git a/action.yml b/action.yml index d5f74f6..6958887 100644 --- a/action.yml +++ b/action.yml @@ -5,8 +5,8 @@ inputs: description: 'Which stacker version to use' required: false default: 'latest' - stackerfile: # id of input - description: 'Which stackerfile to build' + file: + description: 'Which stacker file to build' required: true default: 'stacker.yaml' layer-type: @@ -14,11 +14,11 @@ inputs: required: false default: "tar" token: - description: 'Used to pull stacker release binaries' + description: 'GitHub Token used to authenticate against a repository for Git context' required: false default: ${{ github.token }} - substitutes: - description: 'The list of subtitutes to make in stacker file separated by whitespace, eg: ONE=1 TWO=2 THREE=3' + build-args: + description: 'The list of build-time arguments 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' diff --git a/dist/index.js b/dist/index.js index f9eba0d..bb55d18 100644 --- a/dist/index.js +++ b/dist/index.js @@ -23841,6 +23841,31 @@ function makeAvailableInPath(download, version) { }); } +;// CONCATENATED MODULE: ./src/utils.ts + +function splitByNewline(s) { + return s.split(/\r?\n/); +} +function getInputList(name) { + const items = core.getInput(name); + if (!items) { + return []; + } + const splitItems = splitByNewline(items); + return splitItems + .reduce((acc, line) => acc.concat(line).map((item) => item.trim()), []); +} +function getSpaceSeparatedInput(name) { + const items = core.getInput(name); + if (items.length === 0) { + core.debug("empty"); + return []; + } + const splitItems = items.trim().split(/\s+/); + return splitItems + .reduce((acc, line) => acc.concat(line).map((item) => item.trim()), []); +} + ;// CONCATENATED MODULE: ./src/index.ts var src_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } @@ -23856,6 +23881,7 @@ var src_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argu + const stackerBin = "stacker"; const stackerOrg = "project-stacker"; const stackerRepo = "stacker"; @@ -23879,29 +23905,17 @@ function run() { const stackerPath = yield io.which("stacker", true); const cli = new StackerCLI(stackerPath); yield cli.execute(["--version"], { group: true }); - const stackerfile = core.getInput("stackerfile"); - var substitutesList = []; - const substitutes = core.getInput("substitutes"); - if (substitutes != "") { - substitutesList = substitutes.trim().split(/\s+/); - } - var layerTypeList = []; - const layerType = core.getInput("layer-type"); - if (layerType != "") { - 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 stackerfile = core.getInput("file"); + const substitutes = getInputList("build-args"); + const layerTypes = getSpaceSeparatedInput("layer-type"); + yield cli.build(stackerfile, layerTypes, substitutes); + const tags = getSpaceSeparatedInput("tags"); 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); + yield cli.publish(stackerfile, layerTypes, substitutes, registryURL, tags, username, password, skipTLS); } }); } diff --git a/src/index.ts b/src/index.ts index 6a427fa..3285ef9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,6 +4,7 @@ import * as tc from "@actions/tool-cache"; import { StackerCLI } from "./stacker"; import * as installer from "./installer"; +import * as utils from "./utils"; export const stackerBin = "stacker"; export const stackerOrg = "project-stacker"; @@ -37,28 +38,18 @@ export async function run(): Promise { await cli.execute(["--version"], { group: true }); // get stacker file path from input - const stackerfile = core.getInput("stackerfile"); + const stackerfile = core.getInput("file"); - // get substitutes from input - var substitutesList: string[] = []; - const substitutes = core.getInput("substitutes"); - if (substitutes != "") { - substitutesList = substitutes.trim().split(/\s+/); - } + // get build-args from input + const substitutes = utils.getInputList("build-args"); - var layerTypeList: string[] = []; - const layerType = core.getInput("layer-type"); - if (layerType != "") { - layerTypeList = layerType.trim().split(/\s+/); - } + // get layer-type from input + const layerTypes = utils.getSpaceSeparatedInput("layer-type"); - await cli.build(stackerfile, layerTypeList, substitutesList); + await cli.build(stackerfile, layerTypes, substitutes); - var tagsList: string[] = []; - const tags = core.getInput("tags"); - if (tags != "") { - tagsList = tags.trim().split(/\s+/); - } + // get tags from input + const tags = utils.getSpaceSeparatedInput("tags"); const registryURL = core.getInput("url"); const username = core.getInput("username"); @@ -66,8 +57,8 @@ export async function run(): Promise { const skipTLS = core.getInput("skip-tls") === "true"; if (registryURL) { - await cli.publish(stackerfile, layerTypeList, substitutesList, - registryURL, tagsList, username, password, skipTLS); + await cli.publish(stackerfile, layerTypes, substitutes, + registryURL, tags, username, password, skipTLS); } } diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..4ba962b --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,33 @@ +import * as core from "@actions/core"; + +export function splitByNewline(s: string): string[] { + return s.split(/\r?\n/); +} + +export function getInputList(name: string): string[] { + const items = core.getInput(name); + if (!items) { + return []; + } + const splitItems = splitByNewline(items); + return splitItems + .reduce( + (acc, line) => acc.concat(line).map((item) => item.trim()), + [], + ); +} + +export function getSpaceSeparatedInput(name: string): string[] { + const items = core.getInput(name); + if (items.length === 0) { + core.debug("empty"); + return []; + } + const splitItems = items.trim().split(/\s+/); + + return splitItems + .reduce( + (acc, line) => acc.concat(line).map((item) => item.trim()), + [], + ); +}