@docker/actions-toolkit 0.12.0-rc.2 → 0.12.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/buildkit/buildkit.js +59 -72
- package/lib/buildkit/buildkit.js.map +1 -1
- package/lib/buildx/bake.js +43 -53
- package/lib/buildx/bake.js.map +1 -1
- package/lib/buildx/builder.js +29 -41
- package/lib/buildx/builder.js.map +1 -1
- package/lib/buildx/buildx.js +63 -84
- package/lib/buildx/buildx.js.map +1 -1
- package/lib/buildx/install.js +204 -230
- package/lib/buildx/install.js.map +1 -1
- package/lib/context.js +1 -1
- package/lib/context.js.map +1 -1
- package/lib/docker/docker.js +26 -43
- package/lib/docker/docker.js.map +1 -1
- package/lib/docker/install.js +313 -339
- package/lib/docker/install.js.map +1 -1
- package/lib/dockerhub.js +70 -91
- package/lib/dockerhub.js.map +1 -1
- package/lib/exec.js +6 -19
- package/lib/exec.js.map +1 -1
- package/lib/git.js +75 -102
- package/lib/git.js.map +1 -1
- package/lib/github.js +36 -46
- package/lib/github.js.map +1 -1
- package/lib/index.js +10 -21
- package/lib/index.js.map +1 -1
- package/lib/toolkit.js +6 -0
- package/lib/toolkit.js.map +1 -1
- package/lib/util.js +20 -33
- package/lib/util.js.map +1 -1
- package/package.json +16 -17
package/lib/docker/install.js
CHANGED
|
@@ -37,15 +37,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
37
37
|
__setModuleDefault(result, mod);
|
|
38
38
|
return result;
|
|
39
39
|
};
|
|
40
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
41
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
42
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
43
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
44
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
45
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
46
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
40
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
41
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
42
|
};
|
|
@@ -69,6 +60,13 @@ const exec_1 = require("../exec");
|
|
|
69
60
|
const util_1 = require("../util");
|
|
70
61
|
const assets_1 = require("./assets");
|
|
71
62
|
class Install {
|
|
63
|
+
runDir;
|
|
64
|
+
version;
|
|
65
|
+
channel;
|
|
66
|
+
contextName;
|
|
67
|
+
daemonConfig;
|
|
68
|
+
_version;
|
|
69
|
+
_toolDir;
|
|
72
70
|
constructor(opts) {
|
|
73
71
|
this.runDir = opts.runDir;
|
|
74
72
|
this.version = opts.version || 'latest';
|
|
@@ -79,325 +77,307 @@ class Install {
|
|
|
79
77
|
get toolDir() {
|
|
80
78
|
return this._toolDir || context_1.Context.tmpDir();
|
|
81
79
|
}
|
|
82
|
-
download() {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
80
|
+
async download() {
|
|
81
|
+
const release = await Install.getRelease(this.version);
|
|
82
|
+
this._version = release.tag_name.replace(/^v+|v+$/g, '');
|
|
83
|
+
core.debug(`docker.Install.download version: ${this._version}`);
|
|
84
|
+
const downloadURL = this.downloadURL(this._version, this.channel);
|
|
85
|
+
core.info(`Downloading ${downloadURL}`);
|
|
86
|
+
const downloadPath = await tc.downloadTool(downloadURL);
|
|
87
|
+
core.debug(`docker.Install.download downloadPath: ${downloadPath}`);
|
|
88
|
+
let extractFolder;
|
|
89
|
+
if (os_1.default.platform() == 'win32') {
|
|
90
|
+
extractFolder = await tc.extractZip(downloadPath);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
extractFolder = await tc.extractTar(downloadPath);
|
|
94
|
+
}
|
|
95
|
+
if (util_1.Util.isDirectory(path_1.default.join(extractFolder, 'docker'))) {
|
|
96
|
+
extractFolder = path_1.default.join(extractFolder, 'docker');
|
|
97
|
+
}
|
|
98
|
+
core.debug(`docker.Install.download extractFolder: ${extractFolder}`);
|
|
99
|
+
core.info('Fixing perms');
|
|
100
|
+
fs_1.default.readdir(path_1.default.join(extractFolder), function (err, files) {
|
|
101
|
+
if (err) {
|
|
102
|
+
throw err;
|
|
100
103
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (err) {
|
|
105
|
-
throw err;
|
|
106
|
-
}
|
|
107
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
108
|
-
files.forEach(function (file, index) {
|
|
109
|
-
fs_1.default.chmodSync(path_1.default.join(extractFolder, file), '0755');
|
|
110
|
-
});
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
105
|
+
files.forEach(function (file, index) {
|
|
106
|
+
fs_1.default.chmodSync(path_1.default.join(extractFolder, file), '0755');
|
|
111
107
|
});
|
|
112
|
-
const tooldir = yield tc.cacheDir(extractFolder, `docker-${this.channel}`, this._version.replace(/(0+)([1-9]+)/, '$2'));
|
|
113
|
-
core.addPath(tooldir);
|
|
114
|
-
core.info('Added Docker to PATH');
|
|
115
|
-
this._toolDir = tooldir;
|
|
116
|
-
return tooldir;
|
|
117
108
|
});
|
|
109
|
+
const tooldir = await tc.cacheDir(extractFolder, `docker-${this.channel}`, this._version.replace(/(0+)([1-9]+)/, '$2'));
|
|
110
|
+
core.addPath(tooldir);
|
|
111
|
+
core.info('Added Docker to PATH');
|
|
112
|
+
this._toolDir = tooldir;
|
|
113
|
+
return tooldir;
|
|
118
114
|
}
|
|
119
|
-
install() {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
115
|
+
async install() {
|
|
116
|
+
if (!this.toolDir) {
|
|
117
|
+
throw new Error('toolDir must be set. Run download first.');
|
|
118
|
+
}
|
|
119
|
+
if (!this.runDir) {
|
|
120
|
+
throw new Error('runDir must be set');
|
|
121
|
+
}
|
|
122
|
+
switch (os_1.default.platform()) {
|
|
123
|
+
case 'darwin': {
|
|
124
|
+
await this.installDarwin();
|
|
125
|
+
break;
|
|
123
126
|
}
|
|
124
|
-
|
|
125
|
-
|
|
127
|
+
case 'linux': {
|
|
128
|
+
await this.installLinux();
|
|
129
|
+
break;
|
|
126
130
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
case 'linux': {
|
|
133
|
-
yield this.installLinux();
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
case 'win32': {
|
|
137
|
-
yield this.installWindows();
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
default: {
|
|
141
|
-
throw new Error(`Unsupported platform: ${os_1.default.platform()}`);
|
|
142
|
-
}
|
|
131
|
+
case 'win32': {
|
|
132
|
+
await this.installWindows();
|
|
133
|
+
break;
|
|
143
134
|
}
|
|
144
|
-
|
|
135
|
+
default: {
|
|
136
|
+
throw new Error(`Unsupported platform: ${os_1.default.platform()}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
145
139
|
}
|
|
146
|
-
installDarwin() {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
140
|
+
async installDarwin() {
|
|
141
|
+
const colimaDir = path_1.default.join(os_1.default.homedir(), '.colima', 'default'); // TODO: create a custom colima profile to avoid overlap with other actions
|
|
142
|
+
await io.mkdirP(colimaDir);
|
|
143
|
+
const dockerHost = `unix://${colimaDir}/docker.sock`;
|
|
144
|
+
if (!(await Install.colimaInstalled())) {
|
|
145
|
+
await core.group('Installing colima', async () => {
|
|
146
|
+
await exec_1.Exec.exec('brew', ['install', 'colima']);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
await core.group('Creating colima config', async () => {
|
|
150
|
+
let colimaDaemonConfig = {};
|
|
151
|
+
if (this.daemonConfig) {
|
|
152
|
+
colimaDaemonConfig = JSON.parse(this.daemonConfig);
|
|
155
153
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
154
|
+
const colimaCfg = handlebars.compile(assets_1.colimaYamlData)({
|
|
155
|
+
daemonConfig: js_yaml_1.default.dump(js_yaml_1.default.load(JSON.stringify({ docker: colimaDaemonConfig }))),
|
|
156
|
+
dockerBinVersion: this._version,
|
|
157
|
+
dockerBinChannel: this.channel,
|
|
158
|
+
dockerBinArch: Install.platformArch()
|
|
159
|
+
});
|
|
160
|
+
core.info(`Writing colima config to ${path_1.default.join(colimaDir, 'colima.yaml')}`);
|
|
161
|
+
fs_1.default.writeFileSync(path_1.default.join(colimaDir, 'colima.yaml'), colimaCfg);
|
|
162
|
+
core.info(colimaCfg);
|
|
163
|
+
});
|
|
164
|
+
const qemuArch = await Install.qemuArch();
|
|
165
|
+
await core.group('QEMU version', async () => {
|
|
166
|
+
await exec_1.Exec.exec(`qemu-system-${qemuArch} --version`);
|
|
167
|
+
});
|
|
168
|
+
// https://github.com/abiosoft/colima/issues/786#issuecomment-1693629650
|
|
169
|
+
if (process.env.SIGN_QEMU_BINARY === '1') {
|
|
170
|
+
await core.group('Signing QEMU binary with entitlements', async () => {
|
|
171
|
+
const qemuEntitlementsFile = path_1.default.join(context_1.Context.tmpDir(), 'qemu-entitlements.xml');
|
|
172
|
+
core.info(`Writing entitlements to ${qemuEntitlementsFile}`);
|
|
173
|
+
fs_1.default.writeFileSync(qemuEntitlementsFile, assets_1.qemuEntitlements);
|
|
174
|
+
await exec_1.Exec.exec(`codesign --sign - --entitlements ${qemuEntitlementsFile} --force /usr/local/bin/qemu-system-${qemuArch}`);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
// colima is already started on the runner so env var added in download
|
|
178
|
+
// method is not expanded to the running process.
|
|
179
|
+
const envs = Object.assign({}, process.env, {
|
|
180
|
+
PATH: `${this.toolDir}:${process.env.PATH}`
|
|
181
|
+
});
|
|
182
|
+
await core.group('Starting colima', async () => {
|
|
183
|
+
const colimaStartArgs = ['start', '--very-verbose'];
|
|
184
|
+
if (process.env.COLIMA_START_ARGS) {
|
|
185
|
+
colimaStartArgs.push(process.env.COLIMA_START_ARGS);
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
await exec_1.Exec.exec(`colima ${colimaStartArgs.join(' ')}`, [], { env: envs });
|
|
189
|
+
}
|
|
190
|
+
catch (e) {
|
|
191
|
+
const limaColimaDir = path_1.default.join(os_1.default.homedir(), '.lima', 'colima');
|
|
192
|
+
promises_1.default
|
|
193
|
+
.readdir(limaColimaDir)
|
|
194
|
+
.then(files => {
|
|
195
|
+
files
|
|
196
|
+
.filter(f => path_1.default.extname(f) === '.log')
|
|
197
|
+
.forEach(f => {
|
|
198
|
+
const logfile = path_1.default.join(limaColimaDir, f);
|
|
199
|
+
const logcontent = fs_1.default.readFileSync(logfile, { encoding: 'utf8' }).trim();
|
|
200
|
+
if (logcontent.length > 0) {
|
|
201
|
+
core.info(`### ${logfile}:\n${logcontent}`);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
})
|
|
205
|
+
.catch(() => {
|
|
206
|
+
// ignore
|
|
166
207
|
});
|
|
167
|
-
|
|
168
|
-
fs_1.default.writeFileSync(path_1.default.join(colimaDir, 'colima.yaml'), colimaCfg);
|
|
169
|
-
core.info(colimaCfg);
|
|
170
|
-
}));
|
|
171
|
-
const qemuArch = yield Install.qemuArch();
|
|
172
|
-
yield core.group('QEMU version', () => __awaiter(this, void 0, void 0, function* () {
|
|
173
|
-
yield exec_1.Exec.exec(`qemu-system-${qemuArch} --version`);
|
|
174
|
-
}));
|
|
175
|
-
// https://github.com/abiosoft/colima/issues/786#issuecomment-1693629650
|
|
176
|
-
if (process.env.SIGN_QEMU_BINARY === '1') {
|
|
177
|
-
yield core.group('Signing QEMU binary with entitlements', () => __awaiter(this, void 0, void 0, function* () {
|
|
178
|
-
const qemuEntitlementsFile = path_1.default.join(context_1.Context.tmpDir(), 'qemu-entitlements.xml');
|
|
179
|
-
core.info(`Writing entitlements to ${qemuEntitlementsFile}`);
|
|
180
|
-
fs_1.default.writeFileSync(qemuEntitlementsFile, assets_1.qemuEntitlements);
|
|
181
|
-
yield exec_1.Exec.exec(`codesign --sign - --entitlements ${qemuEntitlementsFile} --force /usr/local/bin/qemu-system-${qemuArch}`);
|
|
182
|
-
}));
|
|
208
|
+
throw e;
|
|
183
209
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
210
|
+
});
|
|
211
|
+
await core.group('Create Docker context', async () => {
|
|
212
|
+
await exec_1.Exec.exec('docker', ['context', 'create', this.contextName, '--docker', `host=${dockerHost}`]);
|
|
213
|
+
await exec_1.Exec.exec('docker', ['context', 'use', this.contextName]);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
async installLinux() {
|
|
217
|
+
const dockerHost = `unix://${path_1.default.join(this.runDir, 'docker.sock')}`;
|
|
218
|
+
await io.mkdirP(this.runDir);
|
|
219
|
+
const daemonConfigPath = path_1.default.join(this.runDir, 'daemon.json');
|
|
220
|
+
await fs_1.default.writeFileSync(daemonConfigPath, '{}');
|
|
221
|
+
let daemonConfig = undefined;
|
|
222
|
+
const daemonConfigDefaultPath = '/etc/docker/daemon.json';
|
|
223
|
+
if (fs_1.default.existsSync(daemonConfigDefaultPath)) {
|
|
224
|
+
await core.group('Default Docker daemon config found', async () => {
|
|
225
|
+
core.info(JSON.stringify(JSON.parse(fs_1.default.readFileSync(daemonConfigDefaultPath, { encoding: 'utf8' })), null, 2));
|
|
188
226
|
});
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
227
|
+
daemonConfig = JSON.parse(fs_1.default.readFileSync(daemonConfigDefaultPath, { encoding: 'utf8' }));
|
|
228
|
+
}
|
|
229
|
+
if (this.daemonConfig) {
|
|
230
|
+
daemonConfig = Object.assign(daemonConfig || {}, JSON.parse(this.daemonConfig));
|
|
231
|
+
}
|
|
232
|
+
if (daemonConfig) {
|
|
233
|
+
const daemonConfigStr = JSON.stringify(daemonConfig, null, 2);
|
|
234
|
+
await core.group('Writing Docker daemon config', async () => {
|
|
235
|
+
fs_1.default.writeFileSync(daemonConfigPath, daemonConfigStr);
|
|
236
|
+
core.info(daemonConfigStr);
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
await core.group('Start Docker daemon', async () => {
|
|
240
|
+
const bashPath = await io.which('bash', true);
|
|
241
|
+
const cmd = `${this.toolDir}/dockerd --host="${dockerHost}" --config-file="${daemonConfigPath}" --exec-root="${this.runDir}/execroot" --data-root="${this.runDir}/data" --pidfile="${this.runDir}/docker.pid" --userland-proxy=false`;
|
|
242
|
+
core.info(`[command] ${cmd}`); // https://github.com/actions/toolkit/blob/3d652d3133965f63309e4b2e1c8852cdbdcb3833/packages/exec/src/toolrunner.ts#L47
|
|
243
|
+
const proc = await child_process.spawn(
|
|
244
|
+
// We can't use Exec.exec here because we need to detach the process to
|
|
245
|
+
// avoid killing it when the action finishes running. Even if detached,
|
|
246
|
+
// we also need to run dockerd in a subshell and unref the process so
|
|
247
|
+
// GitHub Action doesn't wait for it to finish.
|
|
248
|
+
`sudo -E ${bashPath} << EOF
|
|
249
|
+
( ${cmd} 2>&1 | tee "${this.runDir}/dockerd.log" ) &
|
|
250
|
+
EOF`, [], {
|
|
251
|
+
detached: true,
|
|
252
|
+
shell: true,
|
|
253
|
+
stdio: ['ignore', process.stdout, process.stderr]
|
|
254
|
+
});
|
|
255
|
+
proc.unref();
|
|
256
|
+
await util_1.Util.sleep(3);
|
|
257
|
+
const retries = 10;
|
|
258
|
+
await (0, async_retry_1.default)(async (bail) => {
|
|
194
259
|
try {
|
|
195
|
-
|
|
260
|
+
await exec_1.Exec.getExecOutput(`docker version`, undefined, {
|
|
261
|
+
silent: true,
|
|
262
|
+
env: Object.assign({}, process.env, {
|
|
263
|
+
DOCKER_HOST: dockerHost
|
|
264
|
+
})
|
|
265
|
+
});
|
|
196
266
|
}
|
|
197
267
|
catch (e) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
const logfile = path_1.default.join(limaColimaDir, f);
|
|
206
|
-
const logcontent = fs_1.default.readFileSync(logfile, { encoding: 'utf8' }).trim();
|
|
207
|
-
if (logcontent.length > 0) {
|
|
208
|
-
core.info(`### ${logfile}:\n${logcontent}`);
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
})
|
|
212
|
-
.catch(() => {
|
|
213
|
-
// ignore
|
|
214
|
-
});
|
|
215
|
-
throw e;
|
|
268
|
+
bail(e);
|
|
269
|
+
}
|
|
270
|
+
}, {
|
|
271
|
+
retries: retries,
|
|
272
|
+
minTimeout: 1000,
|
|
273
|
+
onRetry: (err, i) => {
|
|
274
|
+
core.info(`${err}. Retrying (${i}/${retries})...`);
|
|
216
275
|
}
|
|
217
|
-
})
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
})
|
|
276
|
+
});
|
|
277
|
+
core.info(`Docker daemon started started successfully`);
|
|
278
|
+
});
|
|
279
|
+
await core.group('Create Docker context', async () => {
|
|
280
|
+
await exec_1.Exec.exec('docker', ['context', 'create', this.contextName, '--docker', `host=${dockerHost}`]);
|
|
281
|
+
await exec_1.Exec.exec('docker', ['context', 'use', this.contextName]);
|
|
222
282
|
});
|
|
223
283
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
( ${cmd} 2>&1 | tee "${this.runDir}/dockerd.log" ) &
|
|
259
|
-
EOF`, [], {
|
|
260
|
-
detached: true,
|
|
261
|
-
shell: true,
|
|
262
|
-
stdio: ['ignore', process.stdout, process.stderr]
|
|
263
|
-
});
|
|
264
|
-
proc.unref();
|
|
265
|
-
yield util_1.Util.sleep(3);
|
|
266
|
-
const retries = 10;
|
|
267
|
-
yield (0, async_retry_1.default)((bail) => __awaiter(this, void 0, void 0, function* () {
|
|
268
|
-
try {
|
|
269
|
-
yield exec_1.Exec.getExecOutput(`docker version`, undefined, {
|
|
270
|
-
silent: true,
|
|
271
|
-
env: Object.assign({}, process.env, {
|
|
272
|
-
DOCKER_HOST: dockerHost
|
|
273
|
-
})
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
catch (e) {
|
|
277
|
-
bail(e);
|
|
278
|
-
}
|
|
279
|
-
}), {
|
|
280
|
-
retries: retries,
|
|
281
|
-
minTimeout: 1000,
|
|
282
|
-
onRetry: (err, i) => {
|
|
283
|
-
core.info(`${err}. Retrying (${i}/${retries})...`);
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
core.info(`Docker daemon started started successfully`);
|
|
287
|
-
}));
|
|
288
|
-
yield core.group('Create Docker context', () => __awaiter(this, void 0, void 0, function* () {
|
|
289
|
-
yield exec_1.Exec.exec('docker', ['context', 'create', this.contextName, '--docker', `host=${dockerHost}`]);
|
|
290
|
-
yield exec_1.Exec.exec('docker', ['context', 'use', this.contextName]);
|
|
291
|
-
}));
|
|
284
|
+
async installWindows() {
|
|
285
|
+
const dockerHost = 'npipe:////./pipe/setup_docker_action';
|
|
286
|
+
let daemonConfig = undefined;
|
|
287
|
+
const daemonConfigPath = path_1.default.join(this.runDir, 'daemon.json');
|
|
288
|
+
if (fs_1.default.existsSync(daemonConfigPath)) {
|
|
289
|
+
await core.group('Default Docker daemon config found', async () => {
|
|
290
|
+
core.info(JSON.stringify(JSON.parse(fs_1.default.readFileSync(daemonConfigPath, { encoding: 'utf8' })), null, 2));
|
|
291
|
+
});
|
|
292
|
+
daemonConfig = JSON.parse(fs_1.default.readFileSync(daemonConfigPath, { encoding: 'utf8' }));
|
|
293
|
+
}
|
|
294
|
+
if (this.daemonConfig) {
|
|
295
|
+
daemonConfig = Object.assign(daemonConfig || {}, JSON.parse(this.daemonConfig));
|
|
296
|
+
}
|
|
297
|
+
let daemonConfigStr = '{}';
|
|
298
|
+
if (daemonConfig) {
|
|
299
|
+
daemonConfigStr = JSON.stringify(daemonConfig, null, 2);
|
|
300
|
+
await core.group('Docker daemon config', async () => {
|
|
301
|
+
core.info(daemonConfigStr);
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
await core.group('Install Docker daemon service', async () => {
|
|
305
|
+
const setupCmd = await util_1.Util.powershellCommand((0, assets_1.setupDockerWinPs1)(), {
|
|
306
|
+
ToolDir: this.toolDir,
|
|
307
|
+
RunDir: this.runDir,
|
|
308
|
+
DockerHost: dockerHost,
|
|
309
|
+
DaemonConfig: daemonConfigStr
|
|
310
|
+
});
|
|
311
|
+
await exec_1.Exec.exec(setupCmd.command, setupCmd.args);
|
|
312
|
+
const logCmd = await util_1.Util.powershellCommand((0, assets_1.dockerServiceLogsPs1)());
|
|
313
|
+
await exec_1.Exec.exec(logCmd.command, logCmd.args);
|
|
314
|
+
});
|
|
315
|
+
await core.group('Create Docker context', async () => {
|
|
316
|
+
await exec_1.Exec.exec('docker', ['context', 'create', this.contextName, '--docker', `host=${dockerHost}`]);
|
|
317
|
+
await exec_1.Exec.exec('docker', ['context', 'use', this.contextName]);
|
|
292
318
|
});
|
|
293
319
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}));
|
|
303
|
-
daemonConfig = JSON.parse(fs_1.default.readFileSync(daemonConfigPath, { encoding: 'utf8' }));
|
|
304
|
-
}
|
|
305
|
-
if (this.daemonConfig) {
|
|
306
|
-
daemonConfig = Object.assign(daemonConfig || {}, JSON.parse(this.daemonConfig));
|
|
320
|
+
async tearDown() {
|
|
321
|
+
if (!this.runDir) {
|
|
322
|
+
throw new Error('runDir must be set');
|
|
323
|
+
}
|
|
324
|
+
switch (os_1.default.platform()) {
|
|
325
|
+
case 'darwin': {
|
|
326
|
+
await this.tearDownDarwin();
|
|
327
|
+
break;
|
|
307
328
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
yield core.group('Docker daemon config', () => __awaiter(this, void 0, void 0, function* () {
|
|
312
|
-
core.info(daemonConfigStr);
|
|
313
|
-
}));
|
|
329
|
+
case 'linux': {
|
|
330
|
+
await this.tearDownLinux();
|
|
331
|
+
break;
|
|
314
332
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
RunDir: this.runDir,
|
|
319
|
-
DockerHost: dockerHost,
|
|
320
|
-
DaemonConfig: daemonConfigStr
|
|
321
|
-
});
|
|
322
|
-
yield exec_1.Exec.exec(setupCmd.command, setupCmd.args);
|
|
323
|
-
const logCmd = yield util_1.Util.powershellCommand((0, assets_1.dockerServiceLogsPs1)());
|
|
324
|
-
yield exec_1.Exec.exec(logCmd.command, logCmd.args);
|
|
325
|
-
}));
|
|
326
|
-
yield core.group('Create Docker context', () => __awaiter(this, void 0, void 0, function* () {
|
|
327
|
-
yield exec_1.Exec.exec('docker', ['context', 'create', this.contextName, '--docker', `host=${dockerHost}`]);
|
|
328
|
-
yield exec_1.Exec.exec('docker', ['context', 'use', this.contextName]);
|
|
329
|
-
}));
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
tearDown() {
|
|
333
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
334
|
-
if (!this.runDir) {
|
|
335
|
-
throw new Error('runDir must be set');
|
|
333
|
+
case 'win32': {
|
|
334
|
+
await this.tearDownWindows();
|
|
335
|
+
break;
|
|
336
336
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
yield this.tearDownDarwin();
|
|
340
|
-
break;
|
|
341
|
-
}
|
|
342
|
-
case 'linux': {
|
|
343
|
-
yield this.tearDownLinux();
|
|
344
|
-
break;
|
|
345
|
-
}
|
|
346
|
-
case 'win32': {
|
|
347
|
-
yield this.tearDownWindows();
|
|
348
|
-
break;
|
|
349
|
-
}
|
|
350
|
-
default: {
|
|
351
|
-
throw new Error(`Unsupported platform: ${os_1.default.platform()}`);
|
|
352
|
-
}
|
|
337
|
+
default: {
|
|
338
|
+
throw new Error(`Unsupported platform: ${os_1.default.platform()}`);
|
|
353
339
|
}
|
|
354
|
-
}
|
|
340
|
+
}
|
|
355
341
|
}
|
|
356
|
-
tearDownDarwin() {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
yield exec_1.Exec.exec('sudo', ['rm', '-rf', this.runDir]);
|
|
369
|
-
}));
|
|
342
|
+
async tearDownDarwin() {
|
|
343
|
+
await core.group('Docker daemon logs', async () => {
|
|
344
|
+
await exec_1.Exec.exec('colima', ['exec', '--', 'cat', '/var/log/docker.log']);
|
|
345
|
+
});
|
|
346
|
+
await core.group('Stopping colima', async () => {
|
|
347
|
+
await exec_1.Exec.exec('colima', ['stop', '--very-verbose']);
|
|
348
|
+
});
|
|
349
|
+
await core.group('Removing Docker context', async () => {
|
|
350
|
+
await exec_1.Exec.exec('docker', ['context', 'rm', '-f', this.contextName]);
|
|
351
|
+
});
|
|
352
|
+
await core.group(`Cleaning up runDir`, async () => {
|
|
353
|
+
await exec_1.Exec.exec('sudo', ['rm', '-rf', this.runDir]);
|
|
370
354
|
});
|
|
371
355
|
}
|
|
372
|
-
tearDownLinux() {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
});
|
|
389
|
-
}));
|
|
356
|
+
async tearDownLinux() {
|
|
357
|
+
await core.group('Docker daemon logs', async () => {
|
|
358
|
+
core.info(fs_1.default.readFileSync(path_1.default.join(this.runDir, 'dockerd.log'), { encoding: 'utf8' }));
|
|
359
|
+
});
|
|
360
|
+
await core.group('Stopping Docker daemon', async () => {
|
|
361
|
+
await exec_1.Exec.exec('sudo', ['kill', '-s', 'SIGTERM', fs_1.default.readFileSync(path_1.default.join(this.runDir, 'docker.pid')).toString().trim()]);
|
|
362
|
+
await util_1.Util.sleep(5);
|
|
363
|
+
});
|
|
364
|
+
await core.group('Removing Docker context', async () => {
|
|
365
|
+
await exec_1.Exec.exec('docker', ['context', 'rm', '-f', this.contextName]);
|
|
366
|
+
});
|
|
367
|
+
await core.group(`Cleaning up runDir`, async () => {
|
|
368
|
+
await exec_1.Exec.exec('sudo', ['rm', '-rf', this.runDir], {
|
|
369
|
+
ignoreReturnCode: true,
|
|
370
|
+
failOnStdErr: false
|
|
371
|
+
});
|
|
390
372
|
});
|
|
391
373
|
}
|
|
392
|
-
tearDownWindows() {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
yield exec_1.Exec.exec('docker', ['context', 'rm', '-f', this.contextName]);
|
|
400
|
-
}));
|
|
374
|
+
async tearDownWindows() {
|
|
375
|
+
await core.group('Docker daemon logs', async () => {
|
|
376
|
+
const logCmd = await util_1.Util.powershellCommand((0, assets_1.dockerServiceLogsPs1)());
|
|
377
|
+
await exec_1.Exec.exec(logCmd.command, logCmd.args);
|
|
378
|
+
});
|
|
379
|
+
await core.group('Removing Docker context', async () => {
|
|
380
|
+
await exec_1.Exec.exec('docker', ['context', 'rm', '-f', this.contextName]);
|
|
401
381
|
});
|
|
402
382
|
}
|
|
403
383
|
downloadURL(version, channel) {
|
|
@@ -450,51 +430,45 @@ EOF`, [], {
|
|
|
450
430
|
}
|
|
451
431
|
}
|
|
452
432
|
}
|
|
453
|
-
static colimaInstalled() {
|
|
454
|
-
return
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
return false;
|
|
464
|
-
});
|
|
433
|
+
static async colimaInstalled() {
|
|
434
|
+
return await io
|
|
435
|
+
.which('colima', true)
|
|
436
|
+
.then(res => {
|
|
437
|
+
core.debug(`docker.Install.colimaAvailable ok: ${res}`);
|
|
438
|
+
return true;
|
|
439
|
+
})
|
|
440
|
+
.catch(error => {
|
|
441
|
+
core.debug(`docker.Install.colimaAvailable error: ${error}`);
|
|
442
|
+
return false;
|
|
465
443
|
});
|
|
466
444
|
}
|
|
467
|
-
static qemuArch() {
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
return 'x86_64';
|
|
472
|
-
}
|
|
473
|
-
case 'arm64': {
|
|
474
|
-
return 'aarch64';
|
|
475
|
-
}
|
|
476
|
-
default: {
|
|
477
|
-
return os_1.default.arch();
|
|
478
|
-
}
|
|
445
|
+
static async qemuArch() {
|
|
446
|
+
switch (os_1.default.arch()) {
|
|
447
|
+
case 'x64': {
|
|
448
|
+
return 'x86_64';
|
|
479
449
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
static getRelease(version) {
|
|
483
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
484
|
-
const url = `https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/docker-releases.json`;
|
|
485
|
-
const http = new httpm.HttpClient('docker-actions-toolkit');
|
|
486
|
-
const resp = yield http.get(url);
|
|
487
|
-
const body = yield resp.readBody();
|
|
488
|
-
const statusCode = resp.message.statusCode || 500;
|
|
489
|
-
if (statusCode >= 400) {
|
|
490
|
-
throw new Error(`Failed to get Docker release ${version} from ${url} with status code ${statusCode}: ${body}`);
|
|
450
|
+
case 'arm64': {
|
|
451
|
+
return 'aarch64';
|
|
491
452
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
throw new Error(`Cannot find Docker release ${version} in ${url}`);
|
|
453
|
+
default: {
|
|
454
|
+
return os_1.default.arch();
|
|
495
455
|
}
|
|
496
|
-
|
|
497
|
-
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
static async getRelease(version) {
|
|
459
|
+
const url = `https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/docker-releases.json`;
|
|
460
|
+
const http = new httpm.HttpClient('docker-actions-toolkit');
|
|
461
|
+
const resp = await http.get(url);
|
|
462
|
+
const body = await resp.readBody();
|
|
463
|
+
const statusCode = resp.message.statusCode || 500;
|
|
464
|
+
if (statusCode >= 400) {
|
|
465
|
+
throw new Error(`Failed to get Docker release ${version} from ${url} with status code ${statusCode}: ${body}`);
|
|
466
|
+
}
|
|
467
|
+
const releases = JSON.parse(body);
|
|
468
|
+
if (!releases[version]) {
|
|
469
|
+
throw new Error(`Cannot find Docker release ${version} in ${url}`);
|
|
470
|
+
}
|
|
471
|
+
return releases[version];
|
|
498
472
|
}
|
|
499
473
|
}
|
|
500
474
|
exports.Install = Install;
|