Current section
Files
Jump to
Current section
Files
priv/templates/bin/deploy.sh.eex
#!/bin/sh
# File autogenerated by mix horizon.init (source: deploy.sh.eex)
#
# Calls `deploy_script-my_app.sh` on the target host.
# The deploy_script is expected to be on the local host.
# The script is located in the build folder for each `bin_path` and release.
#
# Example
#
# ./bin/deploy-my_app.sh [-u user] [-h host]
#
#
set -eu
# Default deployment user and host
DEPLOY_USER="<%= @deploy_user %>"
DEPLOY_HOST="<%= @deploy_host %>"
APP_PATH="<%= @app_path %>"
APP="<%= @app %>"
# Parse arguments
while getopts "u:h:" opt; do
case $opt in
u) DEPLOY_USER=$OPTARG ;;
h) DEPLOY_HOST=$OPTARG ;;
*)
echo "Usage: $0 [-u user] [-h host]"
exit 1
;;
esac
done
shift $((OPTIND - 1))
if [ $# -gt 0 ]; then
echo "Usage: $0 [-u user] [-h host]"
exit 1
fi
release=$(cat "<%= @releases_path %>/$APP.data")
scp "<%= @releases_path %>/$release" "${DEPLOY_USER}@${DEPLOY_HOST}:/tmp/$APP.tar.gz"
# Define the installation script and arguments
INSTALL_SCRIPT="<%= @bin_path %>/deploy_script-<%= @app %>.sh"
INSTALL_ARGS="$APP $APP_PATH $release"
# Run the deploy script on the remote host
ssh "${DEPLOY_USER}@${DEPLOY_HOST}" "sh -s -- $INSTALL_ARGS" <"$INSTALL_SCRIPT"
GREEN='\033[0;32m'
RED='\033[0;31m'
RESET='\033[0m'
if [ $? -eq 0 ]; then
printf "${GREEN}Deployment to ${DEPLOY_HOST} successful.${RESET}\n"
else
printf "${RED}Deployment failed.${RESET}\n"
exit 1
fi