-
Notifications
You must be signed in to change notification settings - Fork 34
131 lines (116 loc) · 4.52 KB
/
docker-build.yml
File metadata and controls
131 lines (116 loc) · 4.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
---
name: Build Tutorial Container
on:
push:
branches:
- main
paths-ignore:
- "*.md"
- slides/**
- images/**
- .gitignore
tags:
- "v*.*"
- "v*.*.*"
pull_request:
paths-ignore:
- "*.md"
- slides/**
- images/**
- .gitignore
workflow_dispatch:
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
packages: write
strategy:
matrix:
arch: [amd64, arm64]
variant: [cpu, cuda]
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=raw,value=${{ matrix.variant }}-${{ matrix.arch }},enable=${{ github.ref == 'refs/heads/main' }}
type=raw,value=${{ matrix.variant }}-${{ matrix.arch }}-pr-${{ github.event.pull_request.number }},enable=${{ github.event_name == 'pull_request' }}
type=raw,value=${{ matrix.variant }}-${{ matrix.arch }}-${{ github.ref_name }},enable=${{ startsWith(github.ref, 'refs/tags/') }}
type=raw,value=${{ matrix.variant }}-${{ matrix.arch }}-sha-${{ github.sha }},prefix=
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/${{ matrix.arch }}
push: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }}
tags: ${{ steps.meta.outputs.tags }}
provenance: false
build-args: |
PYTORCH_VARIANT=${{ matrix.variant }}
create-manifests:
needs: build-and-push
runs-on: ubuntu-latest
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
permissions:
packages: write
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
image=moby/buildkit:latest
network=host
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push CPU manifest
run: |
# Create and push multi-architecture manifest for CPU variant
docker buildx imagetools create --tag ghcr.io/${{ github.repository }}:cpu \
ghcr.io/${{ github.repository }}:cpu-amd64 \
ghcr.io/${{ github.repository }}:cpu-arm64
# If on main branch, also tag as latest
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
docker buildx imagetools create --tag ghcr.io/${{ github.repository }}:latest \
ghcr.io/${{ github.repository }}:cpu-amd64 \
ghcr.io/${{ github.repository }}:cpu-arm64
fi
# If this is a tag, add version tag for CPU
if [[ "${{ startsWith(github.ref, 'refs/tags/') }}" == "true" ]]; then
docker buildx imagetools create --tag ghcr.io/${{ github.repository }}:cpu-${{ github.ref_name }} \
ghcr.io/${{ github.repository }}:cpu-amd64 \
ghcr.io/${{ github.repository }}:cpu-arm64
fi
- name: Create and push CUDA manifest
run: |
# Create and push multi-architecture manifest for CUDA variant
docker buildx imagetools create --tag ghcr.io/${{ github.repository }}:cuda \
ghcr.io/${{ github.repository }}:cuda-amd64 \
ghcr.io/${{ github.repository }}:cuda-arm64
# If this is a tag, add version tag for CUDA
if [[ "${{ startsWith(github.ref, 'refs/tags/') }}" == "true" ]]; then
docker buildx imagetools create --tag ghcr.io/${{ github.repository }}:cuda-${{ github.ref_name }} \
ghcr.io/${{ github.repository }}:cuda-amd64 \
ghcr.io/${{ github.repository }}:cuda-arm64
fi