From 2e61dc31802f4762622bb68849d8b8c6d87dfebe Mon Sep 17 00:00:00 2001 From: Hamel Husain Date: Fri, 22 Dec 2023 06:37:20 -0800 Subject: [PATCH] Add tests to Docker (#993) --- .github/workflows/main.yml | 21 +++++++++++++++++---- docker/Dockerfile | 3 +++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bdab96ac2..3eb97e55d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -38,27 +38,40 @@ jobs: uses: docker/metadata-action@v5 with: images: winglian/axolotl + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - name: Login to Docker Hub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Build + # guidance for testing before pushing: https://docs.docker.com/build/ci/github-actions/test-before-push/ + - name: Build and export to Docker uses: docker/build-push-action@v5 with: context: . + load: true build-args: | BASE_TAG=${{ github.ref_name }}-base-py${{ matrix.python_version }}-cu${{ matrix.cuda }}-${{ matrix.pytorch }} CUDA=${{ matrix.cuda }} PYTORCH_VERSION=${{ matrix.pytorch }} file: ./docker/Dockerfile - push: ${{ github.event_name != 'pull_request' }} tags: | ${{ steps.metadata.outputs.tags }}-py${{ matrix.python_version }}-cu${{ matrix.cuda }}-${{ matrix.pytorch }}${{ matrix.axolotl_extras != '' && '-' || '' }}${{ matrix.axolotl_extras }} ${{ (matrix.is_latest) && format('{0}-latest', steps.metadata.outputs.tags) || '' }} labels: ${{ steps.metadata.outputs.labels }} + - name: Unit Tests + run: | + docker run --rm ${{ steps.metadata.outputs.tags }}-py${{ matrix.python_version }}-cu${{ matrix.cuda }}-${{ matrix.pytorch }}${{ matrix.axolotl_extras != '' && '-' || '' }}${{ matrix.axolotl_extras }} pytest --ignore=tests/e2e/ /workspace/axolotl/tests/ + - name: Push to Docker Hub + if: github.event_name != 'pull_request' + run: | + docker push ${{ steps.metadata.outputs.tags }}-py${{ matrix.python_version }}-cu${{ matrix.cuda }}-${{ matrix.pytorch }}${{ matrix.axolotl_extras != '' && '-' || '' }}${{ matrix.axolotl_extras }} + latest_tag=${{ (matrix.is_latest) && format('{0}-latest', steps.metadata.outputs.tags) || '' }} + if [ -n "$latest_tag" ]; then + docker push "$latest_tag" + fi + build-axolotl-runpod: needs: build-axolotl if: github.repository_owner == 'OpenAccess-AI-Collective' diff --git a/docker/Dockerfile b/docker/Dockerfile index 81a08bc8b..f8e052856 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -25,6 +25,9 @@ RUN if [ "$AXOLOTL_EXTRAS" != "" ] ; then \ pip install -e .[deepspeed,flash-attn]; \ fi +# So we can test the Docker image +RUN pip install pytest + # fix so that git fetch/pull from remote works RUN git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" && \ git config --get remote.origin.fetch