Skip to content
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
45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
- ubuntu-latest
- windows-latest
version:
- ""
- v27.3.1
- type=image,tag=27.3.1
include:
Expand Down Expand Up @@ -341,3 +342,47 @@ jobs:
docker info
env:
DOCKER_HOST: ${{ steps.setup_docker.outputs.tcp }}

undock-regctl-version:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
undock_version:
- ''
- v0.9.0
regctl_version:
- ''
- v0.8.2
steps:
-
name: Checkout
uses: actions/checkout@v5
-
name: Set up Docker
uses: ./
with:
version: type=image
env:
UNDOCK_VERSION: ${{ matrix.undock_version }}
REGCTL_VERSION: ${{ matrix.regctl_version }}

docker-29:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-13
- windows-latest
steps:
-
name: Checkout
uses: actions/checkout@v5
-
name: Set up Docker
uses: ./
with:
version: v29.0.0-rc.1
channel: test
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,16 @@ jobs:

The following inputs can be used as `step.with` keys

| Name | Type | Default | Description |
|-----------------|--------|-----------------------|-----------------------------------------------------------------------------------------------------------------------------|
| `version` | String | `latest` | Docker version to use. See [inputs.version](#inputs.version). |
| `channel` | String | `stable` | Docker CE [channel](https://download.docker.com/linux/static/) (`stable` or `test`). Only applicable to `type=archive` |
| `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. |
| `set-host` | Bool | `false` | Set `DOCKER_HOST` environment variable to docker socket path. |
| `rootless` | Bool | `false` | Start daemon in rootless mode |
| Name | Type | Default | Description |
|-------------------|--------|------------------------------|-----------------------------------------------------------------------------------------------------------------------------|
| `version` | String | `latest` | Docker version to use. See [inputs.version](#inputs.version). |
| `channel` | String | `stable` | Docker CE [channel](https://download.docker.com/linux/static/) (`stable` or `test`). Only applicable to `type=archive` |
| `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. |
| `set-host` | Bool | `false` | Set `DOCKER_HOST` environment variable to docker socket path. |
| `rootless` | Bool | `false` | Start daemon in rootless mode |
| `runtime-basedir` | String | `<home>/setup-docker-action` | Docker runtime base directory |

### inputs.version

Expand Down
24 changes: 18 additions & 6 deletions __tests__/context.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {beforeEach, describe, expect, test} from '@jest/globals';
import * as os from 'os';
import * as path from 'path';

import * as context from '../src/context';

Expand Down Expand Up @@ -30,7 +32,8 @@ describe('getInputs', () => {
context: '',
daemonConfig: '',
rootless: false,
setHost: false
setHost: false,
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
} as context.Inputs
],
[
Expand All @@ -52,7 +55,8 @@ describe('getInputs', () => {
context: 'foo',
daemonConfig: `{"debug":true,"features":{"containerd-snapshotter":true}}`,
rootless: false,
setHost: false
setHost: false,
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
} as context.Inputs
],
[
Expand All @@ -70,7 +74,8 @@ describe('getInputs', () => {
context: '',
daemonConfig: '',
rootless: false,
setHost: true
setHost: true,
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
} as context.Inputs
],
[
Expand All @@ -90,7 +95,8 @@ describe('getInputs', () => {
context: 'foo',
daemonConfig: `{"debug":true,"features":{"containerd-snapshotter":true}}`,
rootless: false,
setHost: false
setHost: false,
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
} as context.Inputs
],
[
Expand All @@ -108,7 +114,8 @@ describe('getInputs', () => {
context: '',
daemonConfig: '',
rootless: false,
setHost: false
setHost: false,
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
} as context.Inputs
],
[
Expand All @@ -128,6 +135,7 @@ describe('getInputs', () => {
context: '',
daemonConfig: '',
rootless: false,
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
} as context.Inputs
],
[
Expand All @@ -147,6 +155,7 @@ describe('getInputs', () => {
context: '',
daemonConfig: '',
rootless: false,
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
} as context.Inputs
],
[
Expand All @@ -165,6 +174,7 @@ describe('getInputs', () => {
context: '',
daemonConfig: '',
rootless: false,
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
} as context.Inputs
],
[
Expand All @@ -183,6 +193,7 @@ describe('getInputs', () => {
context: '',
daemonConfig: '',
rootless: true,
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
} as context.Inputs
],
[
Expand All @@ -203,7 +214,8 @@ describe('getInputs', () => {
daemonConfig: '',
tcpPort: 2378,
rootless: false,
setHost: false
setHost: false,
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
} as context.Inputs
],
])(
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ inputs:
description: 'Enable Docker rootless mode'
default: 'false'
required: false
runtime-basedir:
description: 'Docker runtime base directory'
required: false

outputs:
sock:
Expand Down
24 changes: 12 additions & 12 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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"license": "Apache-2.0",
"dependencies": {
"@actions/core": "^1.10.1",
"@docker/actions-toolkit": "^0.49.0",
"@docker/actions-toolkit": "^0.64.0",
"uuid": "^10.0.0"
},
"devDependencies": {
Expand Down
6 changes: 5 additions & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os from 'os';
import path from 'path';
import * as core from '@actions/core';
import {parse} from 'csv-parse/sync';

Expand All @@ -11,6 +13,7 @@ export interface Inputs {
context: string;
setHost: boolean;
rootless: boolean;
runtimeBasedir: string;
}

export function getInputs(): Inputs {
Expand All @@ -27,7 +30,8 @@ export function getInputs(): Inputs {
tcpPort: Util.getInputNumber('tcp-port'),
context: core.getInput('context'),
setHost: core.getBooleanInput('set-host'),
rootless: core.getBooleanInput('rootless')
rootless: core.getBooleanInput('rootless'),
runtimeBasedir: core.getInput('runtime-basedir') || path.join(os.homedir(), `setup-docker-action`)
};
}

Expand Down
31 changes: 29 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as crypto from 'crypto';
import os from 'os';
import path from 'path';
import * as core from '@actions/core';
import * as actionsToolkit from '@docker/actions-toolkit';
import {Install} from '@docker/actions-toolkit/lib/docker/install';
import {Docker} from '@docker/actions-toolkit/lib/docker/docker';
import axios, {isAxiosError} from 'axios';
import {Install as RegclientInstall} from '@docker/actions-toolkit/lib/regclient/install';
import {Install as UndockInstall} from '@docker/actions-toolkit/lib/undock/install';

import * as context from './context';
import * as stateHelper from './state-helper';
Expand All @@ -25,18 +26,44 @@ async function validateSubscription(): Promise<void> {
}
}

const regctlDefaultVersion = 'v0.8.3';
const undockDefaultVersion = 'v0.10.0';

actionsToolkit.run(
// main
async () => {
await validateSubscription();

const input: context.Inputs = context.getInputs();
const runDir = path.join(os.homedir(), `setup-docker-action-${crypto.randomUUID().slice(0, 8)}`);
const runDir = path.join(input.runtimeBasedir, `run-${crypto.randomUUID().slice(0, 8)}`);

if (input.context == 'default') {
throw new Error(`'default' context cannot be used.`);
}

if (input.source.type === 'image') {
await core.group(`Download and install regctl`, async () => {
const regclientInstall = new RegclientInstall();
const regclientBinPath = await regclientInstall.download(
process.env.REGCTL_VERSION && process.env.REGCTL_VERSION.trim()
? process.env.REGCTL_VERSION
: regctlDefaultVersion,
true
);
await regclientInstall.install(regclientBinPath);
});
await core.group(`Download and install undock`, async () => {
const undockInstall = new UndockInstall();
const undockBinPath = await undockInstall.download(
process.env.UNDOCK_VERSION && process.env.UNDOCK_VERSION.trim()
? process.env.UNDOCK_VERSION
: undockDefaultVersion,
true
);
await undockInstall.install(undockBinPath);
});
}

let tcpPort: number | undefined;
let tcpAddress: string | undefined;
if (input.tcpPort) {
Expand Down
Loading
Loading