Last active
August 2, 2017 08:35
Revisions
-
jeremyjs revised this gist
Aug 2, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,7 +19,7 @@ APP_NAME="example-app" if [ $ENVIRONMENT = "production" ]; then REMOTE_URL=$PRODUCTION_URL elif [ $ENVIRONMENT = "staging" ]; then REMOTE_URL="$STAGING_URL" else echo -e "\nERROR: unknown environment \"$ENVIRONMENT\"\n" -
jeremyjs revised this gist
Aug 2, 2017 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -40,12 +40,12 @@ echo echo -e "\nbuilding application bundle..." rm -rf /tmp/$APP_NAME.tar.gz meteor build /tmp --architecture os.linux.x86_64 echo -e "copying bundle to remote host $REMOTE_URL...\n" scp /tmp/$APP_NAME.tar.gz $APP_USER@$REMOTE_URL:/tmp/$APP_NAME.tar.gz rm -rf /tmp/$APP_NAME.tar.gz echo -e "deploying to remote host...\n" ssh -T $APP_USER@$REMOTE_URL 'bash -s' << EOF -
jeremyjs created this gist
Aug 2, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ #!/bin/bash set -eo pipefail # TODO: check and perform stash if needed # TODO: save current branch and return after release # git add -A # git stash LATEST_TAG="$(git describe --tags `git rev-list --tags --max-count=1`)" DEPLOY_TAG=${1:-$LATEST_TAG} # TODO: use command line args and flags DEPLOY_ENVIRONMENT="${DEPLOY_ENVIRONMENT:-production}" PRODUCTION_URL="example.com" STAGING_URL="staging.example.com" APP_USER="root" APP_NAME="example-app" if [ $ENVIRONMENT = "production" ]; then REMOTE_URL=$PRODUCTION_URL elif [ $ENVIRONMENT = "staging ]; then REMOTE_URL="$STAGING_URL" else echo -e "\nERROR: unknown environment \"$ENVIRONMENT\"\n" exit 1 fi echo -e "deploying $DEPLOY_TAG to $REMOTE_URL\n" echo "updating git remote refs and checking out master..." git remote update -p git checkout master echo "pushing tags to git remote..." git push --tags echo "checking out deploy tag $DEPLOY_TAG..." git checkout $DEPLOY_TAG echo echo -e "\nbuilding application bundle..." rm -rf /tmp/softexposition.tar.gz meteor build /tmp --architecture os.linux.x86_64 echo -e "copying bundle to remote host $REMOTE_URL...\n" scp /tmp/softexposition.tar.gz softexposition@$REMOTE_URL:/tmp/softexposition.tar.gz rm -rf /tmp/softexposition.tar.gz echo -e "deploying to remote host...\n" ssh -T $APP_USER@$REMOTE_URL 'bash -s' << EOF rm -rf /tmp/bundle cd /tmp/ tar -xzf $APP_NAME.tar.gz sudo cp -rf /tmp/bundle/* /var/www/$APP_NAME/ cd /var/www/$APP_NAME/programs/server && sudo npm install pm2 restart $APP_NAME EOF git checkout master # git stash pop # git reset HEAD This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ #!/usr/bin/env node --harmony const git = require('simple-git')(); const program = require('commander'); const semver = require('semver'); const shell = require('shelljs'); program .usage('-- [-d <env>] [-l <major | minor | patch>] [-t <custom tag name>] [-m <message>]') .description('perform a git tag of the current master branch with a version bump and push') .option('-d, --deploy', 'also deploy <env> to this version, defaulting to production') .option('-l, --level <level>', 'level to bump [major | minor | patch]', /^(major|minor|patch)$/i) .option('-t, --tag-name', 'custom tag name') .option('-m, --message', 'the release tag annotation') .parse(process.argv); if (program.deploy) { console.warn('Warning: `--deploy <env>` not implemented, defaulting to `--deploy production`'); console.warn('Warning: `--deploy` flag suppresses logging'); } const nextVersionTag = (latestTag, level) => { const latestVersion = semver.clean(latestTag); const newVersion = semver.inc(latestVersion, level); return `v${newVersion}`; }; git .checkout('master') .exec(() => { shell.exec('git remote update -p'); }) .pull('origin/master', { '--ff-only': null }) .push('origin', 'master') .tags((err, tags) => { // TODO: exit if the latest tag is even with origin/master const latestTag = tags.latest; const level = program.level || 'patch' const newTag = program.tagName || nextVersionTag(latestTag, level); const tagMessage = program.message || ''; console.log(`Performing ${level} version bump from ${latestTag} to ${newTag}`); if (tagMessage) console.log(tagMessage); git .addAnnotatedTag(newTag, tagMessage) .pushTags('origin') .exec(() => { // TODO: don't suppress logging if (program.deploy) shell.exec('npm run deploy'); }); });