Skip to content

Commit

Permalink
Move deploy into a script
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathonsim committed Jan 15, 2018
1 parent 2162a0a commit 42668c2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
32 changes: 1 addition & 31 deletions buildspec-4-sftpdeploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,37 +77,7 @@ phases:
- aws s3 sync --delete coverage/ "s3://${COVERAGE_S3_BUCKET}/coverage"

# Deployment to the SFTP server
- |
set -e
cat /codebuild/output/tmp/script.sh
# Determine what git branch we're on, we only want to deploy master
export CODEBUILD_GIT_BRANCH=`git symbolic-ref HEAD --short 2>/dev/null`
if [ "$CODEBUILD_GIT_BRANCH" == "" ] ; then
CODEBUILD_GIT_BRANCH=`git branch -a --contains HEAD | sed -n 2p | awk '{ printf $1 }'`
export CODEBUILD_GIT_BRANCH=${CODEBUILD_GIT_BRANCH#remotes/origin/}
fi
echo "On branch $CODEBUILD_GIT_BRANCH"
if [ "$CODEBUILD_GIT_BRANCH" != 'master' ]; then
echo "On branch $CODEBUILD_GIT_BRANCH ; not deploying as not master"
exit 0
fi
# Install SSH client so we can deploy
apt-get install -y openssh-client rsync
# Setup the SSH key
mkdir ~/.ssh
chmod 700 ~/.ssh
echo $SSH_KEY | base64 -d > ~/.ssh/id_rsa
chmod 600 ~/.ssh/*
# Upload Files
rsync -arvce --delete-after "ssh -o StrictHostKeyChecking=no -p ${SFTP_PORT}" . ${SSH_USERNAME}@${SSH_SERVER}:~/public_html/
# Run any necessary remote commands
ssh -o "StrictHostKeyChecking=no" ${SSH_USERNAME}@${SSH_SERVER} -p ${SSH_PORT} 'cd public_html ; composer install --optimize-autoloader; php artisan migrate'
- ./codebuild-deploy.sh

cache:
paths:
Expand Down
30 changes: 30 additions & 0 deletions codebuild-deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -e

# Determine what git branch we're on, we only want to deploy master
export CODEBUILD_GIT_BRANCH=`git symbolic-ref HEAD --short 2>/dev/null`
if [ "$CODEBUILD_GIT_BRANCH" == "" ] ; then
CODEBUILD_GIT_BRANCH=`git branch -a --contains HEAD | sed -n 2p | awk '{ printf $1 }'`
export CODEBUILD_GIT_BRANCH=${CODEBUILD_GIT_BRANCH#remotes/origin/}
fi

echo "On branch $CODEBUILD_GIT_BRANCH"
if [ "$CODEBUILD_GIT_BRANCH" != 'master' ]; then
echo "On branch $CODEBUILD_GIT_BRANCH ; not deploying as not master"
exit 0
fi

# Install SSH client so we can deploy
apt-get install -y openssh-client rsync

# Setup the SSH key
mkdir ~/.ssh
chmod 700 ~/.ssh
echo $SSH_KEY | base64 -d > ~/.ssh/id_rsa
chmod 600 ~/.ssh/*

# Upload Files
rsync -arvce --delete-after "ssh -o StrictHostKeyChecking=no -p ${SFTP_PORT}" . ${SSH_USERNAME}@${SSH_SERVER}:~/public_html/

# Run any necessary remote commands
ssh -o "StrictHostKeyChecking=no" ${SSH_USERNAME}@${SSH_SERVER} -p ${SSH_PORT} 'cd public_html ; composer install --optimize-autoloader; php artisan migrate'

0 comments on commit 42668c2

Please sign in to comment.