-
Notifications
You must be signed in to change notification settings - Fork 0
/
push.sh
executable file
·73 lines (57 loc) · 1.42 KB
/
push.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
#!/bin/bash
set -e
EXPECTED_ARGS=2
if [ $# -ne $EXPECTED_ARGS ]
then
echo "Usage: `basename $0` [container, e.g. default] [tag]"
exit 1
fi
container=$1
tag=$2
docker_username="${DOCKER_USERNAME:-alexandrebouchardcote}"
function is_git_clean {
mods=`git status --porcelain | tail -n 1`
if [ "${#mods}" -gt "0" ]
then
return 1 # false
else
return 0 # true
fi
}
# return 1 (true) if the git repo is up to date with remote, 0 (false) otherwise
function is_git_remote_up_to_date {
LOCAL=$(git rev-parse @)
REMOTE=$(git rev-parse @{u})
if [ $LOCAL = $REMOTE ]
then
return 0
else
return 1
fi
}
if ! [ -f "push.sh" ]; then
echo "Run from root of the containers repo"
exit 1
fi
echo "Checking everything is committed.."
if ! is_git_clean
then
echo "Make sure everything is committed in the project dir before releasing artifacts"
exit 1
fi
echo "Checking everything is committed.."
if ! is_git_remote_up_to_date
then
echo "Make sure to git pull before releasing artifacts"
exit 1
fi
# tag the git repo
# this will stop the script if tag already exists
echo "Tagging the git repo..."
git tag -a ${container}_${tag} -m "Automatic tag for $container:$tag"
# perform docker operation
echo "Performing docker operation..."
docker buildx create --use
docker buildx build --platform linux/amd64,linux/arm64 -t $docker_username/$container:$tag --push $container
# push the tag to git
git push --tags