diff --git a/.github/buildkit-container-logs.png b/.github/buildkit-container-logs.png new file mode 100644 index 00000000..e2cf1ead Binary files /dev/null and b/.github/buildkit-container-logs.png differ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9c757487..7b73e742 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,6 +77,34 @@ jobs: echo "Flags: ${{ steps.buildx2.outputs.flags }}" echo "Platforms: ${{ steps.buildx2.outputs.platforms }}" + debug: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v2 + - + name: Create Dockerfile + run: | + cat > ./Dockerfile < 0) { + core.startGroup(`BuildKit container logs`); + yield mexec.exec('docker', ['logs', `${stateHelper.containerName}`], false).then(res => { + if (res.stderr != '' && !res.success) { + core.warning(res.stderr); + } + }); + core.endGroup(); + } + if (stateHelper.builderName.length > 0) { + core.startGroup(`Removing builder`); + yield mexec.exec('docker', ['buildx', 'rm', `${stateHelper.builderName}`], false).then(res => { + if (res.stderr != '' && !res.success) { + core.warning(res.stderr); + } + }); + core.endGroup(); } - yield mexec.exec('docker', ['buildx', 'rm', `${stateHelper.builderName}`], false).then(res => { - if (res.stderr != '' && !res.success) { - core.warning(res.stderr); - } - }); }); } if (!stateHelper.IsPost) { @@ -5623,14 +5640,24 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.setBuilderName = exports.builderName = exports.IsPost = void 0; +exports.setContainerName = exports.setBuilderName = exports.setDebug = exports.containerName = exports.builderName = exports.IsDebug = exports.IsPost = void 0; const core = __importStar(__webpack_require__(186)); exports.IsPost = !!process.env['STATE_isPost']; +exports.IsDebug = !!process.env['STATE_isDebug']; exports.builderName = process.env['STATE_builderName'] || ''; +exports.containerName = process.env['STATE_containerName'] || ''; +function setDebug(debug) { + core.saveState('isDebug', debug); +} +exports.setDebug = setDebug; function setBuilderName(builderName) { core.saveState('builderName', builderName); } exports.setBuilderName = setBuilderName; +function setContainerName(containerName) { + core.saveState('containerName', containerName); +} +exports.setContainerName = setContainerName; if (!exports.IsPost) { core.saveState('isPost', 'true'); } diff --git a/src/main.ts b/src/main.ts index 5a1e2b90..87540fd9 100644 --- a/src/main.ts +++ b/src/main.ts @@ -78,20 +78,38 @@ async function run(): Promise { context.setOutput('flags', builder.node_flags); context.setOutput('platforms', builder.node_platforms); core.endGroup(); + + if (inputs.driver == 'docker-container') { + stateHelper.setContainerName(`buildx_buildkit_${builder.node_name}`); + } + if (core.isDebug() || builder.node_flags?.includes('--debug')) { + stateHelper.setDebug('true'); + } } catch (error) { core.setFailed(error.message); } } async function cleanup(): Promise { - if (stateHelper.builderName.length == 0) { - return; + 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) { + core.warning(res.stderr); + } + }); + core.endGroup(); + } + + 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) { + core.warning(res.stderr); + } + }); + core.endGroup(); } - await mexec.exec('docker', ['buildx', 'rm', `${stateHelper.builderName}`], false).then(res => { - if (res.stderr != '' && !res.success) { - core.warning(res.stderr); - } - }); } if (!stateHelper.IsPost) { diff --git a/src/state-helper.ts b/src/state-helper.ts index 6e675eaf..bbdd05b6 100644 --- a/src/state-helper.ts +++ b/src/state-helper.ts @@ -1,12 +1,22 @@ import * as core from '@actions/core'; export const IsPost = !!process.env['STATE_isPost']; +export const IsDebug = !!process.env['STATE_isDebug']; export const builderName = process.env['STATE_builderName'] || ''; +export const containerName = process.env['STATE_containerName'] || ''; + +export function setDebug(debug: string) { + core.saveState('isDebug', debug); +} export function setBuilderName(builderName: string) { core.saveState('builderName', builderName); } +export function setContainerName(containerName: string) { + core.saveState('containerName', containerName); +} + if (!IsPost) { core.saveState('isPost', 'true'); }