forked from bugsink/bugsink
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuilddocker.bash
More file actions
executable file
·64 lines (53 loc) · 2.05 KB
/
builddocker.bash
File metadata and controls
executable file
·64 lines (53 loc) · 2.05 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
#!/bin/bash
set -e
WHEEL_FILE=$(ls dist/ -1atr | grep bugsink | grep whl | tail -n1)
echo "Building docker image with wheel file: $WHEEL_FILE"
echo "Is this the correct wheel file? [y/n]"
read -r response
if [[ ! "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
echo "Please run the script again with the correct wheel file in the dist/ directory"
exit 1
fi
# example: bugsink-0.1.8.dev5+g200ea5e.d20240827-py3-none-any.whl
# if this a non-dev version, we tag the image with the full version number, major.minor, major, and latest
# otherwise no tags are added
if [[ $WHEEL_FILE == *"dev"* ]]; then
echo "This is a dev version, no (numbered) tags will be added, just a :dev tag"
TAGS="-t bugsink/bugsink:dev"
else
VERSION=$(echo $WHEEL_FILE | cut -d'-' -f2)
REPO="bugsink/bugsink"
# numeric tags for this build
TAG_LIST=(
"$REPO:$VERSION"
"$REPO:$(echo "$VERSION" | awk -F. '{print $1"."$2}')"
"$REPO:$(echo "$VERSION" | awk -F. '{print $1}')"
)
# Find highest published semver on Docker Hub (public repo; no auth needed)
HIGHEST_PUBLISHED=$(
curl -fsSL "https://hub.docker.com/v2/repositories/${REPO}/tags?page_size=100" \
| grep -o '"name":"[^"]*"' \
| cut -d'"' -f4 \
| grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' \
| sort -V \
| tail -n1
)
# Decide whether we’re allowed to move :latest forward
ADD_LATEST=true
if [[ -n "$HIGHEST_PUBLISHED" ]]; then
# if VERSION < HIGHEST_PUBLISHED, do NOT set :latest
top=$(printf '%s\n%s\n' "$HIGHEST_PUBLISHED" "$VERSION" | sort -V | tail -n1)
if [[ "$top" != "$VERSION" ]]; then
ADD_LATEST=false
echo "Not tagging :latest: $VERSION < already published $HIGHEST_PUBLISHED"
fi
fi
# Build TAGS string
TAGS=""
for t in "${TAG_LIST[@]}"; do TAGS+=" -t $t"; done
if $ADD_LATEST; then
TAGS+=" -t $REPO:latest -t $REPO"
echo "Tagging as latest: $VERSION ≥ ${HIGHEST_PUBLISHED:-<none>}"
fi
fi
docker build -f Dockerfile.fromwheel --build-arg WHEEL_FILE=$WHEEL_FILE $TAGS .