ci: Add workflow to build official docker images with multiarch (#83437)

Resolves https://github.com/pytorch/pytorch/issues/80764

Signed-off-by: Eli Uriegas <seemethere101@gmail.com>
Pull Request resolved: https://github.com/pytorch/pytorch/pull/83437
Approved by: https://github.com/ZainRizvi, https://github.com/malfet
This commit is contained in:
Eli Uriegas
2022-08-16 13:07:16 -07:00
committed by PyTorch MergeBot
parent 3a511e8354
commit 1b437718a3
3 changed files with 140 additions and 18 deletions

89
.github/workflows/docker-release.yml vendored Normal file
View File

@ -0,0 +1,89 @@
name: Build Official Docker Images
on:
workflow_dispatch:
pull_request:
paths:
- Dockerfile
- docker.Makefile
push:
branches:
- nightly
tags:
# Release candidate tags look like: v1.11.0-rc1
- v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+
- ciflow/nightly/*
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }}
cancel-in-progress: true
env:
BUILD_PROGRESS: plain
BUILD_TYPE: official
DOCKER_ORG: pytorch
DOCKER_REGISTRY: ghcr.io
NO_BUILD_SUFFIX: true
USE_BUILDX: 1
WITH_PUSH: ${{ github.event_name == 'push' && (github.event.ref == 'refs/heads/nightly' || (startsWith(github.event.ref, 'refs/tags/') && !startsWith(github.event.ref, 'refs/tags/ciflow/'))) }}
jobs:
build:
if: ${{ github.repository == 'pytorch/pytorch' }}
runs-on: [self-hosted, linux.2xlarge]
timeout-minutes: 240
strategy:
matrix:
include:
# nvidia specific images don't exist for arm64 so only build the runtime image
- image_type: runtime
platform: linux/arm64,linux/amd64
- image_type: devel
platform: linux/amd64
env:
BUILD_IMAGE_TYPE: ${{ matrix.image_type }}
BUILD_PLATFORMS: ${{ matrix.platform }}
steps:
# [see note: pytorch repo ref]
# deep clone (fetch-depth 0) required for git merge-base
- name: Checkout PyTorch
uses: pytorch/pytorch/.github/actions/checkout-pytorch@master
- name: Setup Linux
uses: ./.github/actions/setup-linux
- name: Setup SSH (Click me for login details)
uses: ./.github/actions/setup-ssh
with:
github-secret: ${{ secrets.GITHUB_TOKEN }}
- name: Login to GitHub Container Registry
if: ${{ env.WITH_PUSH == 'true' }}
uses: docker/login-action@v2
with:
registry: ghcr.io
username: pytorch
password: ${{ secrets.GHCR_PAT }}
# Setup multi-arch image builds
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
env:
QEMU_BINARY_PATH: ${{ runner.temp }}/bin
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Setup job specific variables
run: |
set -eou pipefail
# To get QEMU binaries in our PATh
echo "${RUNNER_TEMP}/bin" >> "${GITHUB_PATH}"
# Generate PyTorch version to use
echo "PYTORCH_VERSION=$(python3 .github/scripts/generate_pytorch_version.py)" >> "${GITHUB_ENV}"
- name: Setup nightly specific variables
if: ${{ github.event.ref == 'refs/heads/nightly' }}
run: |
# Use nightly image if building for nightly
echo "DOCKER_IMAGE=pytorch-nightly" >> "${GITHUB_ENV}"
- name: Run docker build / push
# WITH_PUSH is used here to determine whether or not to add the --push flag
run: |
make -f docker.Makefile "${BUILD_IMAGE_TYPE}-image"
- name: Teardown Linux
uses: ./.github/actions/teardown-linux
if: always()

View File

@ -11,8 +11,7 @@ ARG BASE_IMAGE=ubuntu:18.04
ARG PYTHON_VERSION=3.8 ARG PYTHON_VERSION=3.8
FROM ${BASE_IMAGE} as dev-base FROM ${BASE_IMAGE} as dev-base
RUN --mount=type=cache,id=apt-dev,target=/var/cache/apt \ RUN apt-get update && apt-get install -y --no-install-recommends \
apt-get update && apt-get install -y --no-install-recommends \
build-essential \ build-essential \
ca-certificates \ ca-certificates \
ccache \ ccache \
@ -28,9 +27,16 @@ ENV PATH /opt/conda/bin:$PATH
FROM dev-base as conda FROM dev-base as conda
ARG PYTHON_VERSION=3.8 ARG PYTHON_VERSION=3.8
# Automatically set by buildx
ARG TARGETPLATFORM
# translating Docker's TARGETPLATFORM into miniconda arches
RUN case ${TARGETPLATFORM} in \
"linux/arm64") MINICONDA_ARCH=aarch64 ;; \
*) MINICONDA_ARCH=x86_64 ;; \
esac && \
curl -fsSL -v -o ~/miniconda.sh -O "https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-${MINICONDA_ARCH}.sh"
COPY requirements.txt . COPY requirements.txt .
RUN curl -fsSL -v -o ~/miniconda.sh -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ RUN chmod +x ~/miniconda.sh && \
chmod +x ~/miniconda.sh && \
~/miniconda.sh -b -p /opt/conda && \ ~/miniconda.sh -b -p /opt/conda && \
rm ~/miniconda.sh && \ rm ~/miniconda.sh && \
/opt/conda/bin/conda install -y python=${PYTHON_VERSION} cmake conda-build pyyaml numpy ipython && \ /opt/conda/bin/conda install -y python=${PYTHON_VERSION} cmake conda-build pyyaml numpy ipython && \
@ -57,15 +63,21 @@ ARG CUDA_VERSION=11.3
ARG CUDA_CHANNEL=nvidia ARG CUDA_CHANNEL=nvidia
ARG INSTALL_CHANNEL=pytorch-nightly ARG INSTALL_CHANNEL=pytorch-nightly
ENV CONDA_OVERRIDE_CUDA=${CUDA_VERSION} ENV CONDA_OVERRIDE_CUDA=${CUDA_VERSION}
RUN /opt/conda/bin/conda install -c "${INSTALL_CHANNEL}" -c "${CUDA_CHANNEL}" -y python=${PYTHON_VERSION} pytorch torchvision torchtext "cudatoolkit=${CUDA_VERSION}" && \ # Automatically set by buildx
RUN /opt/conda/bin/conda install -c "${INSTALL_CHANNEL}" -y python=${PYTHON_VERSION}
ARG TARGETPLATFORM
# On arm64 we can only install wheel packages
RUN case ${TARGETPLATFORM} in \
"linux/arm64") pip install --extra-index-url https://download.pytorch.org/whl/cpu/ torch torchvision torchtext ;; \
*) /opt/conda/bin/conda install -c "${INSTALL_CHANNEL}" -c "${CUDA_CHANNEL}" -y "python=${PYTHON_VERSION}" pytorch torchvision torchtext "cudatoolkit=${CUDA_VERSION}" ;; \
esac && \
/opt/conda/bin/conda clean -ya /opt/conda/bin/conda clean -ya
RUN /opt/conda/bin/pip install torchelastic RUN /opt/conda/bin/pip install torchelastic
FROM ${BASE_IMAGE} as official FROM ${BASE_IMAGE} as official
ARG PYTORCH_VERSION ARG PYTORCH_VERSION
LABEL com.nvidia.volumes.needed="nvidia_driver" LABEL com.nvidia.volumes.needed="nvidia_driver"
RUN --mount=type=cache,id=apt-final,target=/var/cache/apt \ RUN apt-get update && apt-get install -y --no-install-recommends \
apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \ ca-certificates \
libjpeg-dev \ libjpeg-dev \
libpng-dev && \ libpng-dev && \

View File

@ -1,6 +1,6 @@
DOCKER_REGISTRY = docker.io DOCKER_REGISTRY ?= docker.io
DOCKER_ORG = $(shell docker info 2>/dev/null | sed '/Username:/!d;s/.* //') DOCKER_ORG ?= $(shell docker info 2>/dev/null | sed '/Username:/!d;s/.* //')
DOCKER_IMAGE = pytorch DOCKER_IMAGE ?= pytorch
DOCKER_FULL_NAME = $(DOCKER_REGISTRY)/$(DOCKER_ORG)/$(DOCKER_IMAGE) DOCKER_FULL_NAME = $(DOCKER_REGISTRY)/$(DOCKER_ORG)/$(DOCKER_IMAGE)
ifeq ("$(DOCKER_ORG)","") ifeq ("$(DOCKER_ORG)","")
@ -8,7 +8,7 @@ $(warning WARNING: No docker user found using results from whoami)
DOCKER_ORG = $(shell whoami) DOCKER_ORG = $(shell whoami)
endif endif
CUDA_VERSION = 11.3 CUDA_VERSION = 11.3.1
CUDNN_VERSION = 8 CUDNN_VERSION = 8
BASE_RUNTIME = ubuntu:18.04 BASE_RUNTIME = ubuntu:18.04
BASE_DEVEL = nvidia/cuda:$(CUDA_VERSION)-cudnn$(CUDNN_VERSION)-devel-ubuntu18.04 BASE_DEVEL = nvidia/cuda:$(CUDA_VERSION)-cudnn$(CUDNN_VERSION)-devel-ubuntu18.04
@ -16,13 +16,13 @@ BASE_DEVEL = nvidia/cuda:$(CUDA_VERSION)-cudnn$(CUDNN_VERSION)-de
# The conda channel to use to install cudatoolkit # The conda channel to use to install cudatoolkit
CUDA_CHANNEL = nvidia CUDA_CHANNEL = nvidia
# The conda channel to use to install pytorch / torchvision # The conda channel to use to install pytorch / torchvision
INSTALL_CHANNEL = pytorch INSTALL_CHANNEL ?= pytorch
PYTHON_VERSION = 3.8 PYTHON_VERSION ?= 3.8
PYTORCH_VERSION = $(shell git describe --tags --always) PYTORCH_VERSION ?= $(shell git describe --tags --always)
# Can be either official / dev # Can be either official / dev
BUILD_TYPE = dev BUILD_TYPE ?= dev
BUILD_PROGRESS = auto BUILD_PROGRESS ?= auto
BUILD_ARGS = --build-arg BASE_IMAGE=$(BASE_IMAGE) \ BUILD_ARGS = --build-arg BASE_IMAGE=$(BASE_IMAGE) \
--build-arg PYTHON_VERSION=$(PYTHON_VERSION) \ --build-arg PYTHON_VERSION=$(PYTHON_VERSION) \
--build-arg CUDA_VERSION=$(CUDA_VERSION) \ --build-arg CUDA_VERSION=$(CUDA_VERSION) \
@ -30,10 +30,32 @@ BUILD_ARGS = --build-arg BASE_IMAGE=$(BASE_IMAGE) \
--build-arg PYTORCH_VERSION=$(PYTORCH_VERSION) \ --build-arg PYTORCH_VERSION=$(PYTORCH_VERSION) \
--build-arg INSTALL_CHANNEL=$(INSTALL_CHANNEL) --build-arg INSTALL_CHANNEL=$(INSTALL_CHANNEL)
EXTRA_DOCKER_BUILD_FLAGS ?= EXTRA_DOCKER_BUILD_FLAGS ?=
BUILD ?= build
# Intentionally left blank
PLATFORMS_FLAG ?=
PUSH_FLAG ?=
USE_BUILDX ?=
BUILD_PLATFORMS ?=
WITH_PUSH ?= false
# Setup buildx flags
ifneq ("$(USE_BUILDX)","")
BUILD = buildx build
ifneq ("$(BUILD_PLATFORMS)","")
PLATFORMS_FLAG = --platform="$(BUILD_PLATFORMS)"
endif
# Only set platforms flags if using buildx
ifeq ("$(WITH_PUSH)","true")
PUSH_FLAG = --push
endif
endif
DOCKER_BUILD = DOCKER_BUILDKIT=1 \ DOCKER_BUILD = DOCKER_BUILDKIT=1 \
docker build \ docker $(BUILD) \
--progress=$(BUILD_PROGRESS) \ --progress=$(BUILD_PROGRESS) \
$(EXTRA_DOCKER_BUILD_FLAGS) \ $(EXTRA_DOCKER_BUILD_FLAGS) \
$(PLATFORMS_FLAG) \
$(PUSH_FLAG) \
--target $(BUILD_TYPE) \ --target $(BUILD_TYPE) \
-t $(DOCKER_FULL_NAME):$(DOCKER_TAG) \ -t $(DOCKER_FULL_NAME):$(DOCKER_TAG) \
$(BUILD_ARGS) . $(BUILD_ARGS) .
@ -59,7 +81,6 @@ runtime-image: BASE_IMAGE := $(BASE_RUNTIME)
runtime-image: DOCKER_TAG := $(PYTORCH_VERSION)-runtime runtime-image: DOCKER_TAG := $(PYTORCH_VERSION)-runtime
runtime-image: runtime-image:
$(DOCKER_BUILD) $(DOCKER_BUILD)
docker tag $(DOCKER_FULL_NAME):$(DOCKER_TAG) $(DOCKER_FULL_NAME):latest
.PHONY: runtime-push .PHONY: runtime-push
runtime-push: BASE_IMAGE := $(BASE_RUNTIME) runtime-push: BASE_IMAGE := $(BASE_RUNTIME)