-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish.sh
executable file
·55 lines (45 loc) · 1.5 KB
/
publish.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
#!/usr/bin/env bash
IMAGE_NAME="canopycanopycanopy/b-ber"
# Check that Docker is running
check_docker_status=$(docker info > /dev/null 2>&1)
if [[ $? -ne 0 ]]; then
echo "Ensure the docker daemon is running before publishing"
exit
fi
if [[ -n $(docker images --filter reference=$IMAGE_NAME -q) ]]; then
echo "Remove existing image before proceeding by running \`docker rmi $IMAGE_NAME\`"
exit
fi
# Verify credentials so that docker push doesn't bail
docker login
read -ra IMAGE_VERSION <<< "$(git describe --abbrev=0 --tags)"
read -ra VCS_REF <<< "$(git rev-parse --short HEAD)"
read -ra VCS_URL <<< "$(git config --get remote.origin.url)"
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
echo
echo "Building..."
echo
echo " Image Name: $IMAGE_NAME"
echo " Image Version: $IMAGE_VERSION"
echo " VCS Ref: $VCS_REF"
echo " VCS URL: $VCS_URL"
echo " Build Date: $BUILD_DATE"
echo
function deploy {
docker build --build-arg VCS_REF="$VCS_REF" \
--build-arg VCS_URL="$VCS_URL" \
--build-arg BUILD_DATE="$BUILD_DATE" \
--build-arg IMAGE_VERSION="$IMAGE_VERSION" \
-t "$IMAGE_NAME":"$IMAGE_VERSION" .
read -ra IMAGE_ID <<< "$(docker images --filter reference=$IMAGE_NAME -q)"
docker tag "$IMAGE_ID" "$IMAGE_NAME":"$IMAGE_VERSION"
docker push "$IMAGE_NAME":"$IMAGE_VERSION"
}
# Confirm deploy
while true; do
read -p " Does this look OK? [yN] " yn
case $yn in
[Yy]* ) deploy; break;;
* ) exit;;
esac
done