Add new conditional deploy action that only runs on the master branch

pull/35/head
Starbeamrainbowlabs 4 years ago
parent f7e502a84d
commit d022708bd2
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
  1. 72
      build

72
build

@ -33,6 +33,13 @@ database_name="aq_db";
# Minimum major version of npm
min_npm_version_major="6";
# Deployment settings
deploy_ssh_user="ci";
deploy_ssh_host="www.connectedhumber.org";
deploy_ssh_port="22";
deploy_root_dir="Air-Quality-Web";
###############################################################################
# Check out the lantern git submodule if needed
@ -264,6 +271,12 @@ task_docs() {
task_ci() {
tasks_run setup setup-dev
NODE_ENV="production" tasks_run client docs archive;
if [ "${GIT_REF_NAME}" == "refs/heads/master" ]; then
tasks_run deploy;
else
echo "Not deploying, as this build wasn't on the master branch.";
fi
}
task_archive() {
@ -272,6 +285,65 @@ task_archive() {
}
task_deploy() {
stage_begin "Deploying to ${deploy_ssh_host}....";
if [ "${SSH_KEY_PATH}" == "" ]; then
stage_end 1 "Error: Can't find the SSH key as the environment variable SSH_KEY_PATH isn't set.";
fi
task_begin "Preparing upload";
subtask_begin "Creating temporary directory";
temp_dir="$(mktemp -d --suffix "-rhinoreminds-upload")";
subtask_end $? "Error: Failed to create temporary directory";
subtask_begin "Unpacking release files";
execute tar -xf "${ARCHIVE}/Air-Quality-Web.tar.gz" -C "${temp_dir}";
subtask_end $? "Failed to unpack release files";
# Define the directory whose contents we want to upload
source_upload_dir="${temp_dir}/RhinoReminds-Release";
task_end $?;
task_begin "Uploading release";
# Acquire an exclusive project-wide lock so that we only upload stuff one-at-a-time
exec 9<"${WORKSPACE}";
flock --exclusive 9;
# We have an extra : before the @ here to avoid the password prompt
# Actions:
# 1. Connect to remote server
# 2. Upload new files
# 3. Create data dir symlink
# 4. Swap in new directory
# 5. Delete old directory
lftp << SFTPCOMMANDS
set connect-program 'ssh -x -i "${SSH_KEY_PATH}" -P "${deploy_ssh_port}" -o "PasswordAuthentication=no"';
connect sftp://${deploy_ssh_user}:@${deploy_ssh_host};
mirror -R -P 3 -r ${source_upload_dir}/* "${deploy_root_dir}/www-new";
ln -s "${deploy_root_dir}/data" "${deploy_root_dir}/www-new/data";
mv "${deploy_root_dir}/www" "${deploy_root_dir}/www-old";
mv "${deploy_root_dir}/www-new" "${deploy_root_dir}/www";
rm -r "${deploy_root_dir}/www-old";
bye
SFTPCOMMANDS
exec 9>&- # Close file descriptor 9 and release the lock
task_end $? "Failed to upload release";
task_begin "Cleaning up";
execute rm -r "${temp_dir}";
task_end $?;
stage_end $? "Failed to deploy to ${deploy_ssh_host}.";
}
#########################################################################
tasks_run $@;

Loading…
Cancel
Save