|
| 1 | +name: Docker |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + pull_request: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + paths: |
| 10 | + - Dockerfile |
| 11 | + - .github/workflows/docker.yaml |
| 12 | + workflow_dispatch: {} |
| 13 | +jobs: |
| 14 | + docker-build: |
| 15 | + runs-on: mosaic-8wide |
| 16 | + if: github.repository_owner == 'mosaicml' |
| 17 | + strategy: |
| 18 | + matrix: |
| 19 | + include: |
| 20 | + - name: "2.1.2_cu121" |
| 21 | + base_image: mosaicml/pytorch:2.1.2_cu121-python3.10-ubuntu20.04 |
| 22 | + dep_groups: "[all]" |
| 23 | + - name: "2.1.2_cu121_aws" |
| 24 | + base_image: mosaicml/pytorch:2.1.2_cu121-python3.10-ubuntu20.04-aws |
| 25 | + dep_groups: "[all]" |
| 26 | + - name: "2.4.0_cu124" |
| 27 | + base_image: mosaicml/pytorch:2.4.0_cu124-python3.11-ubuntu20.04 |
| 28 | + dep_groups: "[all]" |
| 29 | + - name: "2.4.0_cu124_aws" |
| 30 | + base_image: mosaicml/pytorch:2.4.0_cu124-python3.11-ubuntu20.04-aws |
| 31 | + dep_groups: "[all]" |
| 32 | + steps: |
| 33 | + |
| 34 | + - name: Checkout |
| 35 | + uses: actions/checkout@v3 |
| 36 | + |
| 37 | + - name: Setup QEMU |
| 38 | + uses: docker/setup-qemu-action@v2 |
| 39 | + |
| 40 | + - name: Setup Docker Buildx |
| 41 | + uses: docker/setup-buildx-action@v2 |
| 42 | + |
| 43 | + - name: Login to DockerHub |
| 44 | + uses: docker/login-action@v2 |
| 45 | + with: |
| 46 | + username: ${{ secrets.DOCKER_HUB_USERNAME }} |
| 47 | + password: ${{ secrets.DOCKER_HUB_PASSWORD }} |
| 48 | + |
| 49 | + - name: Calculate Docker Image Variables |
| 50 | + run: | |
| 51 | + set -euxo pipefail |
| 52 | +
|
| 53 | + ################### |
| 54 | + # Calculate the tag |
| 55 | + ################### |
| 56 | + GIT_SHA=$(echo ${{ github.sha }} | cut -c1-7) |
| 57 | + echo "IMAGE_TAG=${GIT_SHA}" >> ${GITHUB_ENV} |
| 58 | +
|
| 59 | + if [ "${{ github.event_name }}" == "pull_request" ]; then |
| 60 | + echo "Triggered by pull_request event." |
| 61 | + STAGING_REPO="mosaicml/ci-staging" |
| 62 | + IMAGE_TAG="${STAGING_REPO}:${{matrix.name}}-${GIT_SHA}" |
| 63 | + IMAGE_CACHE="${STAGING_REPO}:${{matrix.name}}-buildcache" |
| 64 | + else |
| 65 | + # Triggered by push or workflow_dispatch event |
| 66 | + echo "Triggered by ${{ github.event_name }} event, releasing to prod" |
| 67 | + PROD_REPO="mosaicml/diffusion" |
| 68 | + IMAGE_TAG="${PROD_REPO}:${{matrix.name}}-${GIT_SHA},${PROD_REPO}:${{matrix.name}}-latest" |
| 69 | + IMAGE_CACHE="${PROD_REPO}:${{matrix.name}}-buildcache" |
| 70 | + fi |
| 71 | +
|
| 72 | + echo "IMAGE_TAG=${IMAGE_TAG}" >> ${GITHUB_ENV} |
| 73 | + echo "IMAGE_CACHE=${IMAGE_CACHE}" >> ${GITHUB_ENV} |
| 74 | +
|
| 75 | + - name: Build and Push the Docker Image |
| 76 | + uses: docker/build-push-action@v3 |
| 77 | + with: |
| 78 | + context: . |
| 79 | + tags: ${{ env.IMAGE_TAG }} |
| 80 | + push: true |
| 81 | + cache-from: type=registry,ref=${{ env.IMAGE_CACHE }} |
| 82 | + cache-to: type=registry,ref=${{ env.IMAGE_CACHE }},mode=max |
| 83 | + build-args: | |
| 84 | + BRANCH_NAME=${{ github.head_ref || github.ref_name }} |
| 85 | + BASE_IMAGE=${{ matrix.base_image }} |
| 86 | + DEP_GROUPS=${{ matrix.dep_groups }} |
0 commit comments