-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathdocker-build.sh
executable file
·34 lines (32 loc) · 1.52 KB
/
docker-build.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
#!/usr/bin/env bash
set -euo pipefail
source ./scripts/utils.sh
lint_docker_file() {
printMessage "$HEART_ICON" "$HEART_ICON" "Starting hadolinting: $1"
hadolint $1
printMessage "$HEART_ICON" "$HEART_ICON" "Completed hadolinting: $1"
}
build_image() {
printMessage "$HEART_ICON" "$HEART_ICON" "Start Building Docker Image..."
TAG=$([ "${CIRCLE_BRANCH}" == "main" ] && echo "0.1.${CIRCLE_BUILD_NUM}" || echo "${CIRCLE_BRANCH}" | sed 's/dependabot\/gradle//g;s/.//')
echo "${TAG}" > version/docker-version.txt
echo "${TAG}" > version/test.txt
printMessage "$HEART_ICON" "$HEART_ICON" "New Docker Image Version : ${TAG}"
echo "${DOCKER_PASS}" | docker login --username "${DOCKER_USER}" --password-stdin
docker build -t "${DOCKER_USER}/${DOCKER_IMAGE}:${TAG}" -f ci.Dockerfile .
}
push_image() {
TAG=$(cat version/docker-version.txt)
printMessage "$HEART_ICON" "$HEART_ICON" "print value from test.tx"
cat version/test.txt
if [ "${CIRCLE_BRANCH}" == "main" ]; then
printMessage "$HEART_ICON" "$HEART_ICON" "Pushing Docker Image latest & ${TAG} ..."
docker tag "${DOCKER_USER}/${DOCKER_IMAGE}:${TAG}" "${DOCKER_USER}/${DOCKER_IMAGE}:latest"
docker push "${DOCKER_USER}/${DOCKER_IMAGE}:${TAG}"
docker push "${DOCKER_USER}/${DOCKER_IMAGE}:latest"
printEmojiWrappedMessage "${GREEN}${HEART_ICON}" "Successfully pushed Docker Image '${DOCKER_USER}/${DOCKER_IMAGE}' with latest & ${TAG} tags..."
else
printEmojiWrappedMessage "${GREEN}${HEART_ICON}" "Skipping push docker image for non main branch."
fi
}
"$@"