Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(base_image): add custom base_image argument #103

Merged
merged 3 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/advanced-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
distro: fedora_latest
- arch: armv7
distro: archarm_latest
- arch: x86_64
distro: ubuntu18.04
base_image: ubuntu:18.04

steps:
- uses: actions/checkout@v3
Expand All @@ -30,6 +33,7 @@ jobs:
with:
arch: ${{ matrix.arch }}
distro: ${{ matrix.distro }}
base_image: ${{ matrix.base_image }}

# Not required, but speeds up builds
githubToken: ${{ github.token }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ jobs:
install: |
case "${{ matrix.distro }}" in
ubuntu*|jessie|stretch|buster|bullseye)
apt-get update -q -y
apt-get install -q -y git
apt-get update -q -y --force-yes
apt-get install -q -y --force-yes git
;;
fedora*)
dnf -y update
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The action also accepts some optional input parameters:
* `dockerRunArgs`: Additional arguments to pass to `docker run`, such as volume mappings. See [`docker run` documentation](https://docs.docker.com/engine/reference/commandline/run).
* `setup`: Shell commands to execute on the host before running the container, such as creating directories for volume mappings.
* `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.
* `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).

### Basic example

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ inputs:
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.'
required: false
default: ''
base_image:
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).'
required: false
default: ''

runs:
using: 'node16'
Expand Down
30 changes: 22 additions & 8 deletions src/run-on-arch.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
const core = require('@actions/core')
/*jshint esversion: 9 */

const core = require('@actions/core');
const fs = require('fs');
const path = require('path')
const path = require('path');
const YAML = require('yaml');
const shlex = require('shlex');
const { exec } = require('@actions/exec')
const { exec } = require('@actions/exec');

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

async function main() {
if (process.platform !== 'linux') {
throw new Error('run-on-arch supports only Linux')
throw new Error('run-on-arch supports only Linux');
}

const arch = core.getInput('arch', { required: true });
const distro = core.getInput('distro', { required: true });
const base_image = core.getInput('base_image', { required: false });

// If bad arch/distro passed, fail fast before installing all the qemu stuff
const dockerFile = path.join(
__dirname, '..', 'Dockerfiles', `Dockerfile.${arch}.${distro}`);

// If a custom base image is given, then dynamically create its Dockerfile.
if (base_image) {
let lines = [];
lines.push(`FROM ${base_image}`);
lines.push("COPY ./run-on-arch-install.sh /root/run-on-arch-install.sh");
lines.push("RUN chmod +x /root/run-on-arch-install.sh && /root/run-on-arch-install.sh");
console.log(`Writing custom Dockerfile to: ${dockerFile} ...`);
fs.writeFileSync(dockerFile, lines.join("\n"));
}

if (!fs.existsSync(dockerFile)) {
throw new Error(`run-on-arch: ${dockerFile} does not exist.`);
}
Expand Down Expand Up @@ -85,7 +99,7 @@ async function main() {
// docker run.
const envYAML = core.getInput('env');
if (envYAML) {
const mapping = YAML.parse(envYAML)
const mapping = YAML.parse(envYAML);
if (typeof mapping !== 'object' || mapping instanceof Array) {
throw new Error(`run-on-arch: env must be a flat mapping of key/value pairs.`);
}
Expand All @@ -105,7 +119,7 @@ async function main() {
arch, distro,
].join('-'));

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

main().catch(err => {
core.setFailed(err.message)
})
core.setFailed(err.message);
});