Add test-docker-build workflow (#109)

Adds a `test-docker-build.yml` workflow to ensure that docker images can correctly build when their Dockerfile has been modified on PRs.
This commit is contained in:
Simon Alibert 2024-04-27 09:40:21 +02:00 committed by GitHub
parent fdf6a0c4e3
commit fe2b9af64f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 109 additions and 2 deletions

109
.github/workflows/test-docker-build.yml vendored Normal file
View File

@ -0,0 +1,109 @@
# Inspired by
# https://github.com/huggingface/peft/blob/main/.github/workflows/test-docker-build.yml
name: Test Docker builds (PR)
on:
pull_request:
branches:
- main
paths:
# Run only when DockerFile files are modified
- "docker/**"
env:
PYTHON_VERSION: "3.10"
jobs:
get_changed_files:
name: "Get all modified Dockerfiles"
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
with:
files: docker/**
json: "true"
- name: Run step if only the files listed above change
if: steps.changed-files.outputs.any_changed == 'true'
id: set-matrix
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
echo "matrix=${{ steps.changed-files.outputs.all_changed_files}}" >> $GITHUB_OUTPUT
build_modified_dockerfiles:
name: "Build all modified Docker images"
needs: get_changed_files
runs-on: ubuntu-latest
if: ${{ needs.get_changed_files.outputs.matrix }} != ''
strategy:
fail-fast: false
matrix:
docker-file: ${{ fromJson(needs.get_changed_files.outputs.matrix) }}
steps:
- name: Cleanup disk
run: |
sudo df -h
# sudo ls -l /usr/local/lib/
# sudo ls -l /usr/share/
sudo du -sh /usr/local/lib/
sudo du -sh /usr/share/
sudo rm -rf /usr/local/lib/android
sudo rm -rf /usr/share/dotnet
sudo du -sh /usr/local/lib/
sudo du -sh /usr/share/
sudo df -h
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Check out code
uses: actions/checkout@v4
# HACK(aliberts): to be removed for release
# -----------------------------------------
- name: Checkout gym-aloha
uses: actions/checkout@v4
with:
repository: huggingface/gym-aloha
path: envs/gym-aloha
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Checkout gym-xarm
uses: actions/checkout@v4
with:
repository: huggingface/gym-xarm
path: envs/gym-xarm
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Checkout gym-pusht
uses: actions/checkout@v4
with:
repository: huggingface/gym-pusht
path: envs/gym-pusht
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Change envs dependencies as local path
run: python .github/scripts/dep_build.py
# -----------------------------------------
- name: Build Docker image
uses: docker/build-push-action@v5
with:
file: ${{ matrix.docker-file }}
context: .
push: False
build-args: PYTHON_VERSION=${{ env.PYTHON_VERSION }}

View File

@ -4,7 +4,6 @@ FROM nvidia/cuda:12.4.1-base-ubuntu22.04
ARG PYTHON_VERSION=3.10 ARG PYTHON_VERSION=3.10
ARG DEBIAN_FRONTEND=noninteractive ARG DEBIAN_FRONTEND=noninteractive
# Install apt dependencies # Install apt dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \ RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential cmake \ build-essential cmake \
@ -12,7 +11,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
python${PYTHON_VERSION} python${PYTHON_VERSION}-venv \ python${PYTHON_VERSION} python${PYTHON_VERSION}-venv \
&& apt-get clean && rm -rf /var/lib/apt/lists/* && apt-get clean && rm -rf /var/lib/apt/lists/*
# Create virtual environment # Create virtual environment
RUN ln -s /usr/bin/python${PYTHON_VERSION} /usr/bin/python RUN ln -s /usr/bin/python${PYTHON_VERSION} /usr/bin/python
RUN python -m venv /opt/venv RUN python -m venv /opt/venv