Skip to content

Commit 009e79d

Browse files
authored
Fix Dockerfile and test docker build in PRs (espressif#216)
* Use requirements.txt in Dockerfile * Test docker build in PRs * Optimize push workflow for PRs * Optimize docker workflow * Improve name
1 parent 33d9253 commit 009e79d

File tree

3 files changed

+47
-11
lines changed

3 files changed

+47
-11
lines changed

.github/workflows/docker.yml

+29-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ on:
77
- 'release/*'
88
tags:
99
- 'v*.*'
10+
pull_request:
11+
paths:
12+
- ".github/workflows/docker.yml"
13+
- "tools/config_editor/requirements.txt"
14+
- "tools/docker/Dockerfile"
15+
- "tools/docker/entrypoint.sh"
1016

1117
env:
1218
# Build the image for amd64 and arm64
@@ -16,8 +22,8 @@ env:
1622
jobs:
1723
docker:
1824
# Disable the job in forks
19-
if: ${{ github.repository_owner == 'espressif' }}
20-
25+
if: ${{ github.event_name == 'pull_request' || github.repository_owner == 'espressif' }}
26+
name: Build docker image and push if needed
2127
runs-on: ubuntu-latest
2228
steps:
2329
# Depending on the branch/tag, set CLONE_BRANCH_OR_TAG variable (used in the Dockerfile
@@ -29,50 +35,65 @@ jobs:
2935
run: |
3036
echo "CLONE_BRANCH_OR_TAG=$GITHUB_REF_NAME" >> $GITHUB_ENV
3137
echo "TAG_NAME=$GITHUB_REF_NAME" >> $GITHUB_ENV
38+
echo "URL=${{ github.server_url }}/${{ github.repository }}.git" >> $GITHUB_ENV
39+
3240
- name: Set variables (release branches)
3341
if: ${{ github.ref_type == 'branch' && startsWith(github.ref_name, 'release/') }}
3442
run: |
3543
echo "CLONE_BRANCH_OR_TAG=$GITHUB_REF_NAME" >> $GITHUB_ENV
3644
echo "TAG_NAME=release-${GITHUB_REF_NAME##release/}" >> $GITHUB_ENV
45+
echo "URL=${{ github.server_url }}/${{ github.repository }}.git" >> $GITHUB_ENV
46+
3747
- name: Set variables (main branch)
3848
if: ${{ github.ref_type == 'branch' && github.ref_name == 'master' }}
3949
run: |
4050
echo "CLONE_BRANCH_OR_TAG=master" >> $GITHUB_ENV
4151
echo "TAG_NAME=latest" >> $GITHUB_ENV
52+
echo "URL=${{ github.server_url }}/${{ github.repository }}.git" >> $GITHUB_ENV
53+
54+
- name: Set variables (pull requests)
55+
if: ${{ github.event_name == 'pull_request' }}
56+
run: |
57+
echo "CLONE_BRANCH_OR_TAG=${{ github.event.pull_request.head.ref }}" >> $GITHUB_ENV
58+
echo "TAG_NAME=PR_${{ github.event.number }}" >> $GITHUB_ENV
59+
echo "URL=${{ github.server_url }}/${{ github.event.pull_request.head.repo.full_name }}.git" >> $GITHUB_ENV
4260
4361
# Display the variables set above, just in case.
4462
- name: Check variables
4563
run: |
4664
echo "CLONE_BRANCH_OR_TAG: $CLONE_BRANCH_OR_TAG"
47-
echo "CHECKOUT_REF: $CHECKOUT_REF"
4865
echo "TAG_NAME: $TAG_NAME"
66+
echo "URL: $URL"
4967
50-
# The following steps are the standard boilerplate from
51-
# https://github.com/marketplace/actions/build-and-push-docker-images
5268
- name: Checkout
5369
uses: actions/checkout@v4
70+
5471
- name: Login to Docker Hub
72+
if: ${{ github.event_name == 'push' }}
5573
uses: docker/login-action@v3
5674
with:
5775
username: ${{ secrets.DOCKERHUB_USERNAME }}
5876
password: ${{ secrets.DOCKERHUB_TOKEN }}
77+
5978
- name: Set up QEMU for multiarch builds
6079
uses: docker/setup-qemu-action@v3
80+
6181
- name: Set up Docker Buildx
6282
uses: docker/setup-buildx-action@v3
83+
6384
- name: Build and push
6485
uses: docker/build-push-action@v5
6586
with:
6687
context: tools/docker
67-
push: true
88+
push: ${{ github.event_name == 'push' }}
6889
tags: ${{ env.DOCKERHUB_REPO }}:${{ env.TAG_NAME }}
6990
platforms: ${{ env.BUILD_PLATFORMS }}
7091
build-args: |
71-
LIBBUILDER_CLONE_URL=${{ github.server_url }}/${{ github.repository }}.git
92+
LIBBUILDER_CLONE_URL=${{ env.URL }}
7293
LIBBUILDER_CLONE_BRANCH_OR_TAG=${{ env.CLONE_BRANCH_OR_TAG }}
7394
7495
- name: Update Docker Hub repository description (master branch)
75-
if: ${{ github.ref_type == 'branch' && github.ref_name == 'master' }}
96+
if: ${{ github.event_name == 'push' && github.ref_type == 'branch' && github.ref_name == 'master' }}
7697
uses: peter-evans/dockerhub-description@v4
7798
with:
7899
username: ${{ secrets.DOCKERHUB_USERNAME }}

.github/workflows/push.yml

+16-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@ on:
55
branches:
66
- master
77
pull_request:
8+
paths:
9+
- "**"
10+
- "!**.md"
11+
- "!.github/workflows/cron_build.yml"
12+
- "!.github/workflows/cron.yml"
13+
- "!.github/workflows/docker.yml"
14+
- "!.github/workflows/repository_dispatch.yml"
15+
- "!tools/config_editor/**"
16+
- "!tools/docker/**"
817

918
concurrency:
1019
group: esp-idf-libs-${{github.event.pull_request.number || github.ref}}
1120
cancel-in-progress: true
1221

1322
jobs:
14-
1523
build-libs:
1624
name: Build Libs for ${{ matrix.target }}
1725
runs-on: ubuntu-latest
@@ -21,16 +29,20 @@ jobs:
2129
fail-fast: false
2230
steps:
2331
- uses: actions/checkout@v4
32+
2433
- name: Install dependencies
2534
run: bash ./tools/prepare-ci.sh
35+
2636
- name: Build Libs for ${{ matrix.target }}
2737
run: bash ./build.sh -e -t ${{ matrix.target }}
38+
2839
- name: Upload build
2940
if: failure()
3041
uses: actions/upload-artifact@v4
3142
with:
3243
name: build-${{ matrix.target }}
3344
path: build
45+
3446
- name: Upload archive
3547
uses: actions/upload-artifact@v4
3648
with:
@@ -48,17 +60,20 @@ jobs:
4860
path: dist
4961
pattern: artifacts-*
5062
merge-multiple: true
63+
5164
- shell: bash
5265
run: |
5366
mkdir -p out
5467
find dist -name 'arduino-esp32-libs-esp*.tar.gz' -exec tar zxvf {} -C out \;
5568
cd out/tools/esp32-arduino-libs && tar zcf ../../../dist/esp32-arduino-libs.tar.gz * && cd ../../..
5669
cp out/package_esp32_index.template.json dist/package_esp32_index.template.json
70+
5771
- name: Upload full esp32-arduino-libs archive
5872
uses: actions/upload-artifact@v4
5973
with:
6074
name: esp32-arduino-libs
6175
path: dist/esp32-arduino-libs.tar.gz
76+
6277
- name: Upload package_esp32_index.template.json
6378
uses: actions/upload-artifact@v4
6479
with:

tools/docker/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ RUN : \
3434
python3-setuptools \
3535
python3-venv \
3636
wget \
37-
&& pip3 install --upgrade pip textual-dev \
3837
&& apt-get autoremove -y \
3938
&& rm -rf /var/lib/apt/lists/* \
4039
&& :
@@ -70,7 +69,8 @@ RUN echo LIBBUILDER_CHECKOUT_REF=$LIBBUILDER_CHECKOUT_REF LIBBUILDER_CLONE_BRANC
7069
fi && \
7170
git checkout $LIBBUILDER_CHECKOUT_REF && \
7271
git submodule update --init --recursive; \
73-
fi
72+
fi && \
73+
pip3 install --upgrade -r $LIBBUILDER_PATH/tools/config_editor/requirements.txt
7474

7575
COPY entrypoint.sh $LIBBUILDER_PATH/entrypoint.sh
7676

0 commit comments

Comments
 (0)