-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathimages
executable file
·116 lines (96 loc) · 2.74 KB
/
images
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
#!/usr/bin/env bash
TAG=$1
REPO=$2
PUSH=$3
. $(dirname $0)/util
set -eu -o pipefail
: "${RELEASE=false}"
: "${PLATFORMS=}"
: "${TARGET=}"
: "${BUILDKIT_DEBUG=}"
versionTag=$(git describe --always --tags --match "v[0-9]*")
if [[ ! "$versionTag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
versionTag=""
fi
usage() {
echo "usage: $0 <tag> <repo> [push]"
exit 1
}
if [ -z "$TAG" ] || [ -z "$REPO" ]; then
usage
fi
platformFlag=""
if [ -n "$PLATFORMS" ]; then
platformFlag="--platform=$PLATFORMS"
fi
localmode=""
if [[ "$TAG" == "local" ]]; then
localmode="1"
if [ "$PUSH" = "push" ]; then
echo >&2 "local images cannot be pushed"
exit 1
fi
fi
attestFlags="$(buildAttestFlags)"
outputFlag="--output=type=image,push=false"
if [ "$PUSH" = "push" ]; then
outputFlag="--output=type=image,push=true"
fi
if [ -n "$localmode" ]; then
outputFlag="--output=type=docker"
attestFlags=""
fi
if [ -z "$localmode" ] && [ "$GITHUB_ACTIONS" = "true" ]; then
outputFlag="${outputFlag},annotation.org.opencontainers.image.title=BuildKit"
if [ -n "$GITHUB_SHA" ]; then
outputFlag="${outputFlag},annotation.org.opencontainers.image.revision=$GITHUB_SHA"
fi
if [ -n "$GITHUB_REPOSITORY" ] && [ -n "$GITHUB_SERVER_URL" ]; then
outputFlag="${outputFlag},annotation.org.opencontainers.image.source=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY"
outputFlag="${outputFlag},annotation.org.opencontainers.image.url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY"
fi
if [ -n "$versionTag" ]; then
outputFlag="${outputFlag},annotation.org.opencontainers.image.version=$versionTag"
fi
fi
targetFlag=""
if [ -n "$TARGET" ]; then
targetFlag="--target=$TARGET"
fi
tagNames="$REPO:$TAG"
if [ -n "$TARGET" ]; then
tagNames="$tagNames-$TARGET"
fi
if [[ "$versionTag" == "$TAG" ]]; then
if [ -n "$TARGET" ]; then
tagNames="$tagNames $REPO:$TARGET"
else
tagNames="$tagNames $REPO:latest"
fi
fi
importCacheFlags=""
for tagName in $tagNames; do
importCacheFlags="$importCacheFlags--cache-from=type=registry,ref=$tagName "
done
if [ -n "$cacheFromFlags" ]; then
importCacheFlags="$importCacheFlags$cacheFromFlags"
fi
if [ -n "$localmode" ]; then
importCacheFlags=""
fi
exportCacheFlags=""
if [ -n "$cacheToFlags" ]; then
exportCacheFlags="$cacheToFlags"
elif [ "$PUSH" = "push" ]; then
exportCacheFlags="--cache-to=type=inline"
fi
tagFlags=""
for tagName in $tagNames; do
tagFlags="$tagFlags--tag=$tagName "
done
nocacheFilterFlag=""
if [[ "$RELEASE" = "true" ]] && [[ "$GITHUB_ACTIONS" = "true" ]]; then
nocacheFilterFlag="--no-cache-filter=git,buildkit-export,gobuild-base"
fi
buildxCmd build --build-arg BUILDKIT_DEBUG $platformFlag $targetFlag $importCacheFlags $exportCacheFlags $tagFlags $outputFlag $nocacheFilterFlag $attestFlags \
$currentcontext