docker: install for linux

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2023-02-28 20:05:08 +01:00
parent 3ec6f00f46
commit 93fa96f54f
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
6 changed files with 75 additions and 6 deletions

View File

@ -16,7 +16,7 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
os: os:
#- ubuntu-latest - ubuntu-latest
- macos-latest - macos-latest
- windows-latest - windows-latest
steps: steps:

View File

@ -12,7 +12,7 @@
"prettier:fix": "prettier --write \"./**/*.ts\"", "prettier:fix": "prettier --write \"./**/*.ts\"",
"test": "jest", "test": "jest",
"test-coverage": "jest --coverage", "test-coverage": "jest --coverage",
"test:e2e": "jest -c jest.config.e2e.ts" "test:e2e": "jest -c jest.config.e2e.ts --runInBand --detectOpenHandles --forceExit"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

51
scripts/setup-docker-linux.sh Executable file
View File

@ -0,0 +1,51 @@
#!/usr/bin/env bash
set -eu
: "${TOOLDIR=}"
: "${RUNDIR=}"
: "${DOCKER_HOST=}"
export PATH="$TOOLDIR::$PATH"
if [ -z "$DOCKER_HOST" ]; then
echo >&2 'error: DOCKER_HOST required'
false
fi
if ! command -v dockerd &> /dev/null; then
echo >&2 'error: dockerd missing from PATH'
false
fi
(
echo "Starting dockerd"
set -x
exec dockerd \
--host="$DOCKER_HOST" \
--exec-root="$RUNDIR/execroot" \
--data-root="$RUNDIR/data" \
--pidfile="$RUNDIR/docker.pid" \
--userland-proxy=false \
2>&1 | tee "$RUNDIR/dockerd.log"
) &
tries=60
echo "Waiting for daemon to start..."
while ! docker version &> /dev/null; do
((tries--))
if [ $tries -le 0 ]; then
printf "\n"
if [ -z "$DOCKER_HOST" ]; then
echo >&2 "error: daemon failed to start"
echo >&2 " check $RUNDIR/docker.log for details"
else
echo >&2 "error: daemon at $DOCKER_HOST fails to 'docker version':"
docker version >&2 || true
fi
false
fi
printf "."
sleep 2
done
printf "\n"

View File

@ -131,14 +131,31 @@ export class Install {
} }
private async installLinux(toolDir: string): Promise<void> { private async installLinux(toolDir: string): Promise<void> {
core.addPath(toolDir); const dockerHost = `unix://${path.join(Context.tmpDir(), 'docker.sock')}`;
core.info('Added Docker to PATH');
await core.group('Install Docker daemon', async () => {
const bashPath: string = await io.which('bash', true);
await Exec.exec('sudo', ['-E', bashPath, scripts.setupDockerLinux], {
env: Object.assign({}, process.env, {
TOOLDIR: toolDir,
RUNDIR: Context.tmpDir(),
DOCKER_HOST: dockerHost
}) as {
[key: string]: string;
}
});
});
await core.group('Create Docker context', async () => {
await Exec.exec('docker', ['context', 'create', 'setup-docker-action', '--docker', `host=${dockerHost}`]);
await Exec.exec('docker', ['context', 'use', 'setup-docker-action']);
});
} }
private async installWindows(toolDir: string): Promise<void> { private async installWindows(toolDir: string): Promise<void> {
const dockerHost = 'npipe:////./pipe/setup_docker_action'; const dockerHost = 'npipe:////./pipe/setup_docker_action';
const setupCmd = await Util.powershellCommand(scripts.setupDockerPowershell, { const setupCmd = await Util.powershellCommand(scripts.setupDockerWin, {
ToolDir: toolDir, ToolDir: toolDir,
TmpDir: Context.tmpDir(), TmpDir: Context.tmpDir(),
DockerHost: dockerHost DockerHost: dockerHost

View File

@ -18,5 +18,6 @@ import path from 'path';
const scriptsPath = path.join(__dirname, '..', 'scripts'); const scriptsPath = path.join(__dirname, '..', 'scripts');
export const setupDockerPowershell = path.join(scriptsPath, 'setup-docker.ps1'); export const setupDockerLinux = path.join(scriptsPath, 'setup-docker-linux.sh');
export const setupDockerWin = path.join(scriptsPath, 'setup-docker-win.ps1');
export const colimaConfig = path.join(scriptsPath, 'colima.yaml'); export const colimaConfig = path.join(scriptsPath, 'colima.yaml');