From 62577a560090972075fa74dd1e9c65809210fb7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Wed, 6 Nov 2024 17:27:52 +0100 Subject: [PATCH] docker/install: Download rootless extras for rootless with archive install source MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paweł Gronowski --- __tests__/docker/install.test.itg.ts | 12 ++++++++---- src/docker/install.ts | 20 ++++++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/__tests__/docker/install.test.itg.ts b/__tests__/docker/install.test.itg.ts index 9938bea7..1bf98169 100644 --- a/__tests__/docker/install.test.itg.ts +++ b/__tests__/docker/install.test.itg.ts @@ -60,16 +60,20 @@ aarch64:https://cloud.debian.org/images/cloud/bookworm/20231013-1532/debian-12-g }); describe('rootless', () => { - test( - 'install', - async () => { + // prettier-ignore + test.each([ + {type: 'image', tag: 'latest'} as InstallSourceImage, + {type: 'archive', version: 'latest', channel: 'stable'} as InstallSourceArchive, + ])( + 'install %s', async (source) => { // Skip on non linux if (os.platform() !== 'linux') { return; } + await ensureNoSystemContainerd(); const install = new Install({ - source: {type: 'image', tag: 'latest'}, + source: source, runDir: tmpDir, contextName: 'foo', daemonConfig: `{"debug":true}`, diff --git a/src/docker/install.ts b/src/docker/install.ts index 1600c18d..665b58e1 100644 --- a/src/docker/install.ts +++ b/src/docker/install.ts @@ -35,6 +35,7 @@ import {limaYamlData, dockerServiceLogsPs1, setupDockerWinPs1} from './assets'; import {GitHubRelease} from '../types/github'; import {HubRepository} from '../hubRepository'; import {Image} from '../types/oci/config'; +import {extract} from "tar-stream"; export interface InstallSourceImage { type: 'image'; @@ -94,22 +95,21 @@ export class Install { return this._toolDir || Context.tmpDir(); } - async downloadStaticArchive(src: InstallSourceArchive): Promise { + async downloadStaticArchive(component: 'docker' | 'docker-rootless-extras', src: InstallSourceArchive, extractFolder?: string): Promise { const release: GitHubRelease = await Install.getRelease(src.version); this._version = release.tag_name.replace(/^v+|v+$/g, ''); core.debug(`docker.Install.download version: ${this._version}`); - const downloadURL = this.downloadURL(this._version, src.channel); + const downloadURL = this.downloadURL(component, this._version, src.channel); core.info(`Downloading ${downloadURL}`); const downloadPath = await tc.downloadTool(downloadURL); core.debug(`docker.Install.download downloadPath: ${downloadPath}`); - let extractFolder: string; if (os.platform() == 'win32') { - extractFolder = await tc.extractZip(downloadPath); + extractFolder = await tc.extractZip(downloadPath, extractFolder); } else { - extractFolder = await tc.extractTar(downloadPath); + extractFolder = await tc.extractTar(downloadPath, extractFolder); } if (Util.isDirectory(path.join(extractFolder, 'docker'))) { extractFolder = path.join(extractFolder, 'docker'); @@ -167,7 +167,11 @@ export class Install { this._version = version; core.info(`Downloading Docker ${version} from ${this.source.channel} at download.docker.com`); - extractFolder = await this.downloadStaticArchive(this.source); + extractFolder = await this.downloadStaticArchive('docker', this.source); + if (this.rootless) { + core.info(`Downloading Docker rootless extras ${version} from ${this.source.channel} at download.docker.com`); + extractFolder = await this.downloadStaticArchive('docker-rootless-extras', this.source, extractFolder); + } break; } } @@ -539,11 +543,11 @@ EOF`, }); } - private downloadURL(version: string, channel: string): string { + private downloadURL(component: 'docker' | 'docker-rootless-extras', version: string, channel: string): string { const platformOS = Install.platformOS(); const platformArch = Install.platformArch(); const ext = platformOS === 'win' ? '.zip' : '.tgz'; - return util.format('https://download.docker.com/%s/static/%s/%s/docker-%s%s', platformOS, channel, platformArch, version, ext); + return `https://download.docker.com/${platformOS}/${channel}/${platformArch}/${component}-${version}${ext}`; } private static platformOS(): string {