Skip to content

Commit 3049a02

Browse files
SukuWcclaude
andcommitted
Inline Docker build into workflow jobs, remove separate build-image job
- mechanical_workflow, electrical_workflow: drop container: block, use background docker container (docker run -d + docker exec) so the image can be built locally on feature branches without pushing to GHCR - firmware_workflow: remove build-image job, pass dockerfile_changed to _firmware_build which now handles build/pull/push inline - On main/master with Dockerfile change: build locally then push :latest to GHCR - On feature branches with Dockerfile change: build locally, use for CI, no push - On any branch without Dockerfile change: pull :latest from GHCR - Delete _build_image.yml (no longer used) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 115a766 commit 3049a02

5 files changed

Lines changed: 99 additions & 106 deletions

File tree

.github/workflows/_build_image.yml

Lines changed: 0 additions & 48 deletions
This file was deleted.

.github/workflows/_firmware_build.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
on:
22
workflow_call:
3+
inputs:
4+
dockerfile_changed:
5+
description: "Whether the firmware Dockerfile was changed"
6+
required: false
7+
type: boolean
8+
default: false
39
outputs:
410
artifact_name:
511
description: "Name of the uploaded nightly artifact"
@@ -18,6 +24,8 @@ on:
1824
jobs:
1925
build:
2026
runs-on: ubuntu-latest
27+
permissions:
28+
packages: write
2129
outputs:
2230
artifact_name: nightly_firmware
2331
release_artifact_name: release_firmware
@@ -36,6 +44,17 @@ jobs:
3644
username: ${{ github.actor }}
3745
password: ${{ secrets.GITHUB_TOKEN }}
3846

47+
- name: Prepare image
48+
run: |
49+
if [ "${{ inputs.dockerfile_changed }}" == "true" ]; then
50+
docker build -t ghcr.io/${{ github.repository_owner }}/knot-firmware-builder:latest -f docker/firmware-builder/Dockerfile .
51+
if [[ "${{ github.ref }}" == "refs/heads/main" || "${{ github.ref }}" == "refs/heads/master" ]]; then
52+
docker push ghcr.io/${{ github.repository_owner }}/knot-firmware-builder:latest
53+
fi
54+
else
55+
docker pull ghcr.io/${{ github.repository_owner }}/knot-firmware-builder:latest
56+
fi
57+
3958
- name: Run script in Docker container
4059
run: docker run -v $PWD:/project -w /project/ ghcr.io/${{ github.repository_owner }}/knot-firmware-builder:latest sh -c "cd Firmware && ./esp_build_firmware.sh"
4160

.github/workflows/electrical_workflow.yml

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,12 @@ jobs:
2121
dockerfile:
2222
- 'docker/electrical-builder/Dockerfile'
2323
24-
build-image:
25-
needs: check-dockerfile
26-
if: (needs.check-dockerfile.outputs.dockerfile-changed == 'true' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')) || github.event_name == 'workflow_dispatch'
27-
uses: ./.github/workflows/_build_image.yml
28-
with:
29-
image_name: knot-electrical-builder
30-
dockerfile: docker/electrical-builder/Dockerfile
31-
secrets: inherit
32-
3324
generate-artifacts:
34-
needs: build-image
35-
if: always() && needs.build-image.result != 'failure'
25+
needs: check-dockerfile
3626
name: kicad export
3727
runs-on: ubuntu-latest
38-
container:
39-
image: ghcr.io/${{ github.repository_owner }}/knot-electrical-builder:latest
40-
credentials:
41-
username: ${{ github.actor }}
42-
password: ${{ secrets.GITHUB_TOKEN }}
28+
permissions:
29+
packages: write
4330
strategy:
4431
fail-fast: false
4532
matrix:
@@ -49,12 +36,39 @@ jobs:
4936
steps:
5037
- uses: actions/checkout@v2
5138

52-
- name: Run PCB stuff
39+
- name: Log in to GitHub Container Registry
40+
uses: docker/login-action@v3
41+
with:
42+
registry: ghcr.io
43+
username: ${{ github.actor }}
44+
password: ${{ secrets.GITHUB_TOKEN }}
45+
46+
- name: Prepare image
5347
run: |
54-
make -C Electrical/Design/${{ matrix.board }}
48+
if [ "${{ needs.check-dockerfile.outputs.dockerfile-changed }}" == "true" ]; then
49+
docker build -t builder:local -f docker/electrical-builder/Dockerfile .
50+
if [[ "${{ github.ref }}" == "refs/heads/main" || "${{ github.ref }}" == "refs/heads/master" ]]; then
51+
docker tag builder:local ghcr.io/${{ github.repository_owner }}/knot-electrical-builder:latest
52+
docker push ghcr.io/${{ github.repository_owner }}/knot-electrical-builder:latest
53+
fi
54+
else
55+
docker pull ghcr.io/${{ github.repository_owner }}/knot-electrical-builder:latest
56+
docker tag ghcr.io/${{ github.repository_owner }}/knot-electrical-builder:latest builder:local
57+
fi
58+
docker run -d --name builder \
59+
-v ${{ github.workspace }}:/work \
60+
-w /work \
61+
builder:local tail -f /dev/null
62+
63+
- name: Run PCB stuff
64+
run: docker exec builder bash -c "make -C /work/Electrical/Design/${{ matrix.board }}"
65+
66+
- name: Stop container
67+
if: always()
68+
run: docker rm -f builder
5569

5670
- name: Print errors
57-
if: ${{ always() }}
71+
if: always()
5872
run: |
5973
cat Electrical/Design/${{ matrix.board }}/mfg-bot/${{ matrix.board }}-drc.html
6074
cat Electrical/Design/${{ matrix.board }}/kibot_error.log
@@ -86,7 +100,7 @@ jobs:
86100
rm -r Electrical/Design/${{ matrix.board }}/mfg-bot/JLCPCB
87101
88102
- name: Upload results
89-
if: ${{ always() }}
103+
if: always()
90104
uses: actions/upload-artifact@v4
91105
with:
92106
name: "result_${{ matrix.board }}_${{ env.action_date }}"

.github/workflows/firmware_workflow.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,13 @@ jobs:
2020
dockerfile:
2121
- 'docker/firmware-builder/Dockerfile'
2222
23-
build-image:
23+
build:
2424
needs: check-dockerfile
25-
if: (needs.check-dockerfile.outputs.dockerfile-changed == 'true' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')) || github.event_name == 'workflow_dispatch'
26-
uses: ./.github/workflows/_build_image.yml
25+
uses: ./.github/workflows/_firmware_build.yml
2726
with:
28-
image_name: knot-firmware-builder
29-
dockerfile: docker/firmware-builder/Dockerfile
27+
dockerfile_changed: ${{ needs.check-dockerfile.outputs.dockerfile-changed == 'true' }}
3028
secrets: inherit
3129

32-
build:
33-
needs: build-image
34-
if: always() && needs.build-image.result != 'failure'
35-
uses: ./.github/workflows/_firmware_build.yml
36-
3730
publish-production:
3831
needs: build
3932
if: always() && needs.build.result == 'success' && needs.build.outputs.release_version != ''

.github/workflows/mechanical_workflow.yml

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,12 @@ jobs:
2222
dockerfile:
2323
- 'docker/mechanical-builder/Dockerfile'
2424
25-
build-image:
26-
needs: check-dockerfile
27-
if: (needs.check-dockerfile.outputs.dockerfile-changed == 'true' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')) || github.event_name == 'workflow_dispatch'
28-
uses: ./.github/workflows/_build_image.yml
29-
with:
30-
image_name: knot-mechanical-builder
31-
dockerfile: docker/mechanical-builder/Dockerfile
32-
secrets: inherit
33-
3425
generate-artifacts:
35-
needs: build-image
36-
if: always() && needs.build-image.result != 'failure'
26+
needs: check-dockerfile
3727
name: freecad export
3828
runs-on: ubuntu-latest
39-
container:
40-
image: ghcr.io/${{ github.repository_owner }}/knot-mechanical-builder:latest
41-
credentials:
42-
username: ${{ github.actor }}
43-
password: ${{ secrets.GITHUB_TOKEN }}
29+
permissions:
30+
packages: write
4431
strategy:
4532
fail-fast: false
4633
matrix:
@@ -53,32 +40,60 @@ jobs:
5340
- name: Checkout code
5441
uses: actions/checkout@v4
5542

43+
- name: Log in to GitHub Container Registry
44+
uses: docker/login-action@v3
45+
with:
46+
registry: ghcr.io
47+
username: ${{ github.actor }}
48+
password: ${{ secrets.GITHUB_TOKEN }}
49+
50+
- name: Prepare image
51+
run: |
52+
if [ "${{ needs.check-dockerfile.outputs.dockerfile-changed }}" == "true" ]; then
53+
docker build -t builder:local -f docker/mechanical-builder/Dockerfile .
54+
if [[ "${{ github.ref }}" == "refs/heads/main" || "${{ github.ref }}" == "refs/heads/master" ]]; then
55+
docker tag builder:local ghcr.io/${{ github.repository_owner }}/knot-mechanical-builder:latest
56+
docker push ghcr.io/${{ github.repository_owner }}/knot-mechanical-builder:latest
57+
fi
58+
else
59+
docker pull ghcr.io/${{ github.repository_owner }}/knot-mechanical-builder:latest
60+
docker tag ghcr.io/${{ github.repository_owner }}/knot-mechanical-builder:latest builder:local
61+
fi
62+
docker run -d --name builder \
63+
-v ${{ github.workspace }}:/work \
64+
-w /work \
65+
builder:local tail -f /dev/null
66+
5667
- name: Start virtual display
5768
run: |
58-
Xvfb :99 -screen 0 1920x1080x24 > /dev/null 2>&1 &
59-
until xdpyinfo -display :99 > /dev/null 2>&1; do sleep 0.5; done
60-
x11vnc -display :99 -nopw -listen localhost -xkb -ncache 10 -ncache_cr -forever > /dev/null 2>&1 &
69+
docker exec builder bash -c "
70+
Xvfb :99 -screen 0 1920x1080x24 > /dev/null 2>&1 &
71+
until xdpyinfo -display :99 > /dev/null 2>&1; do sleep 0.5; done
72+
x11vnc -display :99 -nopw -listen localhost -xkb -ncache 10 -ncache_cr -forever > /dev/null 2>&1 &
73+
"
6174
6275
- name: Run GUI application
6376
continue-on-error: true
6477
run: |
65-
ls
66-
export DISPLAY=:99
67-
freecad --hidden ./Mechanical/Design/${{ matrix.component }}/${{ matrix.component }}.FCStd ./.github/workflows/freecad_export.py step pdf || true
78+
docker exec -e DISPLAY=:99 builder bash -c "
79+
freecad --hidden /work/Mechanical/Design/${{ matrix.component }}/${{ matrix.component }}.FCStd /work/.github/workflows/freecad_export.py step pdf || true
80+
"
6881
6982
- name: Convert STEP to STL
70-
run: /opt/conda/envs/occenv/bin/python ./.github/workflows/pythonocc_step_to_stl.py
83+
run: docker exec builder /opt/conda/envs/occenv/bin/python /work/.github/workflows/pythonocc_step_to_stl.py
7184

7285
- name: Generate Preview PNG
73-
run: |
74-
./.github/workflows/openscad_preview.sh
86+
run: docker exec builder bash -c "/work/.github/workflows/openscad_preview.sh"
7587

7688
- name: Copy reference files
7789
run: |
78-
find Mechanical/Design/${{ matrix.component }}/ -maxdepth 1 -name "${{ matrix.component }}*" ! -name "*.FCStd" ! -name "*.FCBak" -exec cp {} temp/ \; || true
90+
docker exec builder bash -c "
91+
find /work/Mechanical/Design/${{ matrix.component }}/ -maxdepth 1 -name '${{ matrix.component }}*' ! -name '*.FCStd' ! -name '*.FCBak' -exec cp {} /work/temp/ \; || true
92+
"
7993
80-
- name: Stop x11vnc
81-
run: pkill x11vnc
94+
- name: Stop container
95+
if: always()
96+
run: docker rm -f builder
8297

8398
- name: Set Date
8499
run: echo "action_date=$(date +'%Y-%m-%d-%H%M')" >> $GITHUB_ENV

0 commit comments

Comments
 (0)