Skip to content

Commit

Permalink
Merge pull request #58 from crazy-max/set-host
Browse files Browse the repository at this point in the history
set-host input to set DOCKER_HOST env var
crazy-max authored Feb 29, 2024
2 parents 38c0711 + 5de1d6b commit f1d1688
Showing 8 changed files with 47 additions and 6 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -249,3 +249,23 @@ jobs:
name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v2

set-host:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Set up Docker
uses: ./
with:
set-host: true
-
name: List contexts
run: |
docker context ls
-
name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v2
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -106,6 +106,7 @@ The following inputs can be used as `step.with` keys
| `channel` | String | `stable` | Docker CE [channel](https://download.docker.com/linux/static/) (e.g, `stable`, `edge` or `test`). |
| `daemon-config` | String | | [Docker daemon JSON configuration](https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-file) |
| `context` | String | `setup-docker-action` | Docker context name. |
| `set-host` | Bool | `false` | Set `DOCKER_HOST` environment variable to docker socket path. |

### outputs

9 changes: 8 additions & 1 deletion __tests__/context.test.ts
Original file line number Diff line number Diff line change
@@ -18,12 +18,14 @@ describe('getInputs', () => {
0,
new Map<string, string>([
['version', 'v24.0.8'],
['set-host', 'false'],
]),
{
version: 'v24.0.8',
channel: '',
context: '',
daemonConfig: '',
setHost: false
} as context.Inputs
],
[
@@ -33,22 +35,27 @@ describe('getInputs', () => {
['channel', 'test'],
['context', 'foo'],
['daemon-config', `{"debug":true,"features":{"containerd-snapshotter":true}}`],
['set-host', 'false'],
]),
{
version: 'v24.0.0-rc.4',
channel: 'test',
context: 'foo',
daemonConfig: `{"debug":true,"features":{"containerd-snapshotter":true}}`,
setHost: false
} as context.Inputs
],
[
2,
new Map<string, string>([]),
new Map<string, string>([
['set-host', 'true'],
]),
{
version: 'latest',
channel: '',
context: '',
daemonConfig: '',
setHost: true
} as context.Inputs
]
])(
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -20,6 +20,10 @@ inputs:
context:
description: 'Docker context name. (default setup-docker-action)'
required: false
set-host:
description: 'Set DOCKER_HOST environment variable to docker socket path'
default: 'false'
required: false

outputs:
sock:
6 changes: 3 additions & 3 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
@@ -5,13 +5,15 @@ export interface Inputs {
channel: string;
daemonConfig?: string;
context: string;
setHost: boolean;
}

export function getInputs(): Inputs {
return {
version: core.getInput('version') || 'latest',
channel: core.getInput('channel'),
daemonConfig: core.getInput('daemon-config'),
context: core.getInput('context')
context: core.getInput('context'),
setHost: core.getBooleanInput('set-host')
};
}
7 changes: 7 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -39,6 +39,13 @@ actionsToolkit.run(
core.info(`sock=${sockPath}`);
core.setOutput('sock', sockPath);
});

if (input.setHost) {
await core.group(`Setting Docker host`, async () => {
core.exportVariable('DOCKER_HOST', sockPath);
core.info(`DOCKER_HOST=${sockPath}`);
});
}
}

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

0 comments on commit f1d1688

Please sign in to comment.