docker: install with custom runDir
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
@@ -14,11 +14,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import path from 'path';
|
||||||
import {describe, expect, test} from '@jest/globals';
|
import {describe, expect, test} from '@jest/globals';
|
||||||
|
|
||||||
import {Install} from '../../src/docker/install';
|
import {Install} from '../../src/docker/install';
|
||||||
import {Docker} from '../../src/docker/docker';
|
import {Docker} from '../../src/docker/docker';
|
||||||
|
|
||||||
|
// prettier-ignore
|
||||||
|
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-jest');
|
||||||
|
|
||||||
describe('install', () => {
|
describe('install', () => {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
test.each(['23.0.0'])(
|
test.each(['23.0.0'])(
|
||||||
@@ -26,7 +30,7 @@ describe('install', () => {
|
|||||||
await expect((async () => {
|
await expect((async () => {
|
||||||
const install = new Install();
|
const install = new Install();
|
||||||
const toolPath = await install.download(version);
|
const toolPath = await install.download(version);
|
||||||
await install.install(toolPath, version);
|
await install.install(toolPath, tmpDir, version);
|
||||||
await Docker.printVersion();
|
await Docker.printVersion();
|
||||||
await Docker.printInfo();
|
await Docker.printInfo();
|
||||||
})()).resolves.not.toThrow();
|
})()).resolves.not.toThrow();
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ if ! command -v dockerd &> /dev/null; then
|
|||||||
false
|
false
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
mkdir -p "$RUNDIR"
|
||||||
|
|
||||||
(
|
(
|
||||||
echo "Starting dockerd"
|
echo "Starting dockerd"
|
||||||
set -x
|
set -x
|
||||||
@@ -31,21 +33,16 @@ fi
|
|||||||
) &
|
) &
|
||||||
|
|
||||||
tries=60
|
tries=60
|
||||||
echo "Waiting for daemon to start..."
|
|
||||||
while ! docker version &> /dev/null; do
|
while ! docker version &> /dev/null; do
|
||||||
((tries--))
|
((tries--))
|
||||||
if [ $tries -le 0 ]; then
|
if [ $tries -le 0 ]; then
|
||||||
printf "\n"
|
if [ -z "$DOCKER_HOST" ]; then
|
||||||
if [ -z "$DOCKER_HOST" ]; then
|
echo >&2 "error: daemon failed to start"
|
||||||
echo >&2 "error: daemon failed to start"
|
else
|
||||||
echo >&2 " check $RUNDIR/docker.log for details"
|
echo >&2 "error: daemon at $DOCKER_HOST fails to 'docker version':"
|
||||||
else
|
docker version >&2 || true
|
||||||
echo >&2 "error: daemon at $DOCKER_HOST fails to 'docker version':"
|
fi
|
||||||
docker version >&2 || true
|
false
|
||||||
fi
|
fi
|
||||||
false
|
sleep 2
|
||||||
fi
|
|
||||||
printf "."
|
|
||||||
sleep 2
|
|
||||||
done
|
done
|
||||||
printf "\n"
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ param(
|
|||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
[string]$ToolDir,
|
[string]$ToolDir,
|
||||||
|
|
||||||
[Parameter(Mandatory = $false)]
|
[Parameter(Mandatory = $true)]
|
||||||
[string]$TmpDir,
|
[string]$RunDir,
|
||||||
|
|
||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
[string]$DockerHost)
|
[string]$DockerHost)
|
||||||
@@ -12,9 +12,8 @@ param(
|
|||||||
$pwver = (Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine -Name 'PowerShellVersion').PowerShellVersion
|
$pwver = (Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine -Name 'PowerShellVersion').PowerShellVersion
|
||||||
Write-Host "PowerShell version: $pwver"
|
Write-Host "PowerShell version: $pwver"
|
||||||
|
|
||||||
# Create temp directory
|
# Create run directory
|
||||||
if (!$TmpDir) { $TmpDir = $env:TEMP }
|
New-Item -ItemType Directory "$RunDir" -ErrorAction SilentlyContinue | Out-Null
|
||||||
New-Item -ItemType Directory "$TmpDir" -ErrorAction SilentlyContinue | Out-Null
|
|
||||||
|
|
||||||
# Remove existing service
|
# Remove existing service
|
||||||
if (Get-Service docker -ErrorAction SilentlyContinue) {
|
if (Get-Service docker -ErrorAction SilentlyContinue) {
|
||||||
@@ -37,14 +36,14 @@ $env:DOCKER_HOST = $DockerHost
|
|||||||
Write-Host "DOCKER_HOST: $env:DOCKER_HOST"
|
Write-Host "DOCKER_HOST: $env:DOCKER_HOST"
|
||||||
|
|
||||||
Write-Host "Creating service"
|
Write-Host "Creating service"
|
||||||
New-Item -ItemType Directory "$TmpDir\moby-root" -ErrorAction SilentlyContinue | Out-Null
|
New-Item -ItemType Directory "$RunDir\moby-root" -ErrorAction SilentlyContinue | Out-Null
|
||||||
New-Item -ItemType Directory "$TmpDir\moby-exec" -ErrorAction SilentlyContinue | Out-Null
|
New-Item -ItemType Directory "$RunDir\moby-exec" -ErrorAction SilentlyContinue | Out-Null
|
||||||
Start-Process -Wait -NoNewWindow "$ToolDir\dockerd" `
|
Start-Process -Wait -NoNewWindow "$ToolDir\dockerd" `
|
||||||
-ArgumentList `
|
-ArgumentList `
|
||||||
"--host=$DockerHost", `
|
"--host=$DockerHost", `
|
||||||
"--data-root=$TmpDir\moby-root", `
|
"--data-root=$RunDir\moby-root", `
|
||||||
"--exec-root=$TmpDir\moby-exec", `
|
"--exec-root=$RunDir\moby-exec", `
|
||||||
"--pidfile=$TmpDir\docker.pid", `
|
"--pidfile=$RunDir\docker.pid", `
|
||||||
"--register-service"
|
"--register-service"
|
||||||
Write-Host "Starting service"
|
Write-Host "Starting service"
|
||||||
Start-Service -Name docker
|
Start-Service -Name docker
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import * as io from '@actions/io';
|
|||||||
import * as tc from '@actions/tool-cache';
|
import * as tc from '@actions/tool-cache';
|
||||||
|
|
||||||
import * as scripts from '../scripts';
|
import * as scripts from '../scripts';
|
||||||
import {Context} from '../context';
|
|
||||||
import {Exec} from '../exec';
|
import {Exec} from '../exec';
|
||||||
import {Util} from '../util';
|
import {Util} from '../util';
|
||||||
|
|
||||||
@@ -41,7 +40,7 @@ export class Install {
|
|||||||
if (os.platform() == 'win32') {
|
if (os.platform() == 'win32') {
|
||||||
extractFolder = await tc.extractZip(downloadPath);
|
extractFolder = await tc.extractZip(downloadPath);
|
||||||
} else {
|
} else {
|
||||||
extractFolder = await tc.extractTar(downloadPath, path.join(Context.tmpDir(), 'docker'));
|
extractFolder = await tc.extractTar(downloadPath);
|
||||||
}
|
}
|
||||||
if (Util.isDirectory(path.join(extractFolder, 'docker'))) {
|
if (Util.isDirectory(path.join(extractFolder, 'docker'))) {
|
||||||
extractFolder = path.join(extractFolder, 'docker');
|
extractFolder = path.join(extractFolder, 'docker');
|
||||||
@@ -65,7 +64,7 @@ export class Install {
|
|||||||
return tooldir;
|
return tooldir;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async install(toolDir: string, version: string, channel?: string): Promise<void> {
|
public async install(toolDir: string, runDir: string, version: string, channel?: string): Promise<void> {
|
||||||
channel = channel || 'stable';
|
channel = channel || 'stable';
|
||||||
switch (os.platform()) {
|
switch (os.platform()) {
|
||||||
case 'darwin': {
|
case 'darwin': {
|
||||||
@@ -73,11 +72,11 @@ export class Install {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'linux': {
|
case 'linux': {
|
||||||
await this.installLinux(toolDir);
|
await this.installLinux(toolDir, runDir);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'win32': {
|
case 'win32': {
|
||||||
await this.installWindows(toolDir);
|
await this.installWindows(toolDir, runDir);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@@ -87,7 +86,7 @@ export class Install {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async installDarwin(toolDir: string, version: string, channel?: string): Promise<void> {
|
private async installDarwin(toolDir: string, version: string, channel?: string): Promise<void> {
|
||||||
const colimaDir = path.join(os.homedir(), '.colima', 'default');
|
const colimaDir = path.join(os.homedir(), '.colima', 'default'); // TODO: create a custom colima profile to avoid overlap with other actions
|
||||||
await io.mkdirP(colimaDir);
|
await io.mkdirP(colimaDir);
|
||||||
const dockerHost = `unix://${colimaDir}/docker.sock`;
|
const dockerHost = `unix://${colimaDir}/docker.sock`;
|
||||||
|
|
||||||
@@ -130,15 +129,15 @@ export class Install {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async installLinux(toolDir: string): Promise<void> {
|
private async installLinux(toolDir: string, runDir: string): Promise<void> {
|
||||||
const dockerHost = `unix://${path.join(Context.tmpDir(), 'docker.sock')}`;
|
const dockerHost = `unix://${path.join(runDir, 'docker.sock')}`;
|
||||||
|
|
||||||
await core.group('Install Docker daemon', async () => {
|
await core.group('Install Docker daemon', async () => {
|
||||||
const bashPath: string = await io.which('bash', true);
|
const bashPath: string = await io.which('bash', true);
|
||||||
await Exec.exec('sudo', ['-E', bashPath, scripts.setupDockerLinux], {
|
await Exec.exec('sudo', ['-E', bashPath, scripts.setupDockerLinux], {
|
||||||
env: Object.assign({}, process.env, {
|
env: Object.assign({}, process.env, {
|
||||||
TOOLDIR: toolDir,
|
TOOLDIR: toolDir,
|
||||||
RUNDIR: Context.tmpDir(),
|
RUNDIR: runDir,
|
||||||
DOCKER_HOST: dockerHost
|
DOCKER_HOST: dockerHost
|
||||||
}) as {
|
}) as {
|
||||||
[key: string]: string;
|
[key: string]: string;
|
||||||
@@ -152,12 +151,12 @@ export class Install {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async installWindows(toolDir: string): Promise<void> {
|
private async installWindows(toolDir: string, runDir: string): Promise<void> {
|
||||||
const dockerHost = 'npipe:////./pipe/setup_docker_action';
|
const dockerHost = 'npipe:////./pipe/setup_docker_action';
|
||||||
|
|
||||||
const setupCmd = await Util.powershellCommand(scripts.setupDockerWin, {
|
const setupCmd = await Util.powershellCommand(scripts.setupDockerWin, {
|
||||||
ToolDir: toolDir,
|
ToolDir: toolDir,
|
||||||
TmpDir: Context.tmpDir(),
|
RunDir: runDir,
|
||||||
DockerHost: dockerHost
|
DockerHost: dockerHost
|
||||||
});
|
});
|
||||||
await core.group('Install Docker daemon service', async () => {
|
await core.group('Install Docker daemon service', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user