This repository has been archived by the owner on Mar 2, 2022. It is now read-only.
/
post_push
49 lines (42 loc) · 1.75 KB
/
post_push
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
#!/bin/bash
set -e
# add additional tags without bugfix and minor version
MAJ_MIN_BUG=${PWD##*/}
MAJ_MIN=$(echo $MAJ_MIN_BUG | sed "s/\.[^\.]*$//")
MAJ=$(echo $MAJ_MIN | sed "s/\.[^\.]*$//")
echo "Add version tags for major and major.minor releases."
## x.y.z
# Tag for major.minor.bug is already provided by Docker Hub configuration
## x.y
# Check if this image is newest within major.minor
NEWEST_MAJ_MIN=`ls ../ | grep "^$MAJ_MIN" | sort --version-sort | tail -n 1`
if [ "$MAJ_MIN_BUG" == "$NEWEST_MAJ_MIN" ]
then
echo "This version is also the newest major.minor version, add tag '$MAJ_MIN' to '$MAJ_MIN_BUG'"
docker tag $IMAGE_NAME $DOCKER_REPO:$MAJ_MIN
docker push $DOCKER_REPO:$MAJ_MIN
else
echo "$NEWEST_MAJ_MIN is newest version starting with $MAJ_MIN, not tagging this one ($MAJ_MIN_BUG)."
fi
## x
# Check if this image is "latest" within major
NEWEST_MAJ=`ls ../ | grep "^$MAJ" | sort --version-sort | tail -n 1`
if [ "$MAJ_MIN_BUG" == "$NEWEST_MAJ" ]
then
echo "This version is also the newest major version, add tag '$MAJ' to '$MAJ_MIN_BUG'."
docker tag $IMAGE_NAME $DOCKER_REPO:$MAJ
docker push $DOCKER_REPO:$MAJ
else
echo "$NEWEST_MAJ is newest version starting with $MAJ, not tagging this one ($MAJ_MIN_BUG)."
fi
# Get "latest": list parent directory files starting with number, sort them and only select the last one
LATEST=`ls ../ | grep '^[0-9]' | sort --version-sort | tail -n 1`
if [ "$MAJ_MIN_BUG" == "$LATEST" ]
then
echo "This version is also newest version overall, add 'latest' tag to $MAJ_MIN_BUG"
docker tag $IMAGE_NAME $DOCKER_REPO:latest
docker push $DOCKER_REPO:latest
else
echo "$LATEST is newest version overall, not tagging this one ($MAJ_MIN_BUG) with latest."
fi
echo "Version tagging completed."