mirror of
https://github.com/docker/setup-docker-action.git
synced 2025-04-19 15:20:02 +02:00
tcp-port opt to expose Docker API to a local TCP address
This commit is contained in:
parent
fde3095c59
commit
3a56725668
28
.github/workflows/ci.yml
vendored
28
.github/workflows/ci.yml
vendored
@ -271,3 +271,31 @@ jobs:
|
|||||||
name: List contexts
|
name: List contexts
|
||||||
run: |
|
run: |
|
||||||
docker context ls
|
docker context ls
|
||||||
|
|
||||||
|
tcp:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os:
|
||||||
|
- ubuntu-latest
|
||||||
|
#- macos-14 # no virt: https://github.com/docker/actions-toolkit/issues/317
|
||||||
|
- macos-13
|
||||||
|
- windows-latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
-
|
||||||
|
name: Set up Docker
|
||||||
|
id: setup_docker
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
version: ${{ env.DOCKER_VERSION }}
|
||||||
|
tcp-port: 2378
|
||||||
|
-
|
||||||
|
name: Check docker info through TCP
|
||||||
|
run: |
|
||||||
|
docker info
|
||||||
|
env:
|
||||||
|
DOCKER_HOST: ${{ steps.setup_docker.outputs.tcp }}
|
||||||
|
@ -117,6 +117,7 @@ The following inputs can be used as `step.with` keys
|
|||||||
| `version` | String | `latest` | Docker CE version (e.g., `v24.0.6`). |
|
| `version` | String | `latest` | Docker CE version (e.g., `v24.0.6`). |
|
||||||
| `channel` | String | `stable` | Docker CE [channel](https://download.docker.com/linux/static/) (e.g, `stable`, `edge` or `test`). |
|
| `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) |
|
| `daemon-config` | String | | [Docker daemon JSON configuration](https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-file) |
|
||||||
|
| `tcp-port` | Number | | TCP port to expose the Docker API locally |
|
||||||
| `context` | String | `setup-docker-action` | Docker context name. |
|
| `context` | String | `setup-docker-action` | Docker context name. |
|
||||||
| `set-host` | Bool | `false` | Set `DOCKER_HOST` environment variable to docker socket path. |
|
| `set-host` | Bool | `false` | Set `DOCKER_HOST` environment variable to docker socket path. |
|
||||||
| `rootless` | Bool | `false` | Start daemon in rootless mode |
|
| `rootless` | Bool | `false` | Start daemon in rootless mode |
|
||||||
@ -125,9 +126,10 @@ The following inputs can be used as `step.with` keys
|
|||||||
|
|
||||||
The following outputs are available
|
The following outputs are available
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
|--------|--------|--------------------|
|
|--------|--------|---------------------------------------|
|
||||||
| `sock` | String | Docker socket path |
|
| `sock` | String | Docker socket path |
|
||||||
|
| `tcp` | String | Docker TCP address if tcp-port is set |
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
@ -185,6 +185,27 @@ describe('getInputs', () => {
|
|||||||
rootless: true,
|
rootless: true,
|
||||||
} as context.Inputs
|
} as context.Inputs
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
9,
|
||||||
|
new Map<string, string>([
|
||||||
|
['version', 'v24.0.8'],
|
||||||
|
['tcp-port', '2378'],
|
||||||
|
['set-host', 'false'],
|
||||||
|
['rootless', 'false'],
|
||||||
|
]),
|
||||||
|
{
|
||||||
|
source: {
|
||||||
|
type: 'archive',
|
||||||
|
version: 'v24.0.8',
|
||||||
|
channel: 'stable'
|
||||||
|
},
|
||||||
|
context: '',
|
||||||
|
daemonConfig: '',
|
||||||
|
tcpPort: 2378,
|
||||||
|
rootless: false,
|
||||||
|
setHost: false
|
||||||
|
} as context.Inputs
|
||||||
|
],
|
||||||
])(
|
])(
|
||||||
'[%d] given %p as inputs, returns %p',
|
'[%d] given %p as inputs, returns %p',
|
||||||
async (num: number, inputs: Map<string, string>, expected: context.Inputs) => {
|
async (num: number, inputs: Map<string, string>, expected: context.Inputs) => {
|
||||||
|
@ -17,6 +17,9 @@ inputs:
|
|||||||
daemon-config:
|
daemon-config:
|
||||||
description: 'Docker daemon JSON configuration'
|
description: 'Docker daemon JSON configuration'
|
||||||
required: false
|
required: false
|
||||||
|
tcp-port:
|
||||||
|
description: 'TCP port to expose the Docker API locally'
|
||||||
|
required: false
|
||||||
context:
|
context:
|
||||||
description: 'Docker context name. (default setup-docker-action)'
|
description: 'Docker context name. (default setup-docker-action)'
|
||||||
required: false
|
required: false
|
||||||
@ -32,6 +35,8 @@ inputs:
|
|||||||
outputs:
|
outputs:
|
||||||
sock:
|
sock:
|
||||||
description: "Docker socket path"
|
description: "Docker socket path"
|
||||||
|
tcp:
|
||||||
|
description: "Docker TCP address if tcp-port is set"
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: 'node20'
|
using: 'node20'
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import {InstallSource} from '@docker/actions-toolkit/lib/docker/install';
|
|
||||||
import {parse} from 'csv-parse/sync';
|
import {parse} from 'csv-parse/sync';
|
||||||
|
|
||||||
|
import {InstallSource} from '@docker/actions-toolkit/lib/docker/install';
|
||||||
|
import {Util} from '@docker/actions-toolkit/lib/util';
|
||||||
|
|
||||||
export interface Inputs {
|
export interface Inputs {
|
||||||
source: InstallSource;
|
source: InstallSource;
|
||||||
daemonConfig?: string;
|
daemonConfig?: string;
|
||||||
|
tcpPort?: number;
|
||||||
context: string;
|
context: string;
|
||||||
setHost: boolean;
|
setHost: boolean;
|
||||||
rootless: boolean;
|
rootless: boolean;
|
||||||
@ -21,6 +24,7 @@ export function getInputs(): Inputs {
|
|||||||
return {
|
return {
|
||||||
source: source,
|
source: source,
|
||||||
daemonConfig: core.getInput('daemon-config'),
|
daemonConfig: core.getInput('daemon-config'),
|
||||||
|
tcpPort: Util.getInputNumber('tcp-port'),
|
||||||
context: core.getInput('context'),
|
context: core.getInput('context'),
|
||||||
setHost: core.getBooleanInput('set-host'),
|
setHost: core.getBooleanInput('set-host'),
|
||||||
rootless: core.getBooleanInput('rootless')
|
rootless: core.getBooleanInput('rootless')
|
||||||
|
14
src/main.ts
14
src/main.ts
@ -19,12 +19,20 @@ actionsToolkit.run(
|
|||||||
throw new Error(`'default' context cannot be used.`);
|
throw new Error(`'default' context cannot be used.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let tcpPort: number | undefined;
|
||||||
|
let tcpAddress: string | undefined;
|
||||||
|
if (input.tcpPort) {
|
||||||
|
tcpPort = input.tcpPort;
|
||||||
|
tcpAddress = `tcp://127.0.0.1:${tcpPort}`;
|
||||||
|
}
|
||||||
|
|
||||||
const install = new Install({
|
const install = new Install({
|
||||||
runDir: runDir,
|
runDir: runDir,
|
||||||
source: input.source,
|
source: input.source,
|
||||||
rootless: input.rootless,
|
rootless: input.rootless,
|
||||||
contextName: input.context || 'setup-docker-action',
|
contextName: input.context || 'setup-docker-action',
|
||||||
daemonConfig: input.daemonConfig
|
daemonConfig: input.daemonConfig,
|
||||||
|
localTCPPort: tcpPort
|
||||||
});
|
});
|
||||||
let toolDir;
|
let toolDir;
|
||||||
if (!(await Docker.isAvailable()) || input.source) {
|
if (!(await Docker.isAvailable()) || input.source) {
|
||||||
@ -38,6 +46,10 @@ actionsToolkit.run(
|
|||||||
await core.group(`Setting outputs`, async () => {
|
await core.group(`Setting outputs`, async () => {
|
||||||
core.info(`sock=${sockPath}`);
|
core.info(`sock=${sockPath}`);
|
||||||
core.setOutput('sock', sockPath);
|
core.setOutput('sock', sockPath);
|
||||||
|
if (tcpAddress) {
|
||||||
|
core.info(`tcp=${tcpAddress}`);
|
||||||
|
core.setOutput('tcp', tcpAddress);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (input.setHost) {
|
if (input.setHost) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user