docker: detach dockerd for linux install

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2023-03-02 13:48:24 +01:00
parent 3c2fe5ddb2
commit ac9d9d9a1b
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
4 changed files with 56 additions and 20 deletions

View File

@ -11,9 +11,9 @@
"prettier": "prettier --check \"./**/*.ts\"",
"prettier:fix": "prettier --write \"./**/*.ts\"",
"test": "jest",
"test:e2e": "jest -c jest.config.e2e.ts --runInBand --detectOpenHandles --forceExit",
"test:e2e": "jest -c jest.config.e2e.ts --runInBand --detectOpenHandles",
"test-coverage": "jest --coverage",
"test-coverage:e2e": "jest --coverage -c jest.config.e2e.ts --runInBand --detectOpenHandles --forceExit"
"test-coverage:e2e": "jest --coverage -c jest.config.e2e.ts --runInBand --detectOpenHandles"
},
"repository": {
"type": "git",
@ -50,6 +50,7 @@
"@actions/http-client": "^2.0.1",
"@actions/io": "^1.1.2",
"@actions/tool-cache": "^2.0.1",
"async-retry": "^1.3.3",
"csv-parse": "^5.3.5",
"handlebars": "^4.7.7",
"jwt-decode": "^3.1.2",

View File

@ -75,22 +75,6 @@ mkdir -p "$RUNDIR"
--userland-proxy=false \\
2>&1 | tee "$RUNDIR/dockerd.log"
) &
tries=60
while ! docker version &> /dev/null; do
((tries--))
if [ $tries -le 0 ]; then
if [ -z "$DOCKER_HOST" ]; then
echo >&2 "error: daemon failed to start"
else
echo >&2 "error: daemon at $DOCKER_HOST fails to 'docker version':"
docker version >&2 || true
fi
false
fi
sleep 2
done
echo "Docker daemon started successfully!"
`;
export const setupDockerWinPs1Data = `

View File

@ -14,9 +14,11 @@
* limitations under the License.
*/
import * as child_process from 'child_process';
import fs from 'fs';
import os from 'os';
import path from 'path';
import retry from 'async-retry';
import * as handlebars from 'handlebars';
import * as util from 'util';
import * as core from '@actions/core';
@ -133,9 +135,12 @@ export class Install {
private async installLinux(toolDir: string, runDir: string): Promise<void> {
const dockerHost = `unix://${path.join(runDir, 'docker.sock')}`;
await core.group('Install Docker daemon', async () => {
await core.group('Start Docker daemon', async () => {
const bashPath: string = await io.which('bash', true);
await Exec.exec('sudo', ['-E', bashPath, setupDockerLinuxSh()], {
const proc = await child_process.spawn(`sudo -E ${bashPath} ${setupDockerLinuxSh()}`, [], {
detached: true,
shell: true,
stdio: ['ignore', process.stdout, process.stderr],
env: Object.assign({}, process.env, {
TOOLDIR: toolDir,
RUNDIR: runDir,
@ -144,6 +149,35 @@ export class Install {
[key: string]: string;
}
});
proc.unref();
await retry(
async bail => {
await Exec.getExecOutput(`docker version`, undefined, {
ignoreReturnCode: true,
silent: true,
env: Object.assign({}, process.env, {
DOCKER_HOST: dockerHost
}) as {
[key: string]: string;
}
})
.then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
bail(new Error(res.stderr));
return false;
}
return res.exitCode == 0;
})
.catch(error => {
bail(error);
return false;
});
},
{
retries: 5
}
);
core.info(`Docker daemon started started successfully`);
});
await core.group('Create Docker context', async () => {

View File

@ -774,6 +774,7 @@ __metadata:
"@types/tmp": ^0.2.3
"@typescript-eslint/eslint-plugin": ^5.49.0
"@typescript-eslint/parser": ^5.49.0
async-retry: ^1.3.3
cpy-cli: ^4.2.0
csv-parse: ^5.3.5
dotenv: ^16.0.3
@ -2034,6 +2035,15 @@ __metadata:
languageName: node
linkType: hard
"async-retry@npm:^1.3.3":
version: 1.3.3
resolution: "async-retry@npm:1.3.3"
dependencies:
retry: 0.13.1
checksum: 38a7152ff7265a9321ea214b9c69e8224ab1febbdec98efbbde6e562f17ff68405569b796b1c5271f354aef8783665d29953f051f68c1fc45306e61aec82fdc4
languageName: node
linkType: hard
"asynckit@npm:^0.4.0":
version: 0.4.0
resolution: "asynckit@npm:0.4.0"
@ -5947,6 +5957,13 @@ __metadata:
languageName: node
linkType: hard
"retry@npm:0.13.1":
version: 0.13.1
resolution: "retry@npm:0.13.1"
checksum: 47c4d5be674f7c13eee4cfe927345023972197dbbdfba5d3af7e461d13b44de1bfd663bfc80d2f601f8ef3fc8164c16dd99655a221921954a65d044a2fc1233b
languageName: node
linkType: hard
"retry@npm:^0.12.0":
version: 0.12.0
resolution: "retry@npm:0.12.0"