forked from fuseumass/dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·174 lines (151 loc) · 5.58 KB
/
deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
cat << "EOF"
---------------------------------------------------------------
______ __ __ __ ___
/ ____/__ __ _____ ___ / / / // |/ /____ _ _____ _____
/ /_ / / / // ___// _ \ / / / // /|_/ // __ `// ___// ___/
/ __/ / /_/ /(__ )/ __// /_/ // / / // /_/ /(__ )(__ )
/_/ \__,_//____/ \___/ \____//_/ /_/ \__,_//____//____/
____ __ __ __
/ __ \ ____ _ _____ / /_ / /_ ____ ____ _ _____ ____/ /
/ / / // __ `// ___// __ \ / __ \ / __ \ / __ `// ___// __ /
/ /_/ // /_/ /(__ )/ / / // /_/ // /_/ // /_/ // / / /_/ /
/_____/ \__,_//____//_/ /_//_.___/ \____/ \__,_//_/ \__,_/
---------------------------------------------------------------
EOF
echo ' '
echo 'Are you ready to deploy?'
CONFIG_NAME=$(cat hackathon-config/hackathon.yml | head -n 1 | cut -d ':' -f 2)
if [[ "$CONFIG_NAME" == " RedPandaHacks" ]]; then
echo ""
echo "WARNING! You are about to deploy with the example configuration repository"
echo "(github.com/hackumass/redpandahacks-config). Are you sure you want to do this?"
echo "For instructions on how to provide your own configuration repository, read the"
echo "Dashboard Wiki (github.com/hackumass/dashboard/wiki)."
else
echo "Deploying with the$CONFIG_NAME configuration repository."
fi
echo -n 'Enter the Heroku name of the application: '
read heroku_name
echo "Heroku app name: $heroku_name"
echo ' '
echo "Preparing for deployment to $heroku_name....."
echo "Fetching remote heroku-$heroku_name"
git fetch "heroku-$heroku_name"
if [[ "$?" != "0" ]]; then
echo "Git remote doesn't exist. Do you want to add a new deployment target? (type y or n)"
read ok
if [[ $ok = 'y' ]]; then
git remote add "heroku-$heroku_name" "https://git.heroku.com/$heroku_name.git"
if [[ "$?" != "0" ]]; then
echo 'Exiting. Unable to add git remote.'
exit 1
else
echo "Successfully added git remote heroku-$heroku_name for heroku instance $heroku_name"
git fetch "heroku-$heroku_name"
fi
else
echo 'Exiting.'
exit 1
fi
fi
echo ' '
# Asset precompilation
echo 'Precompiling Assets...'
./docker_shell.sh bundle exec rake assets:precompile
if [[ "$?" != "0" ]]; then
echo 'Failed. Ensure Docker is running and restart the script.'
echo 'Do you want to rerun without Docker? Rails, bundle, and rake must be installed. (y or n)'
read rerun
if [[ $rerun = 'y' ]]; then
echo 'Precompiling Assets...'
bundle exec rake assets:precompile
if [[ "$?" != "0" ]]; then
echo 'Failed. Exiting.'
exit 1
fi
else
echo 'Exiting.'
exit 1
fi
fi
echo 'Assets precompiled succesfully ✅'
echo ' '
echo 'Checking git submodule configuration...'
SUBMOD_URL=`git config --file=.gitmodules submodule.hackathon-config.url`
SUBMOD_CHANGED=0
if [[ $SUBMOD_URL == [email protected]:* ]]; then
echo 'Modifying git submodule to have https URL. The repository will need to be public.'
git config --file=.gitmodules submodule.hackathon-config.url `echo $SUBMOD_URL|sed 's/[email protected]:/https:\/\/github.com\//g'`
echo 'Updated git submodule URL. Running sync and update...'
git submodule sync
git submodule update --init --recursive --remote
echo 'Submodule changes done.'
SUBMOD_CHANGED=1
fi
# Committing Assets
echo 'Committing precompiled assets and submodule config temporarily....'
echo 'Warning: any non-committed or untracked files will be included in the Heroku deploy.'
git add .
git commit --allow-empty -m "Assets precompiled with submodule"
# Pushing build to Heroku
echo ' '
echo 'Pushing build to Heroku....'
git push -f "heroku-$heroku_name" master
echo ' '
echo 'Heroku Build Successful ✅'
echo ' '
if [[ $SUBMOD_CHANGED = 1 ]]; then
echo 'Reverting git submodule to old URL....'
git config --file=.gitmodules submodule.hackathon-config.url $SUBMOD_URL
echo 'Fixed git submodule URL. Running sync and update...'
git submodule sync
git submodule update --init --recursive --remote
echo 'Submodule URL fixed.'
echo ' '
fi
# Undo precompile commit
echo 'Undoing precompile commit'
git reset HEAD~1
echo 'Undone.'
echo ' '
echo 'Do you want to push non-submodule code changes to GitHub? If you have cloned the'
echo 'fuseumass/dashboard repo directly, then this will only work for UMass tech team members. (type y or n)'
read gitpush
if [[ $gitpush = 'y' ]]; then
echo 'Running git push'
git push
else
echo 'Not pushing to GitHub'
fi
# Migrations
echo 'Do you want to migrate the production database? (type y or n)'
read migrate
if [[ $migrate = 'y' ]]; then
echo 'Application entering maintenance mode...'
heroku maintenance:on -a $heroku_name
echo ' '
echo 'Migrating databases....'
heroku run rake db:migrate -a $heroku_name
echo ' '
echo 'Database Migration Successful ✅'
echo ' '
echo 'Application exiting maintenance mode...'
heroku maintenance:off -a $heroku_name
echo ' '
else
echo 'Skipping maintenance mode. No migrations found. ✅'
fi
# Feature flag updates
echo 'Do you want to update the feature flag? (type y or n)'
read fflag
if [[ $fflag = 'y' ]]; then
echo 'Running feature flag script...'
heroku run rake feature_flags:load_flags -a $heroku_name
echo ' '
echo 'Feature flags successfully added to database ✅'
echo ' '
else
echo 'Skipping feature flag script ✅'
fi
# All good!
echo 'HackUMass Web App Has Been Deployed ✅'