-
Notifications
You must be signed in to change notification settings - Fork 32
/
docker.sh
executable file
·100 lines (90 loc) · 2.44 KB
/
docker.sh
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
#!/usr/bin/env bash
set -e
ARCH=$(uname -m)
GIT_COMMIT=$(git rev-parse HEAD)
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
IMAGE_NAME=rustvmm/dev
REGISTRY=index.docker.io
# Get the latest published version. Returns a number.
# If latest is v100, returns 100.
# If latest for riscv64 is v100-riscv, returns 100.
# This works as long as we have less than 100 tags because we set the page size to 100,
# once we have more than that this script needs to be updated.
latest(){
curl -L -s 'https://registry.hub.docker.com/v2/repositories/rustvmm/dev/tags?page_size=100'| \
jq '."results"[]["name"]' | sed 's/"//g' | cut -c 2- | grep -E "^[0-9]+" | sort -n | tail -1
}
next_version() {
latest_version=$(latest)
new_version=$((latest_version + 1))
echo "$new_version"
}
print_next_version() {
echo "rustvmm/dev:v$(next_version)"
}
print_registry() {
echo ${REGISTRY}
}
print_image_name() {
echo ${IMAGE_NAME}
}
# Builds the tag for the newest versions. It needs the last published version number.
# Returns a valid docker tag.
build_tag(){
new_version=$(next_version)
new_tag=${IMAGE_NAME}:v${new_version}_$ARCH
echo "$new_tag"
}
# Build a new docker version.
# It will build a new docker image with tag latest version + 1
# and will alias it with "latest" tag.
build(){
new_tag=$(build_tag)
docker build -t "$new_tag" \
--build-arg GIT_BRANCH="${GIT_BRANCH}" \
--build-arg GIT_COMMIT="${GIT_COMMIT}" \
-f Dockerfile .
echo "Build completed for $new_tag"
}
# Creates and pushes a manifest for a new version
manifest(){
latest_version=$(latest)
new_version=$((latest_version + 1))
new_tag=${IMAGE_NAME}:v${new_version}
docker manifest create \
$new_tag \
"${new_tag}_x86_64" \
"${new_tag}_aarch64"
echo "Manifest successfully created"
docker manifest push $new_tag
echo "Manifest successfully pushed on DockerHub: ${DOCKERHUB_LINK}"
}
publish(){
new_tag=$(build_tag)
echo "Publishing $new_tag on dockerhub"
docker push "$new_tag"
echo "Successfully published $new_tag on DockerHub: ${DOCKERHUB_LINK}"
}
case $1 in
"build")
build;
;;
"publish")
publish;
;;
"manifest")
manifest;
;;
"print-registry")
print_registry;
;;
"print-image-name")
print_image_name;
;;
"print-next-version")
print_next_version;
;;
*)
echo "Command $1 not supported. Try with 'publish', 'build', 'manifest' or 'print-next-version'. ";
;;
esac