mirror of
https://github.com/docker/setup-docker-action.git
synced 2025-04-19 23:30: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:
|
||||
- pinned
|
||||
- latest
|
||||
- type=image,tag=27.3.1
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
|
@ -21,8 +21,11 @@ describe('getInputs', () => {
|
||||
['set-host', 'false'],
|
||||
]),
|
||||
{
|
||||
version: 'v24.0.8',
|
||||
channel: '',
|
||||
source: {
|
||||
type: 'archive',
|
||||
version: 'v24.0.8',
|
||||
channel: 'stable'
|
||||
},
|
||||
context: '',
|
||||
daemonConfig: '',
|
||||
setHost: false
|
||||
@ -38,8 +41,11 @@ describe('getInputs', () => {
|
||||
['set-host', 'false'],
|
||||
]),
|
||||
{
|
||||
version: 'v24.0.0-rc.4',
|
||||
channel: 'test',
|
||||
source: {
|
||||
type: 'archive',
|
||||
version: 'v24.0.0-rc.4',
|
||||
channel: 'test'
|
||||
},
|
||||
context: 'foo',
|
||||
daemonConfig: `{"debug":true,"features":{"containerd-snapshotter":true}}`,
|
||||
setHost: false
|
||||
@ -51,13 +57,100 @@ describe('getInputs', () => {
|
||||
['set-host', 'true'],
|
||||
]),
|
||||
{
|
||||
version: 'latest',
|
||||
channel: '',
|
||||
source: {
|
||||
type: 'archive',
|
||||
version: 'latest',
|
||||
channel: 'stable',
|
||||
},
|
||||
context: '',
|
||||
daemonConfig: '',
|
||||
setHost: true
|
||||
} 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',
|
||||
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 {InstallSource} from '@docker/actions-toolkit/lib/docker/install';
|
||||
import {parse} from 'csv-parse/sync';
|
||||
|
||||
export interface Inputs {
|
||||
version: string;
|
||||
channel: string;
|
||||
source: InstallSource;
|
||||
daemonConfig?: string;
|
||||
context: string;
|
||||
setHost: boolean;
|
||||
}
|
||||
|
||||
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 {
|
||||
version: core.getInput('version') || 'latest',
|
||||
channel: core.getInput('channel'),
|
||||
source: source,
|
||||
daemonConfig: core.getInput('daemon-config'),
|
||||
context: core.getInput('context'),
|
||||
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({
|
||||
runDir: runDir,
|
||||
source: {
|
||||
type: 'archive',
|
||||
version: input.version,
|
||||
channel: input.channel || 'stable'
|
||||
},
|
||||
source: input.source,
|
||||
contextName: input.context || 'setup-docker-action',
|
||||
daemonConfig: input.daemonConfig
|
||||
});
|
||||
let toolDir;
|
||||
if (!(await Docker.isAvailable()) || input.version) {
|
||||
if (!(await Docker.isAvailable()) || input.source) {
|
||||
await core.group(`Download docker`, async () => {
|
||||
toolDir = await install.download();
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user