diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index b970040..024ae10 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -16,7 +16,7 @@ jobs: fail-fast: false matrix: os: - #- ubuntu-latest + - ubuntu-latest - macos-latest - windows-latest steps: diff --git a/package.json b/package.json index f8aaf19..6886fd1 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "prettier:fix": "prettier --write \"./**/*.ts\"", "test": "jest", "test-coverage": "jest --coverage", - "test:e2e": "jest -c jest.config.e2e.ts" + "test:e2e": "jest -c jest.config.e2e.ts --runInBand --detectOpenHandles --forceExit" }, "repository": { "type": "git", diff --git a/scripts/setup-docker-linux.sh b/scripts/setup-docker-linux.sh new file mode 100755 index 0000000..763a707 --- /dev/null +++ b/scripts/setup-docker-linux.sh @@ -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" diff --git a/scripts/setup-docker.ps1 b/scripts/setup-docker-win.ps1 similarity index 100% rename from scripts/setup-docker.ps1 rename to scripts/setup-docker-win.ps1 diff --git a/src/docker/install.ts b/src/docker/install.ts index d722ae2..687c07f 100644 --- a/src/docker/install.ts +++ b/src/docker/install.ts @@ -131,14 +131,31 @@ export class Install { } private async installLinux(toolDir: string): Promise { - core.addPath(toolDir); - core.info('Added Docker to PATH'); + const dockerHost = `unix://${path.join(Context.tmpDir(), 'docker.sock')}`; + + 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 { const dockerHost = 'npipe:////./pipe/setup_docker_action'; - const setupCmd = await Util.powershellCommand(scripts.setupDockerPowershell, { + const setupCmd = await Util.powershellCommand(scripts.setupDockerWin, { ToolDir: toolDir, TmpDir: Context.tmpDir(), DockerHost: dockerHost diff --git a/src/scripts.ts b/src/scripts.ts index ac33853..600c1e3 100644 --- a/src/scripts.ts +++ b/src/scripts.ts @@ -18,5 +18,6 @@ import path from 'path'; 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');