Skip to content

Commit

Permalink
docker/install: Download rootless extras for rootless with archive in…
Browse files Browse the repository at this point in the history
…stall source

Signed-off-by: Paweł Gronowski <[email protected]>
  • Loading branch information
vvoland committed Nov 6, 2024
1 parent d7de9c8 commit 62577a5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
12 changes: 8 additions & 4 deletions __tests__/docker/install.test.itg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down
20 changes: 12 additions & 8 deletions src/docker/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -94,22 +95,21 @@ export class Install {
return this._toolDir || Context.tmpDir();
}

async downloadStaticArchive(src: InstallSourceArchive): Promise<string> {
async downloadStaticArchive(component: 'docker' | 'docker-rootless-extras', src: InstallSourceArchive, extractFolder?: string): Promise<string> {
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');
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 62577a5

Please sign in to comment.