Skip to content

Commit 6acffcd

Browse files
authored
Adding docker images for diffusion repo (#174)
1 parent c1f953f commit 6acffcd

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

.github/workflows/docker.yaml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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 }}

.github/workflows/pytest-cpu.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,4 @@ jobs:
6262
with:
6363
name: coverage-${{ github.sha }}-${{ inputs.name }}
6464
path: .coverage
65+
include-hidden-files: true

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2022 MosaicML Diffusion authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
ARG BASE_IMAGE
5+
FROM $BASE_IMAGE
6+
7+
ARG BRANCH_NAME
8+
ARG DEP_GROUPS
9+
10+
ENV TORCH_CUDA_ARCH_LIST="8.0 8.6 8.7 8.9 9.0"
11+
12+
# Check for changes in setup.py.
13+
# If there are changes, the docker cache is invalidated and a fresh pip installation is triggered.
14+
ADD https://raw.githubusercontent.com/mosaicml/diffusion/$BRANCH_NAME/setup.py setup.py
15+
RUN rm setup.py
16+
17+
# Install and uninstall diffusion to cache diffusion requirements
18+
RUN git clone -b $BRANCH_NAME https://github.com/mosaicml/diffusion.git
19+
RUN pip install --no-cache-dir "./diffusion${DEP_GROUPS}"
20+
RUN pip uninstall -y diffusion
21+
RUN rm -rf diffusion

0 commit comments

Comments
 (0)