Skip to content

Commit

Permalink
Update deploy script (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
dshafer authored Feb 11, 2020
1 parent 1a46f50 commit 87bd640
Showing 1 changed file with 54 additions and 18 deletions.
72 changes: 54 additions & 18 deletions ci/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,38 +1,74 @@
#!/usr/bin/env bash

# Environment variables:
#
# REPOSITORY_URI (Optional)

echo "[INFO] $0 started at `date`"

# Read the commit hash
image_name=shib-proxy
return=0

# Get the commit hash
read -r commit_hash<<<$(git rev-parse --short HEAD)
echo "[INFO] Commit hash: \"$commit_hash\""

image_name=shib-proxy

# Read the version
# Get the image's version label
read -r version<<<$(docker inspect --format='{{.Config.Labels.version}}' $image_name:$commit_hash)
if [[ "$version" == "" ]]; then
if [ -z "$version" ]; then
echo "[ERROR] Unable to inspect version label for image $image_name:$commit_hash"
exit 1
fi
echo "[INFO] Version: \"$version\""
read -r major minor patch<<<$(echo $version | tr . ' ')
echo "[DEBUG] major.minor.patch=\"$major.$minor.$patch\""
local_image="$image_name:$commit_hash"
echo "[DEBUG] local_image=\"$local_image\""

# If no ECR hostname is set, default to using Docker Hub
if [ -z "$REPOSITORY_URI" ]; then
remote_image_uri="${image_name}"
else
remote_image_uri="${REPOSITORY_URI}/${image_name}"
fi
echo "[DEBUG] image_uri=\"$remote_image_uri\""

# Determine tags
tags=(
"latest"
"$major.$minor.$patch"
"$major.$minor"
"$major"
)
echo "[DEBUG] tags=\"${tags[*]}\""

# Tag the image
echo "[INFO] Tagging the container image"
docker tag $image_name:$commit_hash ${ECR_HOSTNAME}/${image_name}:$major.$minor.$patch
docker tag $image_name:$commit_hash ${ECR_HOSTNAME}/${image_name}:$major.$minor
docker tag $image_name:$commit_hash ${ECR_HOSTNAME}/${image_name}:$major
for tag in ${tags[@]}; do
cmd="docker tag $local_image $remote_image_uri:$tag"
echo "[DEBUG] cmd=\"$cmd\""
$cmd
rc=$?
if [ $rc -ne 0 ]; then
echo "[ERROR] Tagging failed (exit code $rc)"
return=1
break
fi
done

# Push the image to a registry if REPOSITORY_BASE is defined
if [ -z "$ECR_HOSTNAME" ]; then
echo "[ERROR] Unable to push image (ECR_HOSTNAME not specified)"
else
echo "[DEBUG] ECR_HOSTNAME=\"$ECR_HOSTNAME\""
docker push ${ECR_HOSTNAME}/${image_name}:latest
docker push ${ECR_HOSTNAME}/${image_name}:$major.$minor.$patch
docker push ${ECR_HOSTNAME}/${image_name}:$major.$minor
docker push ${ECR_HOSTNAME}/${image_name}:$major
fi
# Push the image to the registry
echo "[INFO] Pushing the image to the registry"
for tag in ${tags[@]}; do
cmd="docker push $remote_image_uri:$tag"
echo "[DEBUG] cmd=\"$cmd\""
$cmd
rc=$?
if [ $rc -ne 0 ]; then
echo "[ERROR] Push failed (exit code $rc)"
return=1
break
fi
done

echo "[INFO] $0 finished at `date`"
exit $return

0 comments on commit 87bd640

Please sign in to comment.