Skip to content

Instantly share code, notes, and snippets.

@simcap
Last active January 27, 2016 17:05
Show Gist options
  • Select an option

  • Save simcap/1e8cc45c3306de7cbfac to your computer and use it in GitHub Desktop.

Select an option

Save simcap/1e8cc45c3306de7cbfac to your computer and use it in GitHub Desktop.
Deploy go appa by convention
#!/bin/sh
if [ -z $1 ]; then
echo "Usage: first argument is the machine alias on which you want to deploy"
exit 1
fi
HOST_ALIAS=$1
PROJECT_NAME=${PWD##*/} # basename of current dir
if ! [ -z $2 ]; then
PROJECT_NAME=$2
fi
echo "Project name is '$PROJECT_NAME'"
if [ -d "pkg" ]; then
rm -r pkg
fi
mkdir pkg
ARTIFACT_NAME=$PROJECT_NAME-`git rev-parse --short HEAD`-`date +%Y-%m-%d`
echo "Go build '$ARTIFACT_NAME' in pkg/"
GOARCH=amd64 GOOS=linux go build -o pkg/$ARTIFACT_NAME .
echo "scp to $HOST_ALIAS"
scp pkg/$ARTIFACT_NAME $HOST_ALIAS:~/goapps/$PROJECT_NAME/
if [ $? -ne 0 ]; then
echo "scp failed"
exit 1
fi
ssh $HOST_ALIAS "cd ~/goapps/$PROJECT_NAME; ln -fs $ARTIFACT_NAME $PROJECT_NAME; sudo service $PROJECT_NAME restart"
if [ $? -ne 0 ]; then
echo "Linking & restart failed"
exit 1
fi
echo "...restarting"
sleep 2
echo `ssh $HOST_ALIAS "sudo tail /var/log/upstart/$PROJECT_NAME.log"`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment