Merge pull request #58 from crazy-max/set-host

set-host input to set DOCKER_HOST env var
This commit is contained in:
CrazyMax 2024-02-29 16:39:12 +01:00 committed by GitHub
commit f1d16883d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 47 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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
]
])(

View File

@ -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
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -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')
};
}

View File

@ -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 () => {