Skip to content

Commit 316c3e4

Browse files
authored
Merge pull request #70 from crazy-max/debug-buildkitd
BuildKit container logs
2 parents 0f03438 + 5b1c96a commit 316c3e4

File tree

6 files changed

+119
-15
lines changed

6 files changed

+119
-15
lines changed

.github/buildkit-container-logs.png

12.7 KB
Loading

.github/workflows/ci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,34 @@ jobs:
7777
echo "Flags: ${{ steps.buildx2.outputs.flags }}"
7878
echo "Platforms: ${{ steps.buildx2.outputs.platforms }}"
7979
80+
debug:
81+
runs-on: ubuntu-latest
82+
steps:
83+
-
84+
name: Checkout
85+
uses: actions/checkout@v2
86+
-
87+
name: Create Dockerfile
88+
run: |
89+
cat > ./Dockerfile <<EOL
90+
FROM alpine
91+
RUN uname -a
92+
EOL
93+
-
94+
name: Set up QEMU
95+
uses: docker/setup-qemu-action@v1
96+
-
97+
name: Set up Docker Buildx
98+
uses: ./
99+
with:
100+
buildkitd-flags: --debug
101+
-
102+
name: Build
103+
uses: docker/build-push-action@v2
104+
with:
105+
context: .
106+
platforms: linux/amd64,linux/arm64,linux/ppc64le
107+
80108
install:
81109
runs-on: ubuntu-latest
82110
steps:

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ ___
2525
* [inputs](#inputs)
2626
* [outputs](#outputs)
2727
* [environment variables](#environment-variables)
28+
* [Notes](#notes)
29+
* [BuildKit container logs](#buildkit-container-logs)
2830
* [Keep up-to-date with GitHub Dependabot](#keep-up-to-date-with-github-dependabot)
2931
* [Limitation](#limitation)
3032

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

169+
## Notes
170+
171+
### BuildKit container logs
172+
173+
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)
174+
or you can also enable debugging in the [setup-buildx action step](https://github.com/docker/setup-buildx-action):
175+
176+
```yaml
177+
-
178+
name: Set up Docker Buildx
179+
uses: docker/setup-buildx-action@v1
180+
with:
181+
buildkitd-flags: --debug
182+
```
183+
184+
Logs will be available at the end of a job:
185+
186+
![BuildKit container logs](.github/buildkit-container-logs.png)
187+
167188
## Keep up-to-date with GitHub Dependabot
168189

169190
Since [Dependabot](https://docs.github.com/en/github/administering-a-repository/keeping-your-actions-up-to-date-with-github-dependabot)

dist/index.js

Lines changed: 35 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,38 @@ async function run(): Promise<void> {
7878
context.setOutput('flags', builder.node_flags);
7979
context.setOutput('platforms', builder.node_platforms);
8080
core.endGroup();
81+
82+
if (inputs.driver == 'docker-container') {
83+
stateHelper.setContainerName(`buildx_buildkit_${builder.node_name}`);
84+
}
85+
if (core.isDebug() || builder.node_flags?.includes('--debug')) {
86+
stateHelper.setDebug('true');
87+
}
8188
} catch (error) {
8289
core.setFailed(error.message);
8390
}
8491
}
8592

8693
async function cleanup(): Promise<void> {
87-
if (stateHelper.builderName.length == 0) {
88-
return;
94+
if (stateHelper.IsDebug && stateHelper.containerName.length > 0) {
95+
core.startGroup(`BuildKit container logs`);
96+
await mexec.exec('docker', ['logs', `${stateHelper.containerName}`], false).then(res => {
97+
if (res.stderr != '' && !res.success) {
98+
core.warning(res.stderr);
99+
}
100+
});
101+
core.endGroup();
102+
}
103+
104+
if (stateHelper.builderName.length > 0) {
105+
core.startGroup(`Removing builder`);
106+
await mexec.exec('docker', ['buildx', 'rm', `${stateHelper.builderName}`], false).then(res => {
107+
if (res.stderr != '' && !res.success) {
108+
core.warning(res.stderr);
109+
}
110+
});
111+
core.endGroup();
89112
}
90-
await mexec.exec('docker', ['buildx', 'rm', `${stateHelper.builderName}`], false).then(res => {
91-
if (res.stderr != '' && !res.success) {
92-
core.warning(res.stderr);
93-
}
94-
});
95113
}
96114

97115
if (!stateHelper.IsPost) {

src/state-helper.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
import * as core from '@actions/core';
22

33
export const IsPost = !!process.env['STATE_isPost'];
4+
export const IsDebug = !!process.env['STATE_isDebug'];
45
export const builderName = process.env['STATE_builderName'] || '';
6+
export const containerName = process.env['STATE_containerName'] || '';
7+
8+
export function setDebug(debug: string) {
9+
core.saveState('isDebug', debug);
10+
}
511

612
export function setBuilderName(builderName: string) {
713
core.saveState('builderName', builderName);
814
}
915

16+
export function setContainerName(containerName: string) {
17+
core.saveState('containerName', containerName);
18+
}
19+
1020
if (!IsPost) {
1121
core.saveState('isPost', 'true');
1222
}

0 commit comments

Comments
 (0)