mirror of
https://github.com/docker/setup-docker-action.git
synced 2025-04-20 07:40:02 +02:00
Merge pull request #106 from vvoland/binimg
support downloading binaries from docker images
This commit is contained in:
commit
8321f1dc18
1
.github/workflows/ci.yml
vendored
1
.github/workflows/ci.yml
vendored
@ -33,6 +33,7 @@ jobs:
|
|||||||
version:
|
version:
|
||||||
- pinned
|
- pinned
|
||||||
- latest
|
- latest
|
||||||
|
- type=image,tag=27.3.1
|
||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
|
@ -21,8 +21,11 @@ describe('getInputs', () => {
|
|||||||
['set-host', 'false'],
|
['set-host', 'false'],
|
||||||
]),
|
]),
|
||||||
{
|
{
|
||||||
|
source: {
|
||||||
|
type: 'archive',
|
||||||
version: 'v24.0.8',
|
version: 'v24.0.8',
|
||||||
channel: '',
|
channel: 'stable'
|
||||||
|
},
|
||||||
context: '',
|
context: '',
|
||||||
daemonConfig: '',
|
daemonConfig: '',
|
||||||
setHost: false
|
setHost: false
|
||||||
@ -38,8 +41,11 @@ describe('getInputs', () => {
|
|||||||
['set-host', 'false'],
|
['set-host', 'false'],
|
||||||
]),
|
]),
|
||||||
{
|
{
|
||||||
|
source: {
|
||||||
|
type: 'archive',
|
||||||
version: 'v24.0.0-rc.4',
|
version: 'v24.0.0-rc.4',
|
||||||
channel: 'test',
|
channel: 'test'
|
||||||
|
},
|
||||||
context: 'foo',
|
context: 'foo',
|
||||||
daemonConfig: `{"debug":true,"features":{"containerd-snapshotter":true}}`,
|
daemonConfig: `{"debug":true,"features":{"containerd-snapshotter":true}}`,
|
||||||
setHost: false
|
setHost: false
|
||||||
@ -51,13 +57,100 @@ describe('getInputs', () => {
|
|||||||
['set-host', 'true'],
|
['set-host', 'true'],
|
||||||
]),
|
]),
|
||||||
{
|
{
|
||||||
|
source: {
|
||||||
|
type: 'archive',
|
||||||
version: 'latest',
|
version: 'latest',
|
||||||
channel: '',
|
channel: 'stable',
|
||||||
|
},
|
||||||
context: '',
|
context: '',
|
||||||
daemonConfig: '',
|
daemonConfig: '',
|
||||||
setHost: true
|
setHost: true
|
||||||
} as context.Inputs
|
} as context.Inputs
|
||||||
]
|
],
|
||||||
|
[
|
||||||
|
3,
|
||||||
|
new Map<string, string>([
|
||||||
|
['version', 'type=image,tag=master'],
|
||||||
|
['context', 'foo'],
|
||||||
|
['daemon-config', `{"debug":true,"features":{"containerd-snapshotter":true}}`],
|
||||||
|
['set-host', 'false'],
|
||||||
|
]),
|
||||||
|
{
|
||||||
|
source: {
|
||||||
|
type: 'image',
|
||||||
|
tag: 'master',
|
||||||
|
},
|
||||||
|
context: 'foo',
|
||||||
|
daemonConfig: `{"debug":true,"features":{"containerd-snapshotter":true}}`,
|
||||||
|
setHost: false
|
||||||
|
} as context.Inputs
|
||||||
|
],
|
||||||
|
[
|
||||||
|
4,
|
||||||
|
new Map<string, string>([
|
||||||
|
['version', 'type=image'],
|
||||||
|
['set-host', 'false'],
|
||||||
|
]),
|
||||||
|
{
|
||||||
|
source: {
|
||||||
|
type: 'image',
|
||||||
|
tag: 'latest',
|
||||||
|
},
|
||||||
|
context: '',
|
||||||
|
daemonConfig: '',
|
||||||
|
setHost: false
|
||||||
|
} as context.Inputs
|
||||||
|
],
|
||||||
|
[
|
||||||
|
5,
|
||||||
|
new Map<string, string>([
|
||||||
|
['version', 'type=archive'],
|
||||||
|
['set-host', 'false'],
|
||||||
|
]),
|
||||||
|
{
|
||||||
|
source: {
|
||||||
|
type: 'archive',
|
||||||
|
version: 'latest',
|
||||||
|
channel: 'stable',
|
||||||
|
},
|
||||||
|
setHost: false,
|
||||||
|
context: '',
|
||||||
|
daemonConfig: '',
|
||||||
|
} as context.Inputs
|
||||||
|
],
|
||||||
|
[
|
||||||
|
6,
|
||||||
|
new Map<string, string>([
|
||||||
|
['version', 'version=v27.2.0,channel=test'],
|
||||||
|
['set-host', 'false'],
|
||||||
|
]),
|
||||||
|
{
|
||||||
|
source: {
|
||||||
|
type: 'archive',
|
||||||
|
version: 'v27.2.0',
|
||||||
|
channel: 'test',
|
||||||
|
},
|
||||||
|
setHost: false,
|
||||||
|
context: '',
|
||||||
|
daemonConfig: '',
|
||||||
|
} as context.Inputs
|
||||||
|
],
|
||||||
|
[
|
||||||
|
7,
|
||||||
|
new Map<string, string>([
|
||||||
|
['version', 'type=image,tag=27.2.1'],
|
||||||
|
['set-host', 'false'],
|
||||||
|
]),
|
||||||
|
{
|
||||||
|
source: {
|
||||||
|
type: 'image',
|
||||||
|
tag: '27.2.1',
|
||||||
|
},
|
||||||
|
setHost: false,
|
||||||
|
context: '',
|
||||||
|
daemonConfig: '',
|
||||||
|
} 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) => {
|
||||||
|
2
dist/index.js
generated
vendored
2
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
@ -1,19 +1,96 @@
|
|||||||
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';
|
||||||
|
|
||||||
export interface Inputs {
|
export interface Inputs {
|
||||||
version: string;
|
source: InstallSource;
|
||||||
channel: string;
|
|
||||||
daemonConfig?: string;
|
daemonConfig?: string;
|
||||||
context: string;
|
context: string;
|
||||||
setHost: boolean;
|
setHost: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getInputs(): Inputs {
|
export function getInputs(): Inputs {
|
||||||
|
const rawVersion = core.getInput('version') || 'latest';
|
||||||
|
const source = parseSource(rawVersion);
|
||||||
|
const channel = core.getInput('channel');
|
||||||
|
if (channel && source.type === 'archive') {
|
||||||
|
source.channel = channel;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
version: core.getInput('version') || 'latest',
|
source: source,
|
||||||
channel: core.getInput('channel'),
|
|
||||||
daemonConfig: core.getInput('daemon-config'),
|
daemonConfig: core.getInput('daemon-config'),
|
||||||
context: core.getInput('context'),
|
context: core.getInput('context'),
|
||||||
setHost: core.getBooleanInput('set-host')
|
setHost: core.getBooleanInput('set-host')
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseSource(input: string): InstallSource {
|
||||||
|
let [type, version, channel, tag] = ['archive', 'latest', 'stable', 'latest'];
|
||||||
|
|
||||||
|
const fields = parse(input, {
|
||||||
|
relaxColumnCount: true,
|
||||||
|
skipEmptyLines: true
|
||||||
|
})[0];
|
||||||
|
for (const field of fields) {
|
||||||
|
const parts = field
|
||||||
|
.toString()
|
||||||
|
.split(/(?<=^[^=]+?)=/)
|
||||||
|
.map(item => item.trim());
|
||||||
|
|
||||||
|
switch (parts[0]) {
|
||||||
|
case 'type':
|
||||||
|
type = parts[1];
|
||||||
|
break;
|
||||||
|
case 'version':
|
||||||
|
version = parts[1];
|
||||||
|
break;
|
||||||
|
case 'channel':
|
||||||
|
channel = parts[1];
|
||||||
|
break;
|
||||||
|
case 'tag':
|
||||||
|
tag = parts[1];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (fields.length === 1) {
|
||||||
|
version = parts[0];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
throw new Error(`Invalid field: ${parts[0]}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!type) {
|
||||||
|
throw new Error(`Invalid type: ${type}`);
|
||||||
|
}
|
||||||
|
if (!channel) {
|
||||||
|
throw new Error(`Invalid channel: ${channel}`);
|
||||||
|
}
|
||||||
|
if (!version) {
|
||||||
|
throw new Error(`Invalid version: ${version}`);
|
||||||
|
}
|
||||||
|
if (!tag) {
|
||||||
|
throw new Error(`Invalid tag: ${tag}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
let src: InstallSource;
|
||||||
|
switch (type) {
|
||||||
|
case 'archive':
|
||||||
|
src = {
|
||||||
|
type: 'archive',
|
||||||
|
version: version,
|
||||||
|
channel: channel
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'image':
|
||||||
|
src = {
|
||||||
|
type: 'image',
|
||||||
|
tag: tag
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Error(`Invalid version: ${input}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return src;
|
||||||
|
}
|
||||||
|
@ -21,16 +21,12 @@ actionsToolkit.run(
|
|||||||
|
|
||||||
const install = new Install({
|
const install = new Install({
|
||||||
runDir: runDir,
|
runDir: runDir,
|
||||||
source: {
|
source: input.source,
|
||||||
type: 'archive',
|
|
||||||
version: input.version,
|
|
||||||
channel: input.channel || 'stable'
|
|
||||||
},
|
|
||||||
contextName: input.context || 'setup-docker-action',
|
contextName: input.context || 'setup-docker-action',
|
||||||
daemonConfig: input.daemonConfig
|
daemonConfig: input.daemonConfig
|
||||||
});
|
});
|
||||||
let toolDir;
|
let toolDir;
|
||||||
if (!(await Docker.isAvailable()) || input.version) {
|
if (!(await Docker.isAvailable()) || input.source) {
|
||||||
await core.group(`Download docker`, async () => {
|
await core.group(`Download docker`, async () => {
|
||||||
toolDir = await install.download();
|
toolDir = await install.download();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user