Skip to content

Commit

Permalink
Merge pull request #70 from crazy-max/debug-buildkitd
Browse files Browse the repository at this point in the history
BuildKit container logs
  • Loading branch information
crazy-max authored Apr 23, 2021
2 parents 0f03438 + 5b1c96a commit 316c3e4
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 15 deletions.
Binary file added .github/buildkit-container-logs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOL
FROM alpine
RUN uname -a
EOL
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
uses: ./
with:
buildkitd-flags: --debug
-
name: Build
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64,linux/arm64,linux/ppc64le

install:
runs-on: ubuntu-latest
steps:
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ ___
* [inputs](#inputs)
* [outputs](#outputs)
* [environment variables](#environment-variables)
* [Notes](#notes)
* [BuildKit container logs](#buildkit-container-logs)
* [Keep up-to-date with GitHub Dependabot](#keep-up-to-date-with-github-dependabot)
* [Limitation](#limitation)

Expand Down Expand Up @@ -164,6 +166,25 @@ The following [official docker environment variables](https://docs.docker.com/en
|-----------------|---------|-------------|-------------------------------------------------|
| `DOCKER_CONFIG` | String | `~/.docker` | The location of your client configuration files |

## Notes

### BuildKit container logs

To display BuildKit container logs (when `docker-container` driver is used) you have to [enable step debug logging](https://docs.github.com/en/actions/managing-workflow-runs/enabling-debug-logging#enabling-step-debug-logging)
or you can also enable debugging in the [setup-buildx action step](https://github.com/docker/setup-buildx-action):

```yaml
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
buildkitd-flags: --debug
```

Logs will be available at the end of a job:

![BuildKit container logs](.github/buildkit-container-logs.png)

## Keep up-to-date with GitHub Dependabot

Since [Dependabot](https://docs.github.com/en/github/administering-a-repository/keeping-your-actions-up-to-date-with-github-dependabot)
Expand Down
43 changes: 35 additions & 8 deletions dist/index.js

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

32 changes: 25 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,38 @@ async function run(): Promise<void> {
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<void> {
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) {
Expand Down
10 changes: 10 additions & 0 deletions src/state-helper.ts
Original file line number Diff line number Diff line change
@@ -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');
}

0 comments on commit 316c3e4

Please sign in to comment.