Skip to content

Commit

Permalink
buildx: make it easier to download precompiled binaries from other repos
Browse files Browse the repository at this point in the history
After this change, callers can pass a release URL of the form:
https://github.com/docker/buildx/releases/tag/v0.11.1
and get the release binaries from the the github api.

Signed-off-by: Nick Santos <[email protected]>
  • Loading branch information
nicks committed Jul 12, 2023
1 parent f1593e3 commit cc39d3c
Show file tree
Hide file tree
Showing 5 changed files with 597 additions and 19 deletions.
29 changes: 23 additions & 6 deletions __tests__/buildx/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,27 @@ import osm = require('os');

import {Install} from '../../src/buildx/install';

import release_0_9_0 = require('./release-v0.9.0.json');

// prettier-ignore
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-jest');
let octokit;

beforeEach(() => {
jest.clearAllMocks();
octokit = {
rest: {
repos: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getReleaseByTag: jest.fn().mockImplementation((args: any) => {
if (args.tag == 'v0.9.0') {
return {data: release_0_9_0};
}
throw new Error(`Unknown release: ${args.tag}`);
})
}
}
};
});

afterEach(function () {
Expand All @@ -38,10 +54,11 @@ describe('download', () => {
test.each([
['v0.9.0', false],
['v0.10.5', true],
['latest', true]
['latest', true],
['https://github.com/docker/buildx/releases/tag/v0.9.0', true],
])(
'acquires %p of buildx (standalone: %p)', async (version, standalone) => {
const install = new Install({standalone: standalone});
const install = new Install({octokit, standalone: standalone});
const toolPath = await install.download(version);
expect(fs.existsSync(toolPath)).toBe(true);
let buildxBin: string;
Expand All @@ -62,7 +79,7 @@ describe('download', () => {
['v0.10.5'],
])(
'acquires %p of buildx with cache', async (version) => {
const install = new Install({standalone: false});
const install = new Install({octokit, standalone: false});
const toolPath = await install.download(version);
expect(fs.existsSync(toolPath)).toBe(true);
});
Expand All @@ -82,7 +99,7 @@ describe('download', () => {
'acquires buildx for %s/%s', async (os, arch) => {
jest.spyOn(osm, 'platform').mockImplementation(() => os as NodeJS.Platform);
jest.spyOn(osm, 'arch').mockImplementation(() => arch);
const install = new Install();
const install = new Install({octokit});
const buildxBin = await install.download('latest');
expect(fs.existsSync(buildxBin)).toBe(true);
},
Expand All @@ -99,7 +116,7 @@ describe('download', () => {
describe('build', () => {
// eslint-disable-next-line jest/no-disabled-tests
it.skip('builds refs/pull/648/head', async () => {
const install = new Install();
const install = new Install({octokit});
const toolPath = await install.build('https://github.com/docker/buildx.git#refs/pull/648/head');
expect(fs.existsSync(toolPath)).toBe(true);
const buildxBin = await install.installStandalone(toolPath, tmpDir);
Expand All @@ -108,7 +125,7 @@ describe('build', () => {

// eslint-disable-next-line jest/no-disabled-tests
it.skip('builds 67bd6f4dc82a9cd96f34133dab3f6f7af803bb14', async () => {
const install = new Install();
const install = new Install({octokit});
const toolPath = await install.build('https://github.com/docker/buildx.git#67bd6f4dc82a9cd96f34133dab3f6f7af803bb14');
expect(fs.existsSync(toolPath)).toBe(true);
const buildxBin = await install.installPlugin(toolPath, tmpDir);
Expand Down
Loading

0 comments on commit cc39d3c

Please sign in to comment.