Skip to content
This repository was archived by the owner on Jan 28, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn.lock binary
28 changes: 20 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Webpack deploy utilities
Collection of useful utilities for deploying (not only) Webpack apps

## Deploy
Each deployment into Redis (`deploy-redis`) saves the `index.html` build file under a full SHA key of the current git commit. (e.g. `app:b45ab63a5aaafd35377ca571824e60fe07a52101`) and optionally updates the “tip” commit of a given branch (using the `--branch` argument). Updates to the branch tip are made by storing it’s revision and index under the `app:branch-revision:branchname` and `app:branch:branchname` respectively.

## Activation
There are two steps to activate a deployed build.
1. Activate branch: use `activate-branch --branch branchname` to activate this branch and set the current main build to the tip of this branch. All consecutive activations **inside this branch** will be automatically promoted as the main current build.
2. Activate a revision: use `activate-rev --branch branchname --rev SHA` to activate a given SHA revision inside a given branch and set the revision as the main current build **if that branch has been previously activated**.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need branch here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's how the new setup works. You activate revs inside branches the same way you move a branch tip in Git.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you don't need information about the branch. There isn't a relation between branch and SHA.


## Installation
```
cd $YOUR_PROJECT
Expand All @@ -17,21 +25,25 @@ Build your Webpack project and run `deploy [environment]`.
The script will automatically detect the build hash from `build.log`.

## Commands
- `deploy`
- `deploy [environment]`
Batch command for quick deployment.
- `deploy-s3`
- `deploy-s3 [--env=environment]`
AWS S3 asset upload of build files.
- `deploy-redis`
- `deploy-redis [--env=environment] [--rev=revision] [--branch=branch]`
Redis deployment of revision index html file.
- `activate-rev`
- `activate-rev [--env=environment] [--rev=revision] [--branch=branch] [--notify|-n] [--major|-m] [--confirm]`
Redis activation of deployed revision.
- `list-revs`
- `activate-branch [--env=environment] [--branch=branch] [--confirm]`
Redis activation of deployed branch.
- `current-rev`
Display currently auto-detected revision.
- `list-revs [--env=environment] [--all|-a]`
List of deployed revisions with meta information.
- `rollbar-source-map`
- `rollbar-source-map [--env=environment] [--rev=revision]`
Rollbar source map upload.
- `slack-notify`
- `slack-notify [--env=environment] [--rev=revision]`
Slack channel notifier.
- `git-deploy-tag`
- `git-deploy-tag [--env=environment] [--rev=revision]`
Git tag creation and push to remote.

## Other
Expand Down
4 changes: 4 additions & 0 deletions bin/activate-branch
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env node
var path = require('path');
require(path.join(__dirname, '..', 'tasks', 'activate-branch'));
require('gulp').start('activate-branch');
4 changes: 0 additions & 4 deletions bin/activate-rev

This file was deleted.

32 changes: 20 additions & 12 deletions bin/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
# dont execute next commands on error
trap 'exit' ERR

# colors
RED='\033[0;31m'
YELLOW='\033[0;33m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color

# let echo interpret escape chars (\n)
shopt -s xpg_echo

GULP="`npm bin`/gulp"

if [[ ! -x "$GULP" ]]; then
echo "ERROR: gulp executable not found"
echo "${RED}ERROR: gulp executable not found$NC"
echo "Check path for valid executable: $GULP"
exit 1
fi
Expand All @@ -33,7 +39,7 @@ set_dirname
# ENV is the first parameter, defaults to "staging"
ENV=${1-development}

echo "Environment: $ENV"
echo "Environment: ${YELLOW}$ENV$NC"

case "$ENV" in
production)
Expand Down Expand Up @@ -62,17 +68,17 @@ BRANCH=`git rev-parse --abbrev-ref HEAD`
REV="$COMMIT"
BUILD_COUNT=`ls -a build*log 2>/dev/null | cat | wc -l | awk {'print $1'}`

if [ $BRANCH == "dev" -o $BRANCH == "master" -o $BRANCH == "HEAD" ]; then
echo "Deploying with commit hash $REV\n"
if [ $BRANCH == "HEAD" ]; then
echo "Deploying with commit hash ${YELLOW}$REV$NC\n"
else
REV="branch/$BRANCH"
echo "Deploying branch $BRANCH\n"
REV="$BRANCH"
echo "Deploying revision ${YELLOW}$COMMIT$NC for branch ${YELLOW}$BRANCH$NC\n"
fi

if [[ $BUILD_COUNT -ne 0 ]]; then
echo "Detected $BUILD_COUNT build app versions:"
echo "Detected $BUILD_COUNT build app versions from logs:"
for build in build*log; do
echo "\t`cat "$build" | grep Hash: | head -1 | cut -d' ' -f2`: `echo $build | cut -d'.' -f2`"
echo "\t${YELLOW}`grep Hash: "$build" | head -1 | cut -d' ' -f2`$NC: $build"
done
echo
else
Expand All @@ -85,7 +91,7 @@ gulp_config deploy-s3 --env=$ENV

gulp_config rollbar-source-map --env=$ENV --rev=$COMMIT_ROLLBAR

gulp_config deploy-redis --env=$ENV --rev=$REV
gulp_config deploy-redis --env=$ENV --rev=$COMMIT --branch=$BRANCH

gulp_config git-deploy-tag --env=$ENV --rev=$REV

Expand All @@ -95,6 +101,8 @@ gulp_config slack-notify --env=$ENV --rev=$REV
echo "\nDeploy into $ENV environment took ${SECONDS}s.\n"

echo "TEST with:"
echo "\t$DOMAIN/?rev=$REV"
echo "THEN to activate run:"
echo "\tactivate-rev --notify --env=$ENV --rev=$REV\n"
echo "\t$DOMAIN/?rev=$REV\n"
echo "To activate the branch (auto updated revision with every branch deploy):"
echo "\t${CYAN}activate-branch --env=$ENV --branch=$BRANCH --notify$NC\n"
echo "To activate the commit:"
echo "\t${CYAN}activate-rev --env=$ENV --rev=$COMMIT --branch=$BRANCH --notify$NC\n"
Copy link
Copy Markdown
Contributor Author

@LeZuse LeZuse Jul 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't really allow that in the current version. We should change the wording a bit.

4 changes: 4 additions & 0 deletions bin/update-branch
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env node
var path = require('path');
require(path.join(__dirname, '..', 'tasks', 'update-branch'));
require('gulp').start('update-branch');
54 changes: 28 additions & 26 deletions deploy-config-example.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
var secrets = require('./secrets.js');

var s3Credential = {
accessKeyId: secrets.s3.accessKeyId,
accessKeyId: secrets.s3.accessKeyId,
secretAccessKey: secrets.s3.secretAccessKey,
params: {
Bucket: 'productboard-assets'
}
Bucket: 'productboard-assets',
},
};

var config = {

redis: {
development: {
port: 6379,
host: 'localhost',
db: 1,
options: { },
options: {},
indexPath: 'dist/index.html',
indexKey: 'app:%s',
metaKey: 'meta:%s',
indexKey: 'app:%s', // revision
branchKey: 'app:branch:%s', // branch name
branchRevKey: 'app:branch-revision:%s', // branch name
metaKey: 'meta:%s', // revision
mainBranchKey: 'app:current-branch',
mainIndexKey: 'app:current',
mainRevKey: 'app:current-revision',
revTimestampKey: 'app-timestamp:%s',
lastMajorTimestampKey: 'app:last-major-timestamp',
revTimestampKey: 'app-timestamp:%s', // revision
lastMajorTimestampKey: 'app:admin:last-major-timestamp:%s', // branch name
},
staging: {
port: 9999,
db: 0,
host: 'pub-redis-9999.us-east-1-1.2.ec2.garantiadata.com',
port: 9999,
db: 0,
host: 'pub-redis-9999.us-east-1-1.2.ec2.garantiadata.com',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this good idea to have those URL in the repository?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything that's not supposed to be in the repo can be in the secrets.js file. I'd leave it up to the library user which parts they consider to be a secret :)

options: { auth_pass: secrets.redis.staging.auth_pass },
indexPath: 'dist/index.html',
indexKey: 'app:%s',
Expand All @@ -38,9 +40,9 @@ var config = {
lastMajorTimestampKey: 'app:last-major-timestamp',
},
me: {
port: 8888,
db: 0,
host: 'pub-redis-8888.us-east-1-3.3.ec2.garantiadata.com',
port: 8888,
db: 0,
host: 'pub-redis-8888.us-east-1-3.3.ec2.garantiadata.com',
options: { auth_pass: secrets.redis.me.auth_pass },
indexPath: 'dist/index.html',
indexKey: 'app:%s',
Expand All @@ -51,9 +53,9 @@ var config = {
lastMajorTimestampKey: 'app:last-major-timestamp',
},
production: {
port: 7777,
db: 0,
host: 'pub-redis-7777.us-east-1-1.2.ec2.garantiadata.com',
port: 7777,
db: 0,
host: 'pub-redis-7777.us-east-1-1.2.ec2.garantiadata.com',
options: { auth_pass: secrets.redis.production.auth_pass },
indexPath: 'dist/index.html',
indexKey: 'app:%s',
Expand All @@ -62,7 +64,7 @@ var config = {
mainRevKey: 'app:current-revision',
revTimestampKey: 'app-timestamp:%s',
lastMajorTimestampKey: 'app:last-major-timestamp',
}
},
},

s3: {
Expand All @@ -86,7 +88,7 @@ var config = {
credentials: s3Credential,
dirname: '/development/assets',
assetsPath: 'dist/assets/*',
}
},
},

rollbar: {
Expand All @@ -107,17 +109,19 @@ var config = {
sourceMapPath: 'dist/assets/main-%s.map',
accessToken: secrets.rollbar.production.accessToken,
abbrev: 7,
}
},
},

slack: {
staging: {
url: 'https://staging.example.com',
notifyWebHook: 'https://hooks.slack.com/services/XXXXYYYY/ZZZZUUUUU/asdjLJFHLFJKHLDJKFHDdfdh',
notifyWebHook:
'https://hooks.slack.com/services/XXXXYYYY/ZZZZUUUUU/asdjLJFHLFJKHLDJKFHDdfdh',
},
production: {
url: 'https://www.example.com',
notifyWebHook: 'https://hooks.slack.com/services/ZZZZYYYY/ZZZZTTTTT/asdjLJFHLFJKHLDJKFHDdfdh',
notifyWebHook:
'https://hooks.slack.com/services/ZZZZYYYY/ZZZZTTTTT/asdjLJFHLFJKHLDJKFHDdfdh',
},
},

Expand All @@ -126,10 +130,8 @@ var config = {
url: 'https://staging.example.com',
remote: 'origin',
abbrev: 7,
}
},
},

};

module.exports = config;

Loading