diff --git a/docs/tasks.md b/docs/tasks.md index f26a3e2..efab1ba 100644 --- a/docs/tasks.md +++ b/docs/tasks.md @@ -18,6 +18,7 @@ runs a command inside of a new container, using a specific image. | [`volumes`](#volumes) | Volumes to mount into the container | No | | [`command`](#command) | Override the default image command | No | | [`user`](#user) | User to run the command as | No | +| [`working_dir`](#working_dir) | Working directory for the command | No | #### **image** @@ -84,6 +85,13 @@ User to run the command as. user: nobody ``` +#### **working_dir** +Working directory for the command. + +```yml +working_dir: /tmp +``` + ## `Exec Task` Runs a new command in a running container diff --git a/lib/schemas/tasks/run.yml b/lib/schemas/tasks/run.yml index 21ed52e..b52c755 100644 --- a/lib/schemas/tasks/run.yml +++ b/lib/schemas/tasks/run.yml @@ -13,6 +13,8 @@ properties: "$ref": "../definitions.yml#/string_or_list" user: type: string + working_dir: + type: string environment: "$ref": "../definitions.yml#/list_or_dict" volumes: diff --git a/lib/tasks/run.js b/lib/tasks/run.js index 591364c..e549e78 100644 --- a/lib/tasks/run.js +++ b/lib/tasks/run.js @@ -3,11 +3,12 @@ const Docker = require('dockerode'); const util = require('../util'); class RunTask { - constructor(name, { image, command, user, volumes, environment, network, pull = 'missing', auto_remove = true }) { + constructor(name, { image, command, user, working_dir, volumes, environment, network, pull = 'missing', auto_remove = true }) { this.name = name; this.image = image; this.command = command ? util.parseCommand(command) : []; this.user = user; + this.workingDir = working_dir; this.volumes = volumes; if (environment) this.environment = util.parseEnvironment(environment); this.network = network; @@ -49,6 +50,7 @@ class RunTask { await this.checkOrPull(this.image, log); const opt = { User: this.user, + WorkingDir: this.workingDir, HostConfig: { AutoRemove: this.autoRemove } diff --git a/test/tasks/run.js b/test/tasks/run.js index faec3b9..1562b0a 100644 --- a/test/tasks/run.js +++ b/test/tasks/run.js @@ -180,4 +180,25 @@ test('run: nonexistent user', async (t) => { t.pass(); }); +test('run: default workingdir', async (t) => { + const task = new RunTask('test', { + image: 'busybox', + command: 'pwd' + }); + + const { exitCode, output } = await task.execute(log); + t.is(exitCode, 0); + t.is(output, '/'); +}); +test('run: custom workingdir', async (t) => { + const task = new RunTask('test', { + image: 'busybox', + command: 'pwd', + working_dir: '/tmp' + }); + + const { exitCode, output } = await task.execute(log); + t.is(exitCode, 0); + t.is(output, '/tmp'); +});