Skip to content

Instantly share code, notes, and snippets.

@efi-mk
Created July 12, 2018 16:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save efi-mk/f5d41cd302ebf5c81eca9b8e76d72ffe to your computer and use it in GitHub Desktop.
Save efi-mk/f5d41cd302ebf5c81eca9b8e76d72ffe to your computer and use it in GitHub Desktop.
Serverless testing from the trenches - deployment script
#!/usr/bin/env bash
# Exit on error
set -e
# Update git repository with latest
# Arg 1 - repository name
# Arg 2 - source dir
update_git () {
full_path=${2}/${1}
# If directory exists then run git stuff there
if [ -d ${full_path} ]; then
echo "Running 'git pull rebase' for ${full_path}"
cd ${full_path}
status=$(git status|grep "origin/" || true)
if [ -z "$status" ]
then
echo "Using local branch, skipping git pull.."
else
git pull --rebase
fi
else
# Repository does not exist, create it.
mkdir -p $2
echo "Running 'git clone' for $1"
cd $2
git clone git@github.com:Coneuron/${1}.git
fi
}
# update AWS via zappa. Pay attention that the working directory after the function ends is the one you gave as a parameter
# Arg 1 - directory to update
push_to_aws() {
echo "Pushing $1 service to AWS"
cd $1
pip install -r requirements.txt
# If we are running under travis use a different zappa configuration
if [ "$TRAVIS" = "true" ]; then
echo Running under travis
./scripts/deploy.sh update zappa_settings_int.json
service_path=$( zappa status -s zappa_settings_int.json |grep "API Gateway URL"|awk '{print $4}')
else
./scripts/deploy.sh
service_path=$( zappa status -s local_zappa_settings.json |grep "API Gateway URL"|awk '{print $4}')
fi
echo "${repository} is available on ${service_path}"
echo "${repository},${service_path}" >> ${integration_tests}/repositories_addresses.txt
pip uninstall -y -r requirements.txt
}
# Read all local repositories from file and update them
integration_tests=${1:-"$HOME/source/integration_tests"}
repositories_file="${integration_tests}/scripts/repositories.txt"
rm ${integration_tests}/repositories_addresses.txt || true
while read -r repository
do
[[ "repository" =~ ^#.*$ ]] && continue # avoid comments
update_git ${repository} $HOME/source/
push_to_aws $HOME/source/${repository}
done < "${repositories_file}"
cd ${integration_tests}
pip install -r requirements.txt
echo "Ready to start testing, use 'pytest -qs integration_tests.py --repositories repositories_addresses.txt' good luck ! "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment