-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdocker_build_and_push.sh
executable file
·55 lines (44 loc) · 1.27 KB
/
docker_build_and_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
#!/bin/bash
set -e
help() {
echo "This script requires four arguments, directory with the Docker file, Docker image name, Base directory, and the Docker tag."
echo "Usages: $(basename "$0") <docker-file-directory> <docker-image-name> <base-dir> <tag>"
}
if [ "$#" -lt 4 ]; then
help
exit 1
fi
push() {
echo "push-indicator=true" >> "$GITHUB_OUTPUT"
"${FOREST_DIR}"/docker_push.sh "$@"
"${FOREST_DIR}"/container_digest.sh "$@"
}
"${FOREST_DIR}"/docker_build.sh "$@"
echo "Check if PUSH_ON_GIT_TAG is set"
if [ "$PUSH_ON_GIT_TAG" = true ]
then
if [[ $GITHUB_REF == refs/tags/* ]]
then
echo "PUSH_ON_GIT_TAG is set and GITHUB_REF ( $GITHUB_REF ) is a tag: start pushing"
push "$@"
exit 0
else
echo "GITHUB_REF is not a tag.. it is: ${GITHUB_REF}"
fi
else
echo "PUSH_ON_GIT_TAG is not set"
fi
echo "Check if we need to push the docker images to docker hub:"
# shellcheck disable=SC2153
echo "Push branches: $PUSH_BRANCHES"
echo "GITHUB_REF: $GITHUB_REF"
read -ra push_branches <<< "$PUSH_BRANCHES"
for branch in "${push_branches[@]}"; do
if [[ "$GITHUB_REF" = "refs/heads/${branch}" ]]; then
echo "Matches: start pushing"
push "$@"
exit 0
fi
done
echo "No branches matched to current branch. No need to push the images to docker hub."
exit 0