-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GitHub Action + Docker tag suffix (#16)
* Metadata to make a GitHub Action * Add options to suffix a tag and pass docker build options * GHA: use a JavaScript action The composite action didn't work as expected (the action's `action.sh` and `build.sh` weren't accessible), so I replaced the shell script with a tiny JavaScript bootstrap, that will properly collect the action inputs and generate a simple local build.sh and calls it. Note that we couldn't use a Docker container action, because we couldn't access the host docker ending, and would need to add both docker cli and docker server to the docker container... * fix: disable shellcheck warning (BUILD_OPTS _must_ be splat) * Tests for -t suffix and -o buildOptions build arguments * Remove already removed `latest` flag See 5d99055 --------- Co-authored-by: Matias Garcia Isaia <[email protected]>
- Loading branch information
1 parent
0558902
commit 0084f2b
Showing
5 changed files
with
128 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const process = require("process") | ||
const { spawn } = require("child_process") | ||
const fs = require("fs") | ||
|
||
// basic implementation of @action/core.getInput() | ||
function getInput(name) { | ||
return process.env[`INPUT_${name.toUpperCase()}`].trim() | ||
} | ||
|
||
// collect action inputs: | ||
let setupOpts = [] | ||
if (getInput("skip-login") === "true") setupOpts.push("--skip-login") | ||
|
||
let buildOpts = [], value | ||
if ((value = getInput("repository")) !== "") buildOpts.push(`-r ${value}`) | ||
if ((value = getInput("repository-suffix")) !== "") buildOpts.push(`-s ${value}`) | ||
if ((value = getInput("tag-suffix")) !== "") buildOpts.push(`-t ${value}`) | ||
if ((value = getInput("build-directory")) !== "") buildOpts.push(`-d ${value}`) | ||
if ((value = getInput("build-options")) !== "") buildOpts.push(`-o "${value}"`) | ||
|
||
// generate a local build.sh script: | ||
fs.writeFileSync("build.sh", `#! bash | ||
source ${__dirname}/build.sh | ||
dockerSetup ${setupOpts.join(" ")} | ||
echo $VERSION > VERSION | ||
dockerBuildAndPush ${buildOpts.join(" ")} | ||
`) | ||
|
||
// execute it: | ||
const build = spawn("bash", ["build.sh"], { maxBuffer: 100 * 1024 * 1024 }) | ||
build.stdout.on("data", data => { process.stdout.write(data) }) | ||
build.stderr.on("data", data => { process.stderr.write(data) }) | ||
build.on("error", error => { console.error(error) }) | ||
build.on("exit", code => { process.exit(code) }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Metadata for the GitHub Action | ||
name: CI Docker Builder | ||
author: Manas | ||
description: Build and publish Docker image(s) | ||
|
||
inputs: | ||
skip-login: | ||
type: boolean | ||
|
||
repository: | ||
type: string | ||
|
||
repository-suffix: | ||
type: string | ||
|
||
tag-suffix: | ||
type: string | ||
|
||
build-directory: | ||
type: string | ||
|
||
build-options: | ||
type: string | ||
|
||
runs: | ||
using: node16 | ||
main: action.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters