Skip to content
New issue

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

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

Already on GitHub? # to your account

Add working_dir option for run task #7

Merged
merged 1 commit into from
Oct 11, 2020
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
8 changes: 8 additions & 0 deletions docs/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/schemas/tasks/run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion lib/tasks/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,6 +50,7 @@ class RunTask {
await this.checkOrPull(this.image, log);
const opt = {
User: this.user,
WorkingDir: this.workingDir,
HostConfig: {
AutoRemove: this.autoRemove
}
Expand Down
21 changes: 21 additions & 0 deletions test/tasks/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});