-
Notifications
You must be signed in to change notification settings - Fork 33
157 lines (142 loc) · 5.73 KB
/
docker-build.yml
File metadata and controls
157 lines (142 loc) · 5.73 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
---
name: Build Tutorial Container
on:
push:
branches:
- main
paths:
- "Dockerfile"
- "docker/**"
- "binder/**"
- "**/environment.yml"
- ".github/workflows/docker-build.yml"
tags:
- "v*.*"
- "v*.*.*"
pull_request:
paths:
- "Dockerfile"
- "docker/**"
- "binder/**"
- "**/environment.yml"
- ".github/workflows/docker-build.yml"
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 }}
- 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: |
# Determine the correct tag suffixes based on the event type
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
# PR build - use the commit SHA for more predictable references
AMD64_TAG="cpu-amd64-sha-${{ github.sha }}"
ARM64_TAG="cpu-arm64-sha-${{ github.sha }}"
TARGET_TAG="cpu-sha-${{ github.sha }}"
elif [[ "${{ startsWith(github.ref, 'refs/tags/') }}" == "true" ]]; then
# Tag build - use tag version in the name
AMD64_TAG="cpu-amd64-${{ github.ref_name }}"
ARM64_TAG="cpu-arm64-${{ github.ref_name }}"
TARGET_TAG="cpu-${{ github.ref_name }}"
else
# Main branch build - use simple arch tags
AMD64_TAG="cpu-amd64"
ARM64_TAG="cpu-arm64"
TARGET_TAG="cpu"
fi
# Create the manifest with the correct tag names
echo "Creating CPU manifest using $AMD64_TAG and $ARM64_TAG"
docker buildx imagetools create --tag ghcr.io/${{ github.repository }}:${TARGET_TAG} \
ghcr.io/${{ github.repository }}:${AMD64_TAG} \
ghcr.io/${{ github.repository }}:${ARM64_TAG}
# 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 }}:${AMD64_TAG} \
ghcr.io/${{ github.repository }}:${ARM64_TAG}
fi
- name: Create and push CUDA manifest
run: |
# Determine the correct tag suffixes based on the event type
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
# PR build - use the commit SHA for more predictable references
AMD64_TAG="cuda-amd64-sha-${{ github.sha }}"
ARM64_TAG="cuda-arm64-sha-${{ github.sha }}"
TARGET_TAG="cuda-sha-${{ github.sha }}"
elif [[ "${{ startsWith(github.ref, 'refs/tags/') }}" == "true" ]]; then
# Tag build - use tag version in the name
AMD64_TAG="cuda-amd64-${{ github.ref_name }}"
ARM64_TAG="cuda-arm64-${{ github.ref_name }}"
TARGET_TAG="cuda-${{ github.ref_name }}"
else
# Main branch build - use simple arch tags
AMD64_TAG="cuda-amd64"
ARM64_TAG="cuda-arm64"
TARGET_TAG="cuda"
fi
# Create the manifest with the correct tag names
echo "Creating CUDA manifest using $AMD64_TAG and $ARM64_TAG"
docker buildx imagetools create --tag ghcr.io/${{ github.repository }}:${TARGET_TAG} \
ghcr.io/${{ github.repository }}:${AMD64_TAG} \
ghcr.io/${{ github.repository }}:${ARM64_TAG}