mirror of
https://github.com/docker/build-push-action.git
synced 2024-11-15 16:13:51 +08:00
Add name output to identify builder instance name
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
b72149bbe7
commit
0cc5e42c7a
27
.github/workflows/setup-buildx-ci.yml
vendored
27
.github/workflows/setup-buildx-ci.yml
vendored
@ -40,6 +40,9 @@ jobs:
|
||||
uses: ./setup-buildx/
|
||||
with:
|
||||
buildx-version: ${{ matrix.buildx-version }}
|
||||
-
|
||||
name: Builder instance name
|
||||
run: echo ${{ steps.buildx.outputs.name }}
|
||||
-
|
||||
name: Available platforms
|
||||
run: echo ${{ steps.buildx.outputs.platforms }}
|
||||
@ -47,6 +50,27 @@ jobs:
|
||||
name: Dump context
|
||||
uses: crazy-max/ghaction-dump-context@v1
|
||||
|
||||
multi:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v2.3.1
|
||||
-
|
||||
name: Set up Docker Buildx 1
|
||||
id: buildx1
|
||||
uses: ./setup-buildx/
|
||||
-
|
||||
name: Builder 1 instance name
|
||||
run: echo ${{ steps.buildx1.outputs.name }}
|
||||
-
|
||||
name: Set up Docker Buildx 2
|
||||
id: buildx2
|
||||
uses: ./setup-buildx/
|
||||
-
|
||||
name: Builder 2 instance name
|
||||
run: echo ${{ steps.buildx2.outputs.name }}
|
||||
|
||||
install:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
@ -135,3 +159,6 @@ jobs:
|
||||
-
|
||||
name: Available platforms
|
||||
run: echo ${{ steps.buildx.outputs.platforms }}
|
||||
-
|
||||
name: Builder instance name
|
||||
run: echo ${{ steps.buildx.outputs.name }}
|
||||
|
@ -77,6 +77,9 @@ jobs:
|
||||
uses: docker/actions/setup-buildx@v1
|
||||
with:
|
||||
buildx-version: latest
|
||||
-
|
||||
name: Builder instance name
|
||||
run: echo ${{ steps.buildx.outputs.name }}
|
||||
-
|
||||
name: Available platforms
|
||||
run: echo ${{ steps.buildx.outputs.platforms }}
|
||||
@ -102,6 +105,7 @@ Following outputs are available
|
||||
|
||||
| Name | Type | Description |
|
||||
|---------------|---------|---------------------------------------|
|
||||
| `name` | String | Builder instance name |
|
||||
| `platforms` | String | Available platforms (comma separated) |
|
||||
|
||||
### environment variables
|
||||
|
@ -8,7 +8,13 @@ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'setup-buildx-'));
|
||||
describe('buildx', () => {
|
||||
it('is available', async () => {
|
||||
expect(await buildx.isAvailable()).toBe(true);
|
||||
}, 100000);
|
||||
});
|
||||
|
||||
it('count builders', async () => {
|
||||
const countBuilders = await buildx.countBuilders();
|
||||
console.log(`countBuilders: ${countBuilders}`);
|
||||
expect(countBuilders).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('acquires v0.2.2 version of buildx', async () => {
|
||||
const buildxBin = await buildx.install('v0.2.2', tmpDir);
|
||||
|
@ -27,6 +27,8 @@ inputs:
|
||||
required: false
|
||||
|
||||
outputs:
|
||||
name:
|
||||
description: 'Builder instance name'
|
||||
platforms:
|
||||
description: 'Available platforms (comma separated)'
|
||||
|
||||
|
27
setup-buildx/dist/index.js
generated
vendored
27
setup-buildx/dist/index.js
generated
vendored
@ -2501,15 +2501,11 @@ function run() {
|
||||
}
|
||||
core.info('📣 Buildx info');
|
||||
yield exec.exec('docker', ['buildx', 'version'], false);
|
||||
const builderName = `builder-${(yield buildx.countBuilders()) + 1}-${process.env.GITHUB_JOB}`;
|
||||
core.saveState('builderName', builderName);
|
||||
core.setOutput('name', builderName);
|
||||
core.info('🔨 Creating a new builder instance...');
|
||||
let createArgs = [
|
||||
'buildx',
|
||||
'create',
|
||||
'--name',
|
||||
`builder-${process.env.GITHUB_SHA}`,
|
||||
'--driver',
|
||||
driver
|
||||
];
|
||||
let createArgs = ['buildx', 'create', '--name', builderName, '--driver', driver];
|
||||
if (driverOpt) {
|
||||
createArgs.push('--driver-opt', driverOpt);
|
||||
}
|
||||
@ -2547,7 +2543,7 @@ function cleanup() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
core.info('🚿 Removing builder instance...');
|
||||
yield exec.exec('docker', ['buildx', 'rm', `builder-${process.env.GITHUB_SHA}`], false);
|
||||
yield exec.exec('docker', ['buildx', 'rm', `${process.env.STATE_builderName}`], false);
|
||||
}
|
||||
catch (error) {
|
||||
core.warning(error.message);
|
||||
@ -7243,7 +7239,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.install = exports.isAvailable = void 0;
|
||||
exports.install = exports.countBuilders = exports.isAvailable = void 0;
|
||||
const fs = __importStar(__webpack_require__(747));
|
||||
const os = __importStar(__webpack_require__(87));
|
||||
const path = __importStar(__webpack_require__(622));
|
||||
@ -7265,6 +7261,17 @@ function isAvailable() {
|
||||
});
|
||||
}
|
||||
exports.isAvailable = isAvailable;
|
||||
function countBuilders() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return yield exec.exec(`docker`, ['buildx', 'ls'], true).then(res => {
|
||||
if (res.stderr != '' && !res.success) {
|
||||
throw new Error(`Cannot list builders: ${res.stderr}`);
|
||||
}
|
||||
return (res.stdout.trim().split(`\n`).length - 1) / 2;
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.countBuilders = countBuilders;
|
||||
function install(inputVersion, dockerConfigHome) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const release = yield github.getRelease(inputVersion);
|
||||
|
@ -19,6 +19,15 @@ export async function isAvailable(): Promise<Boolean> {
|
||||
});
|
||||
}
|
||||
|
||||
export async function countBuilders(): Promise<number> {
|
||||
return await exec.exec(`docker`, ['buildx', 'ls'], true).then(res => {
|
||||
if (res.stderr != '' && !res.success) {
|
||||
throw new Error(`Cannot list builders: ${res.stderr}`);
|
||||
}
|
||||
return (res.stdout.trim().split(`\n`).length - 1) / 2;
|
||||
});
|
||||
}
|
||||
|
||||
export async function install(inputVersion: string, dockerConfigHome: string): Promise<string> {
|
||||
const release: github.GitHubRelease | null = await github.getRelease(inputVersion);
|
||||
if (!release) {
|
||||
|
@ -27,15 +27,12 @@ async function run(): Promise<void> {
|
||||
core.info('📣 Buildx info');
|
||||
await exec.exec('docker', ['buildx', 'version'], false);
|
||||
|
||||
const builderName: string = `builder-${(await buildx.countBuilders()) + 1}-${process.env.GITHUB_JOB}`;
|
||||
core.saveState('builderName', builderName);
|
||||
core.setOutput('name', builderName);
|
||||
|
||||
core.info('🔨 Creating a new builder instance...');
|
||||
let createArgs: Array<string> = [
|
||||
'buildx',
|
||||
'create',
|
||||
'--name',
|
||||
`builder-${process.env.GITHUB_SHA}`,
|
||||
'--driver',
|
||||
driver
|
||||
];
|
||||
let createArgs: Array<string> = ['buildx', 'create', '--name', builderName, '--driver', driver];
|
||||
if (driverOpt) {
|
||||
createArgs.push('--driver-opt', driverOpt);
|
||||
}
|
||||
@ -76,7 +73,7 @@ async function run(): Promise<void> {
|
||||
async function cleanup(): Promise<void> {
|
||||
try {
|
||||
core.info('🚿 Removing builder instance...');
|
||||
await exec.exec('docker', ['buildx', 'rm', `builder-${process.env.GITHUB_SHA}`], false);
|
||||
await exec.exec('docker', ['buildx', 'rm', `${process.env.STATE_builderName}`], false);
|
||||
} catch (error) {
|
||||
core.warning(error.message);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user