Skip to content

Commit b346fda

Browse files
authored
Merge pull request #103 from LonghronShen/master
feat(base_image): add custom base_image argument
2 parents b101fff + b0c64c5 commit b346fda

File tree

6 files changed

+34
-10
lines changed

6 files changed

+34
-10
lines changed

.github/workflows/advanced-example.yml

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ jobs:
2121
distro: fedora_latest
2222
- arch: armv7
2323
distro: archarm_latest
24+
- arch: x86_64
25+
distro: ubuntu18.04
26+
base_image: ubuntu:18.04
2427

2528
steps:
2629
- uses: actions/checkout@v3
@@ -30,6 +33,7 @@ jobs:
3033
with:
3134
arch: ${{ matrix.arch }}
3235
distro: ${{ matrix.distro }}
36+
base_image: ${{ matrix.base_image }}
3337

3438
# Not required, but speeds up builds
3539
githubToken: ${{ github.token }}

.github/workflows/test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ jobs:
8585
install: |
8686
case "${{ matrix.distro }}" in
8787
ubuntu*|jessie|stretch|buster|bullseye)
88-
apt-get update -q -y
89-
apt-get install -q -y git
88+
apt-get update -q -y --force-yes
89+
apt-get install -q -y --force-yes git
9090
;;
9191
fedora*)
9292
dnf -y update

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.vscode/

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The action also accepts some optional input parameters:
2020
* `dockerRunArgs`: Additional arguments to pass to `docker run`, such as volume mappings. See [`docker run` documentation](https://docs.docker.com/engine/reference/commandline/run).
2121
* `setup`: Shell commands to execute on the host before running the container, such as creating directories for volume mappings.
2222
* `install`: Shell commands to execute in the container as part of `docker build`, such as installing dependencies. This speeds up subsequent builds if `githubToken` is also used, but note that the image layer will be publicly available in your projects GitHub Package Registry, so make sure the resulting image does not have any secrets cached in logs or state.
23+
* `base_image`: Specify a custom base image, such as **busybox** or your predefined base image. This will replace the **FROM** claus in the default Dockerfile on the fly. This is optional. Hint: with this option you are able to use all the available archs other than the ones showed in this page. See the [advanced example](./.github/workflows/advanced-example.yml) in this repo. For more detials, see [PR #103](https://github.com/uraimo/run-on-arch-action/pull/103#issuecomment-1363810049).
2324

2425
### Basic example
2526

action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ inputs:
3939
description: 'Shell commands to execute in the container as part of docker build, such as installing dependencies. This speeds up subsequent builds if githubToken is also used, but note that the image layer will be publicly available in your projects GitHub Package Registry, so make sure the resulting image does not have any secrets cached in logs or state.'
4040
required: false
4141
default: ''
42+
base_image:
43+
description: 'Specify a custom base image, such as \"busybox\" or your predefined base image. This will replace the \"FROM\" claus in the default Dockerfile on the fly. This is optional. Hint: with this option you are able to use all the available archs other than the ones showed by default. See the [advanced example](./.github/workflows/advanced-example.yml) in this repo. For more detials, see [PR #103](https://github.com/uraimo/run-on-arch-action/pull/103#issuecomment-1363810049).'
44+
required: false
45+
default: ''
4246

4347
runs:
4448
using: 'node16'

src/run-on-arch.js

+22-8
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,39 @@
1-
const core = require('@actions/core')
1+
/*jshint esversion: 9 */
2+
3+
const core = require('@actions/core');
24
const fs = require('fs');
3-
const path = require('path')
5+
const path = require('path');
46
const YAML = require('yaml');
57
const shlex = require('shlex');
6-
const { exec } = require('@actions/exec')
8+
const { exec } = require('@actions/exec');
79

810
function slug(str) {
911
return str.replace(/[^a-zA-Z0-9]/g, '-').toLowerCase();
1012
}
1113

1214
async function main() {
1315
if (process.platform !== 'linux') {
14-
throw new Error('run-on-arch supports only Linux')
16+
throw new Error('run-on-arch supports only Linux');
1517
}
1618

1719
const arch = core.getInput('arch', { required: true });
1820
const distro = core.getInput('distro', { required: true });
21+
const base_image = core.getInput('base_image', { required: false });
1922

2023
// If bad arch/distro passed, fail fast before installing all the qemu stuff
2124
const dockerFile = path.join(
2225
__dirname, '..', 'Dockerfiles', `Dockerfile.${arch}.${distro}`);
26+
27+
// If a custom base image is given, then dynamically create its Dockerfile.
28+
if (base_image) {
29+
let lines = [];
30+
lines.push(`FROM ${base_image}`);
31+
lines.push("COPY ./run-on-arch-install.sh /root/run-on-arch-install.sh");
32+
lines.push("RUN chmod +x /root/run-on-arch-install.sh && /root/run-on-arch-install.sh");
33+
console.log(`Writing custom Dockerfile to: ${dockerFile} ...`);
34+
fs.writeFileSync(dockerFile, lines.join("\n"));
35+
}
36+
2337
if (!fs.existsSync(dockerFile)) {
2438
throw new Error(`run-on-arch: ${dockerFile} does not exist.`);
2539
}
@@ -85,7 +99,7 @@ async function main() {
8599
// docker run.
86100
const envYAML = core.getInput('env');
87101
if (envYAML) {
88-
const mapping = YAML.parse(envYAML)
102+
const mapping = YAML.parse(envYAML);
89103
if (typeof mapping !== 'object' || mapping instanceof Array) {
90104
throw new Error(`run-on-arch: env must be a flat mapping of key/value pairs.`);
91105
}
@@ -105,7 +119,7 @@ async function main() {
105119
arch, distro,
106120
].join('-'));
107121

108-
console.log('Configuring Docker for multi-architecture support')
122+
console.log('Configuring Docker for multi-architecture support');
109123
await exec(
110124
path.join(__dirname, 'run-on-arch.sh'),
111125
[ dockerFile, containerName, ...dockerRunArgs ],
@@ -114,5 +128,5 @@ async function main() {
114128
}
115129

116130
main().catch(err => {
117-
core.setFailed(err.message)
118-
})
131+
core.setFailed(err.message);
132+
});

0 commit comments

Comments
 (0)