Skip to content

Commit f1d1688

Browse files
authored
Merge pull request #58 from crazy-max/set-host
set-host input to set DOCKER_HOST env var
2 parents 38c0711 + 5de1d6b commit f1d1688

File tree

8 files changed

+47
-6
lines changed

8 files changed

+47
-6
lines changed

.github/workflows/ci.yml

+20
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,23 @@ jobs:
249249
name: Dump context
250250
if: always()
251251
uses: crazy-max/ghaction-dump-context@v2
252+
253+
set-host:
254+
runs-on: ubuntu-latest
255+
steps:
256+
-
257+
name: Checkout
258+
uses: actions/checkout@v4
259+
-
260+
name: Set up Docker
261+
uses: ./
262+
with:
263+
set-host: true
264+
-
265+
name: List contexts
266+
run: |
267+
docker context ls
268+
-
269+
name: Dump context
270+
if: always()
271+
uses: crazy-max/ghaction-dump-context@v2

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ The following inputs can be used as `step.with` keys
106106
| `channel` | String | `stable` | Docker CE [channel](https://download.docker.com/linux/static/) (e.g, `stable`, `edge` or `test`). |
107107
| `daemon-config` | String | | [Docker daemon JSON configuration](https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-file) |
108108
| `context` | String | `setup-docker-action` | Docker context name. |
109+
| `set-host` | Bool | `false` | Set `DOCKER_HOST` environment variable to docker socket path. |
109110

110111
### outputs
111112

__tests__/context.test.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ describe('getInputs', () => {
1818
0,
1919
new Map<string, string>([
2020
['version', 'v24.0.8'],
21+
['set-host', 'false'],
2122
]),
2223
{
2324
version: 'v24.0.8',
2425
channel: '',
2526
context: '',
2627
daemonConfig: '',
28+
setHost: false
2729
} as context.Inputs
2830
],
2931
[
@@ -33,22 +35,27 @@ describe('getInputs', () => {
3335
['channel', 'test'],
3436
['context', 'foo'],
3537
['daemon-config', `{"debug":true,"features":{"containerd-snapshotter":true}}`],
38+
['set-host', 'false'],
3639
]),
3740
{
3841
version: 'v24.0.0-rc.4',
3942
channel: 'test',
4043
context: 'foo',
4144
daemonConfig: `{"debug":true,"features":{"containerd-snapshotter":true}}`,
45+
setHost: false
4246
} as context.Inputs
4347
],
4448
[
4549
2,
46-
new Map<string, string>([]),
50+
new Map<string, string>([
51+
['set-host', 'true'],
52+
]),
4753
{
4854
version: 'latest',
4955
channel: '',
5056
context: '',
5157
daemonConfig: '',
58+
setHost: true
5259
} as context.Inputs
5360
]
5461
])(

action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ inputs:
2020
context:
2121
description: 'Docker context name. (default setup-docker-action)'
2222
required: false
23+
set-host:
24+
description: 'Set DOCKER_HOST environment variable to docker socket path'
25+
default: 'false'
26+
required: false
2327

2428
outputs:
2529
sock:

dist/index.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/context.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ export interface Inputs {
55
channel: string;
66
daemonConfig?: string;
77
context: string;
8+
setHost: boolean;
89
}
910

1011
export function getInputs(): Inputs {
1112
return {
1213
version: core.getInput('version') || 'latest',
1314
channel: core.getInput('channel'),
1415
daemonConfig: core.getInput('daemon-config'),
15-
context: core.getInput('context')
16+
context: core.getInput('context'),
17+
setHost: core.getBooleanInput('set-host')
1618
};
1719
}

src/main.ts

+7
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ actionsToolkit.run(
3939
core.info(`sock=${sockPath}`);
4040
core.setOutput('sock', sockPath);
4141
});
42+
43+
if (input.setHost) {
44+
await core.group(`Setting Docker host`, async () => {
45+
core.exportVariable('DOCKER_HOST', sockPath);
46+
core.info(`DOCKER_HOST=${sockPath}`);
47+
});
48+
}
4249
}
4350

4451
await core.group(`Docker info`, async () => {

0 commit comments

Comments
 (0)