Skip to content

Commit

Permalink
update deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
vladyslav-tk committed Oct 2, 2023
1 parent f2d7019 commit a863629
Showing 1 changed file with 78 additions and 23 deletions.
101 changes: 78 additions & 23 deletions scripts/deploy-to-env.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,82 @@
#!/bin/bash -e

export VERSION=latest
export REGISTRY_PREFIX="docker.io/"

# Use individual image versionning on dev to ensure argocd
# will deploy them (otherwise the tag is the same, latest)
VERSIONNED_SERVICES="swissgeol_api abbreviator"
for svc in $VERSIONNED_SERVICES
do
kind=`echo $svc| tr [:upper:] [:lower:]`
export IMAGE_${svc}="${REGISTRY_PREFIX}camptocamp/$svc:$VERSION"
done
target=$1 # dev, int, prod

if [[ $target = "dev" ]]
then
echo "On dev, forcing version to latest"
export VERSION=latest
elif [[ "$target" = "prod" || "$target" = "int" ]] && [[ -z $VERSION ]]
then
echo "VERSION should be defined to deploy to int and prod envs"
exit 2
fi

function get_image_hash() {
local svc="$1"

local IMAGE=$(echo camptocamp/$svc | tr [:upper:] [:lower:])
echo "docker inspect $IMAGE -f '{{ .RepoDigests }}'"
local HASH=$(docker inspect $IMAGE -f '{{ .RepoDigests }}' | tr -d '[]' | tr " " "\n" | cut -d@ -f2)

if [[ -z $HASH ]]; then
echo "Something wrong getting digest of image $IMAGE"
exit 1
fi

echo Using $HASH for $IMAGE

for svc in $VERSIONNED_SERVICES
do
IMAGE=`echo ${REGISTRY_PREFIX}camptocamp/$svc | tr [:upper:] [:lower:]`
echo "docker inspect $IMAGE -f '{{ .RepoDigests }}'"
HASH=`docker inspect $IMAGE -f '{{ .RepoDigests }}' | tr -d '[]' | tr " " "\n" | grep docker.io | cut -d@ -f2`
if [[ -z $HASH ]]
then
echo "Something wrong getting digest of image $IMAGE"
exit 1
retval=$HASH
}
rm -rf argocd
[ ! -e argocd ] && (echo cloning apps && git clone [email protected]:ngm/argocd.git)
cd argocd/
git checkout $target
git pull
cd apps
for dir in ./*/; do
file="${dir}tag_value.yaml"
IMAGE_TAG=""
if [ "$target" = "dev" ]; then
if [[ "$dir" == *api* ]]; then
get_image_hash "swissgeol_api"
IMAGE_TAG=@$retval
elif [[ "$dir" == *urlshortener* ]]; then
get_image_hash "abbreviator"
IMAGE_TAG=@$retval
fi
elif [[ "$target" = "prod" || "$target" = "int" ]]; then
IMAGE_TAG=$VERSION
fi
export IMAGE_${svc}=$IMAGE@$HASH
echo Using $IMAGE@$HASH
done
if [[ -z $IMAGE_TAG ]]; then
echo "Something went wrong with directory ${dir}"
exit 1
fi
echo "Processing $file"
cat > $file << EOM
image:
tag: "$IMAGE_TAG"
EOM

done
cd ../

git add -A .
git commit -m "dev iteration"
git push origin $target
THE_TAG="${target}_`date +'%Y-%m-%d'`_$VERSION"
[ "$target" = "prod" ] || [ "$target" = "int" ] && (git tag -f $THE_TAG -m $THE_TAG; git push -f origin $THE_TAG)
cd ../
rm -rf argocd

#if [[ -n $CI ]]
#then
# echo "In CI: skipping argocd SYNC (auto-sync enabled)"
#else
# # Ask argocd to sync the app
# ARGOCD_SERVER="dev-argocd.swissgeol.ch"
# echo argocd login --sso $ARGOCD_SERVER
# argocd --grpc-web app sync api-${target} urlshortener-${target} --prune --force --server $ARGOCD_SERVER
#fi

echo "the end"

0 comments on commit a863629

Please sign in to comment.