diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 498b171..11c5676 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/README.md b/README.md index 5a494e0..84a3a5f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts index 439e050..5e813ac 100644 --- a/__tests__/context.test.ts +++ b/__tests__/context.test.ts @@ -18,12 +18,14 @@ describe('getInputs', () => { 0, new Map([ ['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([]), + new Map([ + ['set-host', 'true'], + ]), { version: 'latest', channel: '', context: '', daemonConfig: '', + setHost: true } as context.Inputs ] ])( diff --git a/action.yml b/action.yml index 5282f26..5a347a4 100644 --- a/action.yml +++ b/action.yml @@ -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: diff --git a/src/context.ts b/src/context.ts index 40ee91b..34ba9a7 100644 --- a/src/context.ts +++ b/src/context.ts @@ -5,6 +5,7 @@ export interface Inputs { channel: string; daemonConfig?: string; context: string; + setHost: boolean; } export function getInputs(): Inputs { @@ -12,6 +13,7 @@ export function getInputs(): Inputs { 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') }; } diff --git a/src/main.ts b/src/main.ts index f1c2b76..d9cf10e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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 () => {