mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 12:54:11 +08:00
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:
committed by
PyTorch MergeBot
parent
3a511e8354
commit
1b437718a3
89
.github/workflows/docker-release.yml
vendored
Normal file
89
.github/workflows/docker-release.yml
vendored
Normal 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()
|
26
Dockerfile
26
Dockerfile
@ -11,8 +11,7 @@ ARG BASE_IMAGE=ubuntu:18.04
|
||||
ARG PYTHON_VERSION=3.8
|
||||
|
||||
FROM ${BASE_IMAGE} as dev-base
|
||||
RUN --mount=type=cache,id=apt-dev,target=/var/cache/apt \
|
||||
apt-get update && apt-get install -y --no-install-recommends \
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
build-essential \
|
||||
ca-certificates \
|
||||
ccache \
|
||||
@ -28,9 +27,16 @@ ENV PATH /opt/conda/bin:$PATH
|
||||
|
||||
FROM dev-base as conda
|
||||
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 .
|
||||
RUN curl -fsSL -v -o ~/miniconda.sh -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
|
||||
chmod +x ~/miniconda.sh && \
|
||||
RUN chmod +x ~/miniconda.sh && \
|
||||
~/miniconda.sh -b -p /opt/conda && \
|
||||
rm ~/miniconda.sh && \
|
||||
/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 INSTALL_CHANNEL=pytorch-nightly
|
||||
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
|
||||
RUN /opt/conda/bin/pip install torchelastic
|
||||
|
||||
FROM ${BASE_IMAGE} as official
|
||||
ARG PYTORCH_VERSION
|
||||
LABEL com.nvidia.volumes.needed="nvidia_driver"
|
||||
RUN --mount=type=cache,id=apt-final,target=/var/cache/apt \
|
||||
apt-get update && apt-get install -y --no-install-recommends \
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
ca-certificates \
|
||||
libjpeg-dev \
|
||||
libpng-dev && \
|
||||
|
@ -1,6 +1,6 @@
|
||||
DOCKER_REGISTRY = docker.io
|
||||
DOCKER_ORG = $(shell docker info 2>/dev/null | sed '/Username:/!d;s/.* //')
|
||||
DOCKER_IMAGE = pytorch
|
||||
DOCKER_REGISTRY ?= docker.io
|
||||
DOCKER_ORG ?= $(shell docker info 2>/dev/null | sed '/Username:/!d;s/.* //')
|
||||
DOCKER_IMAGE ?= pytorch
|
||||
DOCKER_FULL_NAME = $(DOCKER_REGISTRY)/$(DOCKER_ORG)/$(DOCKER_IMAGE)
|
||||
|
||||
ifeq ("$(DOCKER_ORG)","")
|
||||
@ -8,7 +8,7 @@ $(warning WARNING: No docker user found using results from whoami)
|
||||
DOCKER_ORG = $(shell whoami)
|
||||
endif
|
||||
|
||||
CUDA_VERSION = 11.3
|
||||
CUDA_VERSION = 11.3.1
|
||||
CUDNN_VERSION = 8
|
||||
BASE_RUNTIME = ubuntu:18.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
|
||||
CUDA_CHANNEL = nvidia
|
||||
# The conda channel to use to install pytorch / torchvision
|
||||
INSTALL_CHANNEL = pytorch
|
||||
INSTALL_CHANNEL ?= pytorch
|
||||
|
||||
PYTHON_VERSION = 3.8
|
||||
PYTORCH_VERSION = $(shell git describe --tags --always)
|
||||
PYTHON_VERSION ?= 3.8
|
||||
PYTORCH_VERSION ?= $(shell git describe --tags --always)
|
||||
# Can be either official / dev
|
||||
BUILD_TYPE = dev
|
||||
BUILD_PROGRESS = auto
|
||||
BUILD_TYPE ?= dev
|
||||
BUILD_PROGRESS ?= auto
|
||||
BUILD_ARGS = --build-arg BASE_IMAGE=$(BASE_IMAGE) \
|
||||
--build-arg PYTHON_VERSION=$(PYTHON_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 INSTALL_CHANNEL=$(INSTALL_CHANNEL)
|
||||
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 $(BUILD) \
|
||||
--progress=$(BUILD_PROGRESS) \
|
||||
$(EXTRA_DOCKER_BUILD_FLAGS) \
|
||||
$(PLATFORMS_FLAG) \
|
||||
$(PUSH_FLAG) \
|
||||
--target $(BUILD_TYPE) \
|
||||
-t $(DOCKER_FULL_NAME):$(DOCKER_TAG) \
|
||||
$(BUILD_ARGS) .
|
||||
@ -59,7 +81,6 @@ runtime-image: BASE_IMAGE := $(BASE_RUNTIME)
|
||||
runtime-image: DOCKER_TAG := $(PYTORCH_VERSION)-runtime
|
||||
runtime-image:
|
||||
$(DOCKER_BUILD)
|
||||
docker tag $(DOCKER_FULL_NAME):$(DOCKER_TAG) $(DOCKER_FULL_NAME):latest
|
||||
|
||||
.PHONY: runtime-push
|
||||
runtime-push: BASE_IMAGE := $(BASE_RUNTIME)
|
||||
|
Reference in New Issue
Block a user