-
Notifications
You must be signed in to change notification settings - Fork 0
/
dupper.hjson
198 lines (176 loc) · 5.54 KB
/
dupper.hjson
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
{
ports:
[
"9418:9418", // sync daemon
"2222:22", // ssh
"8080:8080", // node-inspector
"3000:3000" // default expressjs port
],
env:
[
"NODE_ENV=development",
"PORT=3000"
],
dependencies:
[
{
name: "linux-dependencies",
cmd:
'''
apt-get install -y curl sudo inotify-tools openssh-server jq wget daemon mongodb
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
apt-get -y install nodejs
'''
},
{
name: "hub",
cmd:
'''
cd tmp
wget https://github.com/github/hub/releases/download/v2.3.0-pre8/hub-linux-amd64-2.3.0-pre8.tgz
tar -xvzf hub-linux-amd64-2.3.0-pre8.tgz
cp ./hub-linux-amd64-2.3.0-pre8/bin/hub /usr/local/bin/
'''
},
{
name: "sync",
cmd:
'''
curl -sSL https://get.dupper.co/dev/index | sh
'''
},
{
name: "nodejs-dependencies",
cmd:
'''
npm install -g bower gulp node-inspector
cd $REPO_ROOT
npm install
''',
watch: "package.json"
}
],
commands: {
sync: [{
server:
'''
if [ ! -f $HOME/.ssh/sync ]
then
mkdir -p $HOME/.ssh
ssh-keygen -q -t rsa -N "" -f "$HOME/.ssh/sync"
cat "$HOME/.ssh/sync.pub" >> $HOME/.ssh/authorized_keys
fi
PRIVATEKEY="$(cat $HOME/.ssh/sync)"
_export PRIVATEKEY
# Remove all occurances of .gut & .gutignore
sed -i 's/^.gut$//g' .gitignore
sed -i 's/^.gutignore$//g' .gitignore
# Remove trailing blank lines
sed -i -e :a -e '/^\n*$/{$d;N;};/\n$/ba' .gitignore
# Copy .gitignore to .gutignore to avoid syncing to client.
cp $REPO_ROOT/.gitignore $REPO_ROOT/.gutignore
# Now add .gut & .gutignore to .gitignore
echo ".gut" >> $REPO_ROOT/.gitignore
echo ".gutignore" >> $REPO_ROOT/.gitignore
ulimit -n 9999
service ssh status > /dev/null 2>&1
if [[ $? -ne 0 ]]
then
service ssh start
fi
'''
},{
client:
'''
_verbose=0
_path=""
while [ "$#" -gt 0 ]
do
opt="$1"
shift
case "$opt" in
--verbose|-v)
_verbose=1
;;
*)
if [[ -z $_path ]]
then
_path="$opt"
fi
;;
esac
done
if [[ $_path == "" ]]
then
echo "Usage: dupper exec -t $REPO_NAME sync [--verbose | -v] PATH"
exit 1
fi
set +e
command -v "dev" > /dev/null 2>&1
if [[ $? -ne 0 ]]; then
curl -sSL https://get.dupper.co/dev/index | sudo sh
fi
mkdir -p $HOME/.ssh
echo "$PRIVATEKEY" > $HOME/.ssh/sync
mkdir -p $_path
ulimit -n 9999
dev sync $([[ $_verbose -eq 1 ]] && echo "-v") -i $HOME/.ssh/sync root@$SERVER_IP:2222:$REPO_ROOT $_path
'''
}],
pull-request: [{
server:
'''
set -e
cd $REPO_ROOT
_CONFIGFILE="$HOME/.sync"
if [[ $(git config remote.origin.forked) == "" ]]; then
printf "Username for 'https://github.com': "
read GITHUB_USER
export GITHUB_USER
echo "GITHUB_USER=$GITHUB_USER" > $_CONFIGFILE
printf "Password for 'https://[email protected]':"
read -s GITHUB_PASSWORD
export GITHUB_PASSWORD
printf "\n"
user_json="$(curl -sSL -u $GITHUB_USER:$GITHUB_PASSWORD https://api.github.com/user | jq .)"
set +e
git config --global --unset-all user.email
git config --global --unset-all user.name
set -e
git config --global user.email "$(echo "$user_json" | jq -r .email)"
git config --global user.name "$(echo "$user_json" | jq -r .name)"
local GITHUB_REPO=$(basename "${REPO_URL%.git}" | tr '[:upper:]' '[:lower:]')
hub fork
hub remote remove $GITHUB_USER
hub remote add $GITHUB_USER https://github.com/$GITHUB_USER/$GITHUB_REPO.git
echo "https://${GITHUB_USER}:${GITHUB_PASSWORD}@github.com/$GITHUB_USER/$GITHUB_REPO.git" > ~/.git-credentials
git config remote.origin.forked 1
fi
[ -f $_CONFIGFILE ] && GITHUB_USER=$(source $_CONFIGFILE; echo $GITHUB_USER)
if [[ -z $GITHUB_USER ]]
then
printf "Username for 'https://github.com': "
read GITHUB_USER
echo "GITHUB_USER=$GITHUB_USER" >> $_CONFIGFILE
fi
[ -f $_CONFIGFILE ] && _BRANCH=$(source $_CONFIGFILE; echo $BRANCH)
if [[ $_BRANCH == "" ]]; then
_BRANCH="${GITHUB_USER}_$RANDOM"
echo "BRANCH=$_BRANCH" >> $_CONFIGFILE
fi
set +e
hub add -A
hub commit
set -e
if [[ $(git config remote.origin.pr-created) == "" ]]; then
hub checkout -b $_BRANCH
hub push $GITHUB_USER $_BRANCH
hub pull-request
git config remote.origin.pr-created 1
else
hub push $GITHUB_USER $_BRANCH
fi
'''
}]
}
}