Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display BuildKit version #72

Merged
merged 1 commit into from Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file modified .github/setup-buildx-action.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -243,6 +243,8 @@ jobs:
uses: ./
with:
endpoint: mycontext
env:
DOCKER_CONTEXT: mycontext

config:
runs-on: ubuntu-latest
Expand Down
37 changes: 31 additions & 6 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 21 additions & 3 deletions src/buildx.ts
Expand Up @@ -20,7 +20,7 @@ export type Builder = {

export async function getVersion(): Promise<string> {
return await exec.exec(`docker`, ['buildx', 'version'], true).then(res => {
if (res.stderr != '' && !res.success) {
if (res.stderr.length > 0 && !res.success) {
throw new Error(res.stderr);
}
return parseVersion(res.stdout);
Expand All @@ -37,7 +37,7 @@ export async function parseVersion(stdout: string): Promise<string> {

export async function isAvailable(): Promise<Boolean> {
return await exec.exec(`docker`, ['buildx'], true).then(res => {
if (res.stderr != '' && !res.success) {
if (res.stderr.length > 0 && !res.success) {
return false;
}
return res.success;
Expand All @@ -46,7 +46,7 @@ export async function isAvailable(): Promise<Boolean> {

export async function inspect(name: string): Promise<Builder> {
return await exec.exec(`docker`, ['buildx', 'inspect', name], true).then(res => {
if (res.stderr != '' && !res.success) {
if (res.stderr.length > 0 && !res.success) {
throw new Error(res.stderr);
}
const builder: Builder = {};
Expand Down Expand Up @@ -171,3 +171,21 @@ async function filename(version: string): Promise<string> {
const ext: string = context.osPlat == 'win32' ? '.exe' : '';
return util.format('buildx-v%s.%s-%s%s', version, platform, arch, ext);
}

export async function getBuildKitVersion(containerID: string): Promise<string> {
return exec.exec(`docker`, ['inspect', '--format', '{{.Config.Image}}', containerID], true).then(bkitimage => {
if (bkitimage.success && bkitimage.stdout.length > 0) {
return exec.exec(`docker`, ['run', '--rm', bkitimage.stdout, '--version'], true).then(bkitversion => {
if (bkitversion.success && bkitversion.stdout.length > 0) {
return `${bkitimage.stdout} => ${bkitversion.stdout}`;
} else if (bkitversion.stderr.length > 0) {
core.warning(bkitversion.stderr);
}
return bkitversion.stdout;
});
} else if (bkitimage.stderr.length > 0) {
core.warning(bkitimage.stderr);
}
return bkitimage.stdout;
});
}
7 changes: 5 additions & 2 deletions src/main.ts
Expand Up @@ -81,6 +81,9 @@ async function run(): Promise<void> {

if (inputs.driver == 'docker-container') {
stateHelper.setContainerName(`buildx_buildkit_${builder.node_name}`);
core.startGroup(`BuildKit version`);
core.info(await buildx.getBuildKitVersion(`buildx_buildkit_${builder.node_name}`));
core.endGroup();
}
if (core.isDebug() || builder.node_flags?.includes('--debug')) {
stateHelper.setDebug('true');
Expand All @@ -94,7 +97,7 @@ async function cleanup(): Promise<void> {
if (stateHelper.IsDebug && stateHelper.containerName.length > 0) {
core.startGroup(`BuildKit container logs`);
await mexec.exec('docker', ['logs', `${stateHelper.containerName}`], false).then(res => {
if (res.stderr != '' && !res.success) {
if (res.stderr.length > 0 && !res.success) {
core.warning(res.stderr);
}
});
Expand All @@ -104,7 +107,7 @@ async function cleanup(): Promise<void> {
if (stateHelper.builderName.length > 0) {
core.startGroup(`Removing builder`);
await mexec.exec('docker', ['buildx', 'rm', `${stateHelper.builderName}`], false).then(res => {
if (res.stderr != '' && !res.success) {
if (res.stderr.length > 0 && !res.success) {
core.warning(res.stderr);
}
});
Expand Down