Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set-host input to set DOCKER_HOST env var #58

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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

Expand Down
9 changes: 8 additions & 1 deletion __tests__/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
],
[
Expand All @@ -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
]
])(
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
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
Expand Up @@ -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
Expand Up @@ -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 () => {
Expand Down
Loading