Skip to content

Commit 781874f

Browse files
authored
Merge pull request #486 from vvoland/docker-install-rootless2
docker/install: Fix rootless install, make teardown also cleanup the toolDir
2 parents 37b0f81 + 54e0f74 commit 781874f

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

__tests__/docker/install.test.itg.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {Install, InstallSourceArchive, InstallSourceImage} from '../../src/docke
2323
import {Docker} from '../../src/docker/docker';
2424
import {Exec} from '../../src/exec';
2525

26-
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'docker-install-itg-'));
26+
const tmpDir = () => fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'docker-install-itg-'));
2727

2828
describe('install', () => {
2929
const originalEnv = process.env;
@@ -51,7 +51,7 @@ aarch64:https://cloud.debian.org/images/cloud/bookworm/20231013-1532/debian-12-g
5151
await ensureNoSystemContainerd();
5252
const install = new Install({
5353
source: source,
54-
runDir: tmpDir,
54+
runDir: tmpDir(),
5555
contextName: 'foo',
5656
daemonConfig: `{"debug":true,"features":{"containerd-snapshotter":true}}`
5757
});
@@ -74,7 +74,7 @@ describe('rootless', () => {
7474
await ensureNoSystemContainerd();
7575
const install = new Install({
7676
source: source,
77-
runDir: tmpDir,
77+
runDir: tmpDir(),
7878
contextName: 'foo',
7979
daemonConfig: `{"debug":true}`,
8080
rootless: true

src/docker/install.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ export class Install {
170170
if (this.rootless) {
171171
core.info(`Downloading Docker rootless extras ${version} from ${this.source.channel} at download.docker.com`);
172172
const extrasFolder = await this.downloadStaticArchive('docker-rootless-extras', this.source);
173-
fs.copyFileSync(path.join(extrasFolder, 'dockerd-rootless.sh'), path.join(extractFolder, 'dockerd-rootless.sh'));
173+
fs.readdirSync(extrasFolder).forEach(file => {
174+
const src = path.join(extrasFolder, file);
175+
const dest = path.join(extractFolder, file);
176+
fs.copyFileSync(src, dest);
177+
});
174178
}
175179
break;
176180
}
@@ -492,6 +496,13 @@ EOF`,
492496
throw new Error(`Unsupported platform: ${os.platform()}`);
493497
}
494498
}
499+
500+
await core.group(`Cleaning up toolDir`, async () => {
501+
if (!this._toolDir) {
502+
return;
503+
}
504+
fs.rmSync(this._toolDir, {recursive: true, force: true});
505+
});
495506
}
496507

497508
private async tearDownDarwin(): Promise<void> {
@@ -541,6 +552,9 @@ EOF`,
541552
await core.group('Removing Docker context', async () => {
542553
await Docker.exec(['context', 'rm', '-f', this.contextName]);
543554
});
555+
await core.group('Stopping Docker daemon service', async () => {
556+
await Exec.exec('powershell', ['-Command', `Stop-Service -Name docker -Force`]);
557+
});
544558
}
545559

546560
private downloadURL(component: 'docker' | 'docker-rootless-extras', version: string, channel: string): string {

0 commit comments

Comments
 (0)