Skip to content

Commit 74ac62f

Browse files
authored
Merge pull request #168 from ArunKumarT1995/feature/rundirinput
Add input for runtime basedir
2 parents 29412e2 + a4da7e5 commit 74ac62f

File tree

7 files changed

+39
-20
lines changed

7 files changed

+39
-20
lines changed

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,16 @@ jobs:
113113

114114
The following inputs can be used as `step.with` keys
115115

116-
| Name | Type | Default | Description |
117-
|-----------------|--------|-----------------------|-----------------------------------------------------------------------------------------------------------------------------|
118-
| `version` | String | `latest` | Docker version to use. See [inputs.version](#inputs.version). |
119-
| `channel` | String | `stable` | Docker CE [channel](https://download.docker.com/linux/static/) (`stable` or `test`). Only applicable to `type=archive` |
120-
| `daemon-config` | String | | [Docker daemon JSON configuration](https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-file) |
121-
| `tcp-port` | Number | | TCP port to expose the Docker API locally |
122-
| `context` | String | `setup-docker-action` | Docker context name. |
123-
| `set-host` | Bool | `false` | Set `DOCKER_HOST` environment variable to docker socket path. |
124-
| `rootless` | Bool | `false` | Start daemon in rootless mode |
116+
| Name | Type | Default | Description |
117+
|-------------------|--------|------------------------------|-----------------------------------------------------------------------------------------------------------------------------|
118+
| `version` | String | `latest` | Docker version to use. See [inputs.version](#inputs.version). |
119+
| `channel` | String | `stable` | Docker CE [channel](https://download.docker.com/linux/static/) (`stable` or `test`). Only applicable to `type=archive` |
120+
| `daemon-config` | String | | [Docker daemon JSON configuration](https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-file) |
121+
| `tcp-port` | Number | | TCP port to expose the Docker API locally |
122+
| `context` | String | `setup-docker-action` | Docker context name. |
123+
| `set-host` | Bool | `false` | Set `DOCKER_HOST` environment variable to docker socket path. |
124+
| `rootless` | Bool | `false` | Start daemon in rootless mode |
125+
| `runtime-basedir` | String | `<home>/setup-docker-action` | Docker runtime base directory |
125126

126127
### inputs.version
127128

__tests__/context.test.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import {beforeEach, describe, expect, test} from '@jest/globals';
2+
import * as os from 'os';
3+
import * as path from 'path';
24

35
import * as context from '../src/context';
46

@@ -30,7 +32,8 @@ describe('getInputs', () => {
3032
context: '',
3133
daemonConfig: '',
3234
rootless: false,
33-
setHost: false
35+
setHost: false,
36+
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
3437
} as context.Inputs
3538
],
3639
[
@@ -52,7 +55,8 @@ describe('getInputs', () => {
5255
context: 'foo',
5356
daemonConfig: `{"debug":true,"features":{"containerd-snapshotter":true}}`,
5457
rootless: false,
55-
setHost: false
58+
setHost: false,
59+
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
5660
} as context.Inputs
5761
],
5862
[
@@ -70,7 +74,8 @@ describe('getInputs', () => {
7074
context: '',
7175
daemonConfig: '',
7276
rootless: false,
73-
setHost: true
77+
setHost: true,
78+
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
7479
} as context.Inputs
7580
],
7681
[
@@ -90,7 +95,8 @@ describe('getInputs', () => {
9095
context: 'foo',
9196
daemonConfig: `{"debug":true,"features":{"containerd-snapshotter":true}}`,
9297
rootless: false,
93-
setHost: false
98+
setHost: false,
99+
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
94100
} as context.Inputs
95101
],
96102
[
@@ -108,7 +114,8 @@ describe('getInputs', () => {
108114
context: '',
109115
daemonConfig: '',
110116
rootless: false,
111-
setHost: false
117+
setHost: false,
118+
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
112119
} as context.Inputs
113120
],
114121
[
@@ -128,6 +135,7 @@ describe('getInputs', () => {
128135
context: '',
129136
daemonConfig: '',
130137
rootless: false,
138+
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
131139
} as context.Inputs
132140
],
133141
[
@@ -147,6 +155,7 @@ describe('getInputs', () => {
147155
context: '',
148156
daemonConfig: '',
149157
rootless: false,
158+
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
150159
} as context.Inputs
151160
],
152161
[
@@ -165,6 +174,7 @@ describe('getInputs', () => {
165174
context: '',
166175
daemonConfig: '',
167176
rootless: false,
177+
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
168178
} as context.Inputs
169179
],
170180
[
@@ -183,6 +193,7 @@ describe('getInputs', () => {
183193
context: '',
184194
daemonConfig: '',
185195
rootless: true,
196+
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
186197
} as context.Inputs
187198
],
188199
[
@@ -203,7 +214,8 @@ describe('getInputs', () => {
203214
daemonConfig: '',
204215
tcpPort: 2378,
205216
rootless: false,
206-
setHost: false
217+
setHost: false,
218+
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
207219
} as context.Inputs
208220
],
209221
])(

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ inputs:
3131
description: 'Enable Docker rootless mode'
3232
default: 'false'
3333
required: false
34+
runtime-basedir:
35+
description: 'Docker runtime base directory'
36+
required: false
3437

3538
outputs:
3639
sock:

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/context.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os from 'os';
2+
import path from 'path';
13
import * as core from '@actions/core';
24
import {parse} from 'csv-parse/sync';
35

@@ -11,6 +13,7 @@ export interface Inputs {
1113
context: string;
1214
setHost: boolean;
1315
rootless: boolean;
16+
runtimeBasedir: string;
1417
}
1518

1619
export function getInputs(): Inputs {
@@ -27,7 +30,8 @@ export function getInputs(): Inputs {
2730
tcpPort: Util.getInputNumber('tcp-port'),
2831
context: core.getInput('context'),
2932
setHost: core.getBooleanInput('set-host'),
30-
rootless: core.getBooleanInput('rootless')
33+
rootless: core.getBooleanInput('rootless'),
34+
runtimeBasedir: core.getInput('runtime-basedir') || path.join(os.homedir(), `setup-docker-action`)
3135
};
3236
}
3337

src/main.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as crypto from 'crypto';
2-
import os from 'os';
32
import path from 'path';
43
import * as core from '@actions/core';
54
import * as actionsToolkit from '@docker/actions-toolkit';
@@ -18,7 +17,7 @@ actionsToolkit.run(
1817
// main
1918
async () => {
2019
const input: context.Inputs = context.getInputs();
21-
const runDir = path.join(os.homedir(), `setup-docker-action-${crypto.randomUUID().slice(0, 8)}`);
20+
const runDir = path.join(input.runtimeBasedir, `run-${crypto.randomUUID().slice(0, 8)}`);
2221

2322
if (input.context == 'default') {
2423
throw new Error(`'default' context cannot be used.`);

0 commit comments

Comments
 (0)