From 5dd8e04d4b5ff57dde63a6cb080f936fdfb56a96 Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Mon, 11 Mar 2024 08:54:00 +0530 Subject: [PATCH] [Dockerfiles] add: a workflow to check if docker containers can be built in case of modifications (#7129) * add: a workflow to check if docker containers can be built if the files are modified. * type * unify docker image build test and push * make it run on prs too. * check * check * check * check again. * remove docker test build file. * remove extra dependencies./ * check --- .github/workflows/build_docker_images.yml | 44 ++++++++++++++++++++--- docker/diffusers-pytorch-cpu/Dockerfile | 2 +- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build_docker_images.yml b/.github/workflows/build_docker_images.yml index aacbd6f095..3d061f88c2 100644 --- a/.github/workflows/build_docker_images.yml +++ b/.github/workflows/build_docker_images.yml @@ -1,22 +1,58 @@ -name: Build Docker images (nightly) +name: Test, build, and push Docker images on: + pull_request: # During PRs, we just check if the changes Dockerfiles can be successfully built + branches: + - main + paths: + - "docker/**" workflow_dispatch: schedule: - cron: "0 0 * * *" # every day at midnight concurrency: - group: docker-image-builds - cancel-in-progress: false + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true env: REGISTRY: diffusers CI_SLACK_CHANNEL: ${{ secrets.CI_DOCKER_CHANNEL }} jobs: - build-docker-images: + test-build-docker-images: runs-on: ubuntu-latest + if: github.event_name == 'pull_request' + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Check out code + uses: actions/checkout@v3 + + - name: Find Changed Dockerfiles + id: file_changes + uses: jitterbit/get-changed-files@v1 + with: + format: 'space-delimited' + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Build Changed Docker Images + run: | + CHANGED_FILES="${{ steps.file_changes.outputs.all }}" + for FILE in $CHANGED_FILES; do + if [[ "$FILE" == docker/*Dockerfile ]]; then + DOCKER_PATH="${FILE%/Dockerfile}" + DOCKER_TAG=$(basename "$DOCKER_PATH") + echo "Building Docker image for $DOCKER_TAG" + docker build -t "$DOCKER_TAG" "$DOCKER_PATH" + fi + done + if: steps.file_changes.outputs.all != '' + build-and-push-docker-images: + runs-on: ubuntu-latest + if: github.event_name != 'pull_request' + permissions: contents: read packages: write diff --git a/docker/diffusers-pytorch-cpu/Dockerfile b/docker/diffusers-pytorch-cpu/Dockerfile index 288559bcfc..213662fa2f 100644 --- a/docker/diffusers-pytorch-cpu/Dockerfile +++ b/docker/diffusers-pytorch-cpu/Dockerfile @@ -40,6 +40,6 @@ RUN python3 -m pip install --no-cache-dir --upgrade pip uv==0.1.11 && \ numpy \ scipy \ tensorboard \ - transformers + transformers matplotlib CMD ["/bin/bash"]