-
Notifications
You must be signed in to change notification settings - Fork 341
129 lines (127 loc) · 4.6 KB
/
images.yml
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
on:
workflow_call:
inputs:
release:
required: true
type: boolean
version:
required: false
type: string
jobs:
images:
runs-on: ubuntu-latest
strategy:
matrix:
dvc: [1, 2, 3]
base: [0, 1]
gpu: [false, true]
include:
- base: 0
ubuntu: 18.04
python: 2.7
cuda: 11.2.2
cudnn: 8
- base: 1
ubuntu: 20.04
python: 3.8
cuda: 11.2.2
cudnn: 8
- latest: true # update the values below after introducing a new major version
base: 1
dvc: 3
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha || github.ref }}
fetch-depth: 0
- name: Metadata
id: metadata
env:
CML_VERSION: ${{ inputs.version }}
run: |
latest_tag=$(git describe --tags | cut -d- -f1)
test -n "$CML_VERSION" && latest_tag="$CML_VERSION"
cml_version=${latest_tag##v}
dvc_version=$(python3 -c '
from distutils.version import StrictVersion as Ver
from urllib.request import urlopen
from json import load
data = load(urlopen("https://pypi.org/pypi/dvc/json"))
ver_pre = "${{ matrix.dvc }}".rstrip(".") + "."
print(
max(
(i.strip() for i in data["releases"] if i.startswith(ver_pre)),
default="${{ matrix.dvc }}",
key=Ver
)
)')
echo cache_tag=${cml_version}-${dvc_version}-${{ matrix.base }}-${{ matrix.gpu }} >> $GITHUB_OUTPUT
echo cml_version=$cml_version >> $GITHUB_OUTPUT
tag=${cml_version//.*/}-dvc${{ matrix.dvc }}-base${{ matrix.base }}
if [[ ${{ matrix.gpu }} == true ]]; then
echo base=nvidia/cuda:${{ matrix.cuda }}-cudnn${{ matrix.cudnn }}-runtime-ubuntu${{ matrix.ubuntu }} >> $GITHUB_OUTPUT
tag=${tag}-gpu
else
echo base=ubuntu:${{ matrix.ubuntu }} >> $GITHUB_OUTPUT
fi
TAGS="$(
for registry in docker.io/{dvcorg,iterativeai} ghcr.io/iterative; do
if [[ "${{ matrix.latest }}" == "true" ]]; then
if [[ "${{ matrix.gpu }}" == "true" ]]; then
echo "${registry}/cml:latest-gpu"
else
echo "${registry}/cml:latest"
fi
fi
echo "${registry}/cml:${tag}"
done | head -c-1
)"
# https://github.com/orgs/community/discussions/26288#discussioncomment-3876281
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
delim="$(openssl rand -hex 8)"
echo "tags<<${delim}" >> $GITHUB_OUTPUT
echo "${TAGS}" >> $GITHUB_OUTPUT
echo "${delim}" >> $GITHUB_OUTPUT
- uses: docker/setup-buildx-action@v2
- uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key:
${{ runner.os }}-buildx-${{ steps.metadata.outputs.cache_tag }}-${{
github.sha }}
restore-keys:
${{ runner.os }}-buildx-${{ steps.metadata.outputs.cache_tag }}-
- uses: docker/login-action@v2
with:
registry: docker.io
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ github.token }}
- uses: docker/build-push-action@v3
with:
push:
${{ inputs.release || github.event_name == 'push' ||
github.event_name == 'schedule' || github.event_name ==
'workflow_dispatch' }}
context: ./
file: ./Dockerfile
tags: |
${{ steps.metadata.outputs.tags }}
build-args: |
CML_VERSION=${{ steps.metadata.outputs.cml_version }}
DVC_VERSION=${{ matrix.dvc }}
PYTHON_VERSION=${{ matrix.python }}
BASE_IMAGE=${{ steps.metadata.outputs.base }}
pull: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Move cache
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache