Skip to content

Commit

Permalink
feat: defaults to privileged mode for test targets (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Leshiy authored Nov 2, 2023
1 parent c9859f1 commit bfab3a8
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ jobs:
ci_cli_version: ${{ inputs.ci_cli_version }}
earthly_version: ${{ inputs.earthly_version }}
target: test
privileged: true
secrets:
dockerhub_token: ${{ secrets.dockerhub_token }}
dockerhub_username: ${{ secrets.dockerhub_username }}
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
on:
workflow_call:
inputs:
privileged:
description: |
Whether the workflow should run earthly in privileged mode (earthly -P flag).
required: false
type: boolean
default: false
target:
description: |
The target to run.
Expand Down Expand Up @@ -103,6 +109,7 @@ jobs:
uses: input-output-hk/catalyst-ci/actions/run@master
id: build
with:
privileged: ${{ inputs.privileged }}
earthfile: ${{ matrix.earthfile }}
target: ${{ inputs.target }}
runner_address: ${{ secrets.earthly_runner_address }}
4 changes: 4 additions & 0 deletions actions/run/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ inputs:
platform:
description: The platform to execute the earthfile target with (defaults to native)
required: false
privileged:
description: Whether the workflow should run earthly in privileged mode (earthly -P flag).
required: false
default: "false"
runner_address:
description: The address of the remote runner to use
required: false
Expand Down
4 changes: 4 additions & 0 deletions actions/run/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2882,12 +2882,16 @@ async function run() {
const earthfile = core.getInput('earthfile');
const flags = core.getInput('flags');
const platform = core.getInput('platform');
const privileged = core.getBooleanInput('privileged');
const runnerAddress = core.getInput('runner_address');
const runnerPort = core.getInput('runner_port');
const target = core.getInput('target');
const targetFlags = core.getInput('target_flags');
const command = 'earthly';
const args = [];
if (privileged) {
args.push('-P');
}
if (runnerAddress) {
args.push('--buildkit-host', `tcp://${runnerAddress}:${runnerPort}`);
}
Expand Down
10 changes: 10 additions & 0 deletions actions/run/src/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('Run Action', () => {
earthfile: './earthfile',
flags: '',
platform: '',
privileged: '',
output: '',
runnerAddress: '',
runnerPort: '',
Expand All @@ -42,6 +43,7 @@ describe('Run Action', () => {
earthfile: './earthfile',
flags: '--test',
platform: '',
privileged: '',
output: 'Artifact +target/artifact output as out\n',
runnerAddress: '',
runnerPort: '',
Expand All @@ -57,6 +59,7 @@ describe('Run Action', () => {
earthfile: './earthfile',
flags: '',
platform: '',
privileged: '',
output: '',
runnerAddress: 'localhost',
runnerPort: '8372',
Expand All @@ -76,12 +79,14 @@ describe('Run Action', () => {
earthfile: './earthfile',
flags: '--flag1 test -f2 test2',
platform: 'linux/amd64',
privileged: 'true',
output: 'Image +docker output as image1:tag1\n',
runnerAddress: '',
runnerPort: '',
target: 'target',
targetFlags: '',
command: [
'-P',
'--platform',
'linux/amd64',
'--flag1',
Expand All @@ -101,6 +106,7 @@ describe('Run Action', () => {
earthfile,
flags,
platform,
privileged,
output,
runnerAddress,
runnerPort,
Expand All @@ -122,6 +128,8 @@ describe('Run Action', () => {
return flags
case 'platform':
return platform
case 'privileged':
return privileged
case 'output':
return output
case 'runner_address':
Expand All @@ -141,6 +149,8 @@ describe('Run Action', () => {
switch (name) {
case 'artifact':
return artifact === 'true'
case 'privileged':
return privileged === 'true'
default:
throw new Error('Unknown input')
}
Expand Down
5 changes: 5 additions & 0 deletions actions/run/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export async function run(): Promise<void> {
const earthfile = core.getInput('earthfile')
const flags = core.getInput('flags')
const platform = core.getInput('platform')
const privileged = core.getBooleanInput('privileged')
const runnerAddress = core.getInput('runner_address')
const runnerPort = core.getInput('runner_port')
const target = core.getInput('target')
Expand All @@ -16,6 +17,10 @@ export async function run(): Promise<void> {
const command = 'earthly'
const args: string[] = []

if (privileged) {
args.push('-P')
}

if (runnerAddress) {
args.push('--buildkit-host', `tcp://${runnerAddress}:${runnerPort}`)
}
Expand Down

0 comments on commit bfab3a8

Please sign in to comment.