Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
docker-shib-test/ci/deploy.sh
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
78 lines (65 sloc)
2.07 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Environment variables: | |
# | |
# REPOSITORY_URI (Optional) | |
echo "[INFO] $0 started at $(date)" | |
images=( shib-test-idp test-ldap ) | |
# Get the commit hash | |
read -r commit_hash<<<"$(git rev-parse --short HEAD)" | |
echo "[INFO] Commit hash: \"$commit_hash\"" | |
for image in "${images[@]}" | |
do | |
echo "[INFO] Building the $image image" | |
cd containers/"$image" || exit 1 | |
# Get the image version from the label | |
read -r version<<<"$(docker inspect --format='{{.Config.Labels.version}}' "$image":"$commit_hash")" | |
if [ -z "$version" ]; then | |
echo "[ERROR] Unable to inspect version label for image $image:$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:$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}" | |
else | |
remote_image_uri="${REPOSITORY_URI}/${image}" | |
fi | |
echo "[DEBUG] image_uri=$remote_image_uri" | |
# Determine tags to apply | |
tags=( | |
"latest" | |
"$major.$minor.$patch" | |
"$major.$minor" | |
"$major" | |
) | |
echo "[DEBUG] tags=\"${tags[*]}\"" | |
# Tag the image | |
echo "[INFO] Tagging the $image image" | |
for tag in "${tags[@]}"; do | |
cmd="docker tag $local_image $remote_image_uri:$tag" | |
echo "[DEBUG] cmd=\"$cmd\"" | |
if ! $cmd | |
then | |
echo "[ERROR] Tagging the $image image with \"$tag\" failed (exit code $rc)" | |
exit 1 | |
fi | |
done | |
# 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)" | |
exit 1 | |
fi | |
done | |
cd ../.. | |
done | |
echo "[INFO] $0 finished at $(date)" |