Skip to content

Commit be441ae

Browse files
committed
Deploy script
1 parent 9aedd8a commit be441ae

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

‎bin/deploy‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bash
2+
3+
# This is a script used to deploy the app. After the git repository is updated, this script is
4+
# executed in order to complete the deployment. Feel free to customize with wild abandon. This
5+
# script is executed as root. Thus, it is critically important to sudo untrusted commands.
6+
# Anything from the app should be considered untrusted.
7+
8+
# If any simple command fails, halt the script.
9+
set -e
10+
11+
# Environment variables available to you:
12+
# BASE_DIR - base location for the application (usually /srv/app_name)
13+
# GIT_DIR - location of the app's main git dir
14+
# RAILS_ENV - the environment (production, staging, etc.)
15+
# APP_USER - the user (and group) for the application
16+
17+
TIME=`date +%s`
18+
RELEASE_DIR=$BASE_DIR/releases/$TIME
19+
CURRENT_DIR=$BASE_DIR/current
20+
21+
# We start by copying this directory into a releases directory.
22+
cp -R $GIT_DIR $RELEASE_DIR
23+
24+
# Now symlink configuration
25+
ln -s /srv/javascriptcom/shared/config/* $RELEASE_DIR/config/
26+
27+
# Make the tmp dir
28+
mkdir -p $RELEASE_DIR/tmp
29+
30+
# Make the app own it
31+
chown -R $APP_USER:$APP_USER $RELEASE_DIR
32+
33+
# Run whatever rake tasks this app requires. Generally tasks should follow the the following
34+
# pattern: 'sudo -i -u $APP_USER RAILS_ENV=$RAILS_ENV the_command'. Commands should only be
35+
# executed outside sudo for very, very good reason.
36+
37+
su $APP_USER -l -c '[ -s "/usr/local/nvm/nvm.sh" ] && . "/usr/local/nvm/nvm.sh" ; cd $RELEASE_DIR ; npm install'
38+
su $APP_USER -l -c '[ -s "/usr/local/nvm/nvm.sh" ] && . "/usr/local/nvm/nvm.sh" ; cd $RELEASE_DIR ; mkdir tmp"'
39+
40+
# Symlink the app
41+
rm -f $CURRENT_DIR
42+
ln -sf $RELEASE_DIR $CURRENT_DIR
43+
44+
# Restart the app
45+
touch $RELEASE_DIR/tmp/restart.txt

0 commit comments

Comments
 (0)