Docker Image Build and Push #272
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Docker Image Build and Push | |
| on: | |
| schedule: | |
| - cron: "0 0 */7 * *" # every 7 days | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - "Dockerfile" | |
| - ".github/workflows/docker_build.yml" | |
| pull_request: | |
| branches: | |
| - main | |
| paths: | |
| - "Dockerfile" | |
| - ".github/workflows/docker_build.yml" | |
| types: [opened, synchronize, reopened, ready_for_review] | |
| #workflow_dispatch: # Add this line to enable manual trigger | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Free Disk Space (Ubuntu) | |
| uses: jlumbroso/free-disk-space@main | |
| with: | |
| tool-cache: false | |
| android: true | |
| dotnet: true | |
| haskell: true | |
| large-packages: true | |
| docker-images: false | |
| swap-storage: true | |
| - name: Checkout | |
| uses: actions/checkout@v5.0.0 | |
| - name: Set up Buildx | |
| uses: docker/setup-buildx-action@v3.11.1 | |
| # ----- PR and non-main branch steps ----- | |
| # For PRs: Build image but do not push and run smoke tests | |
| - name: Build Docker Image (No Push) | |
| if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref != 'refs/heads/main') | |
| uses: docker/build-push-action@v6.18.0 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: false | |
| load: true | |
| tags: arc:test | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Run Smoke Tests | |
| if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref != 'refs/heads/main') | |
| run: | | |
| docker run --rm arc:test bash -lc \ | |
| "cd /home/mambauser/Code/ARC && micromamba run -n arc_env pytest dockerfiles/docker_tests/test_docker_smoke.py -m smoke -q" | |
| # ----- Main branch only steps ----- | |
| # For pushes to main: Build, run smoke tests, and push to Docker Hub | |
| - name: Build test stage (main) | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| uses: docker/build-push-action@v6.18.0 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| load: true | |
| tags: arc:final-${{ github.sha }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Run smoke (main, test stage) | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| run: | | |
| docker run --rm arc:final-${{ github.sha }} bash -lc \ | |
| "cd /home/mambauser/Code/ARC && micromamba run -n arc_env pytest dockerfiles/docker_tests/test_docker_smoke.py -m smoke -q" | |
| - name: Login to Docker Hub | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| uses: docker/login-action@v3.5.0 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build final and push (main) | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| uses: docker/build-push-action@v6.18.0 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| tags: | | |
| ${{ secrets.DOCKERHUB_USERNAME }}/arc:latest | |
| ${{ secrets.DOCKERHUB_USERNAME }}/arc:${{ github.sha }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |