Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Dockerfile and test docker build in PRs #216

Merged
merged 5 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ on:
- 'release/*'
tags:
- 'v*.*'
pull_request:
paths:
- ".github/workflows/docker.yml"
- "tools/config_editor/requirements.txt"
- "tools/docker/Dockerfile"
- "tools/docker/entrypoint.sh"

env:
# Build the image for amd64 and arm64
Expand All @@ -16,8 +22,8 @@ env:
jobs:
docker:
# Disable the job in forks
if: ${{ github.repository_owner == 'espressif' }}

if: ${{ github.event_name == 'pull_request' || github.repository_owner == 'espressif' }}
name: Build docker image and push if needed
runs-on: ubuntu-latest
steps:
# Depending on the branch/tag, set CLONE_BRANCH_OR_TAG variable (used in the Dockerfile
Expand All @@ -29,50 +35,65 @@ jobs:
run: |
echo "CLONE_BRANCH_OR_TAG=$GITHUB_REF_NAME" >> $GITHUB_ENV
echo "TAG_NAME=$GITHUB_REF_NAME" >> $GITHUB_ENV
echo "URL=${{ github.server_url }}/${{ github.repository }}.git" >> $GITHUB_ENV

- name: Set variables (release branches)
if: ${{ github.ref_type == 'branch' && startsWith(github.ref_name, 'release/') }}
run: |
echo "CLONE_BRANCH_OR_TAG=$GITHUB_REF_NAME" >> $GITHUB_ENV
echo "TAG_NAME=release-${GITHUB_REF_NAME##release/}" >> $GITHUB_ENV
echo "URL=${{ github.server_url }}/${{ github.repository }}.git" >> $GITHUB_ENV

- name: Set variables (main branch)
if: ${{ github.ref_type == 'branch' && github.ref_name == 'master' }}
run: |
echo "CLONE_BRANCH_OR_TAG=master" >> $GITHUB_ENV
echo "TAG_NAME=latest" >> $GITHUB_ENV
echo "URL=${{ github.server_url }}/${{ github.repository }}.git" >> $GITHUB_ENV

- name: Set variables (pull requests)
if: ${{ github.event_name == 'pull_request' }}
run: |
echo "CLONE_BRANCH_OR_TAG=${{ github.event.pull_request.head.ref }}" >> $GITHUB_ENV
echo "TAG_NAME=PR_${{ github.event.number }}" >> $GITHUB_ENV
echo "URL=${{ github.server_url }}/${{ github.event.pull_request.head.repo.full_name }}.git" >> $GITHUB_ENV

# Display the variables set above, just in case.
- name: Check variables
run: |
echo "CLONE_BRANCH_OR_TAG: $CLONE_BRANCH_OR_TAG"
echo "CHECKOUT_REF: $CHECKOUT_REF"
echo "TAG_NAME: $TAG_NAME"
echo "URL: $URL"

# The following steps are the standard boilerplate from
# https://github.com/marketplace/actions/build-and-push-docker-images
- name: Checkout
uses: actions/checkout@v4

- name: Login to Docker Hub
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set up QEMU for multiarch builds
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push
uses: docker/build-push-action@v5
with:
context: tools/docker
push: true
push: ${{ github.event_name == 'push' }}
tags: ${{ env.DOCKERHUB_REPO }}:${{ env.TAG_NAME }}
platforms: ${{ env.BUILD_PLATFORMS }}
build-args: |
LIBBUILDER_CLONE_URL=${{ github.server_url }}/${{ github.repository }}.git
LIBBUILDER_CLONE_URL=${{ env.URL }}
LIBBUILDER_CLONE_BRANCH_OR_TAG=${{ env.CLONE_BRANCH_OR_TAG }}

- name: Update Docker Hub repository description (master branch)
if: ${{ github.ref_type == 'branch' && github.ref_name == 'master' }}
if: ${{ github.event_name == 'push' && github.ref_type == 'branch' && github.ref_name == 'master' }}
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
Expand Down
17 changes: 16 additions & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ on:
branches:
- master
pull_request:
paths:
- "**"
- "!**.md"
- "!.github/workflows/cron_build.yml"
- "!.github/workflows/cron.yml"
- "!.github/workflows/docker.yml"
- "!.github/workflows/repository_dispatch.yml"
- "!tools/config_editor/**"
- "!tools/docker/**"

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

jobs:

build-libs:
name: Build Libs for ${{ matrix.target }}
runs-on: ubuntu-latest
Expand All @@ -21,16 +29,20 @@ jobs:
fail-fast: false
steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: bash ./tools/prepare-ci.sh

- name: Build Libs for ${{ matrix.target }}
run: bash ./build.sh -e -t ${{ matrix.target }}

- name: Upload build
if: failure()
uses: actions/upload-artifact@v4
with:
name: build-${{ matrix.target }}
path: build

- name: Upload archive
uses: actions/upload-artifact@v4
with:
Expand All @@ -48,17 +60,20 @@ jobs:
path: dist
pattern: artifacts-*
merge-multiple: true

- shell: bash
run: |
mkdir -p out
find dist -name 'arduino-esp32-libs-esp*.tar.gz' -exec tar zxvf {} -C out \;
cd out/tools/esp32-arduino-libs && tar zcf ../../../dist/esp32-arduino-libs.tar.gz * && cd ../../..
cp out/package_esp32_index.template.json dist/package_esp32_index.template.json

- name: Upload full esp32-arduino-libs archive
uses: actions/upload-artifact@v4
with:
name: esp32-arduino-libs
path: dist/esp32-arduino-libs.tar.gz

- name: Upload package_esp32_index.template.json
uses: actions/upload-artifact@v4
with:
Expand Down
4 changes: 2 additions & 2 deletions tools/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ RUN : \
python3-setuptools \
python3-venv \
wget \
&& pip3 install --upgrade pip textual-dev \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/* \
&& :
Expand Down Expand Up @@ -70,7 +69,8 @@ RUN echo LIBBUILDER_CHECKOUT_REF=$LIBBUILDER_CHECKOUT_REF LIBBUILDER_CLONE_BRANC
fi && \
git checkout $LIBBUILDER_CHECKOUT_REF && \
git submodule update --init --recursive; \
fi
fi && \
pip3 install --upgrade -r $LIBBUILDER_PATH/tools/config_editor/requirements.txt

COPY entrypoint.sh $LIBBUILDER_PATH/entrypoint.sh

Expand Down