1 | Go Go Go
|
2 | ========
|
3 |
|
4 | Gogogo is a simple command-line tool for easily deploying command-line
|
5 | applications. It puts files into place on any server with upstart and gets it
|
6 | all configured.
|
7 |
|
8 | ### Goals
|
9 |
|
10 | 1. Easy to setup
|
11 | 2. Easy to redeploy
|
12 | 3. Deploy to multiple servers
|
13 | 4. Deploy different branches to the same server
|
14 |
|
15 | Installation
|
16 | ------------
|
17 |
|
18 | npm -g install gogogo
|
19 |
|
20 | Change Log
|
21 | ----------
|
22 |
|
23 | * 0.5.0 - Add ability to support running multiple processes in one deploy
|
24 | target
|
25 | * 0.4.10 - Add a command to run a command on the server, plus colorized output
|
26 | * 0.4.8 - automatically add logrotate files, make upstart work properly on
|
27 | reboot
|
28 | * 0.4.3 - added support for local deploys, and sudo for non-root users (see
|
29 | note below)
|
30 | * 0.4.0 - Added support for tracking support history, plugins, and a chef
|
31 | plugin
|
32 | * 0.3.3 - multi cron support, plus per-layer config
|
33 | * 0.3.0 - custom config file, cron support
|
34 | * 0.2.6 - git push force
|
35 | * 0.2.5 - Server Environment variables are preserved! Deploy monitors the log
|
36 | for a couple seconds.
|
37 | * 0.2.0 - gogogo list, logs, start, stop, restart, deploy
|
38 |
|
39 | Server Requirements
|
40 | -------------------
|
41 |
|
42 | 1. Upstart (included with ubuntu)
|
43 | 2. SSH Access
|
44 | 3. Git installed on both local computer and server
|
45 | 4. for non-root users, sudo must work without a password
|
46 |
|
47 | Usage
|
48 | -----
|
49 |
|
50 | In your local repo
|
51 |
|
52 | 1. `ggg init`
|
53 |
|
54 | 2. edit ggg.js:
|
55 |
|
56 | ``` JavaScript
|
57 | module.exports = {
|
58 | // services
|
59 | // can either be a string or an object with mutiple processes to start up
|
60 | start: "node app.js",
|
61 | /* or
|
62 | start: {
|
63 | web: 'node app.js',
|
64 | worker 'node worker.js',
|
65 | montior: 'node monitor.js'
|
66 | },
|
67 | */
|
68 |
|
69 | // install
|
70 | install: "npm install",
|
71 |
|
72 | // cron jobs (from your app folder)
|
73 | cron: {
|
74 | someTask: { time: "0 3 * * *", command: "node sometask.js"},
|
75 | },
|
76 |
|
77 | // targets to deploy to
|
78 | servers: {
|
79 | dev: "deploy@dev.mycompany.com",
|
80 | staging: ["deploy@staging.mycompany.com", "deploy@staging2.mycompany.com"],
|
81 | prod: {
|
82 | hosts: ["deploy@mycompany.com", "deploy@backup.mycompany.com"],
|
83 | cron: {
|
84 | someTask: {time: "0 3 * * *", command: "node sometask.js"},
|
85 | anotherTask: {time: "0 3 * * *", command: "node secondTask.js"}
|
86 | },
|
87 | start: "prodstart app.js"
|
88 | }
|
89 | }
|
90 | }
|
91 | ```
|
92 |
|
93 | 3. ggg deploy dev master
|
94 |
|
95 | ### Redeploy
|
96 |
|
97 | # change some stuff and commit
|
98 | ...
|
99 |
|
100 | # deploy again
|
101 | ggg deploy test master
|
102 |
|
103 |
|
104 | Limitations
|
105 | -----------
|
106 |
|
107 | 1. Only works on ubuntu (requires upstart to be installed)
|
108 | 2. You must change the port in either the code or an environment variable to
|
109 | run the same app twice on the same server
|
110 |
|
111 | Roadmap
|
112 | -------
|
113 |
|
114 | * Clean up cron files when removing a cronjob after a deploy
|
115 |
|
116 | Help
|
117 | ----
|
118 |
|
119 | ### Actions
|
120 |
|
121 | ```bash
|
122 | ggg help
|
123 | ggg init - creates a ggg.js config file for you
|
124 | ggg deploy <target> <branch> — deploys branch to named server
|
125 | ggg restart <target:process>
|
126 | ggg start <target:process>
|
127 | ggg stop <target:process>
|
128 | ggg logs <target:process> — tail remote log
|
129 | ggg list — show available names
|
130 | ggg history <target> - shows a history of deployed commits
|
131 | ggg command <target> <command> - run a command on the server in base directory
|
132 | ```
|
133 |
|
134 | gogogo is aliased to ggg for SWEET EFFICIENCY
|
135 |
|
136 | ### Cron Support
|
137 |
|
138 | gogogo can create cron jobs for you on deploy.
|
139 |
|
140 | ``` JavaScript
|
141 | module.exports = {
|
142 | cron: {
|
143 | cronName: {time: "0 3 * * *" command: " node something.js"}
|
144 | }
|
145 | }
|
146 | ```
|
147 |
|
148 | It will create a script in /etc/cron.d/, set the permissions correctly, and
|
149 | redirect log output to `cron_cronName.log`.
|
150 |
|
151 | You can have multiple cron commands by having multiple keys in the cron object:
|
152 |
|
153 | ```JavaScript
|
154 | module.exports = {
|
155 | cron: {
|
156 | cronName: {time: "0 3 * * *" command: "node something.js"},
|
157 | anotherCron: {time: "0 1 * * *" command: "node somethingElse.js"}
|
158 | }
|
159 | }
|
160 | ```
|
161 |
|
162 | gogogo isn't smart enough yet to remove old cron files it created when you
|
163 | change or remove cronjobs, so you'll have to do that yourself now.
|
164 |
|
165 | ### Multiple processes under one deploy target
|
166 |
|
167 | gogogo supports running multiple processes under one deploy target. Let's look
|
168 | at an example.
|
169 |
|
170 | If the value of the `start` property is a string, your target will only have
|
171 | one process. You can start, stop, restart and log it by running
|
172 | `ggg <start|stop|logs|restart> <target>`.
|
173 |
|
174 |
|
175 | ```JavaScript
|
176 | module.exports = {
|
177 | start: 'echo "foo"'
|
178 | }
|
179 | ```
|
180 |
|
181 | If the value of the `start` property is an object, your target will have
|
182 | multiple processes associated with it. Check out an example ggg.js file.
|
183 |
|
184 | ```JavaScript
|
185 | module.exports = {
|
186 | servers: {
|
187 | prod: {
|
188 | hosts: ["deploy@mycompany.com", "deploy@backup.mycompany.com"],
|
189 | install: "npm install",
|
190 | start: {
|
191 | web: 'echo "starting web"',
|
192 | worker: 'echo "starting worker"',
|
193 | monitor: 'echo "starting monitor"'
|
194 | }
|
195 | }
|
196 | }
|
197 | }
|
198 | ```
|
199 |
|
200 | Here we define one target, `prod`, with three processes. Each process gets its
|
201 | own upstart script, log file, and logrotate file. Deploying will restart all
|
202 | three processes at once. If you run `ggg prod <stop|restart|start>` gogogo will
|
203 | stop|restart|start all three processes at once.
|
204 |
|
205 | You can start, stop, restart or log individual processes by running
|
206 | `ggg <command> prod:<processName>`. If you wanted to restart the web process,
|
207 | you would run `ggg restart prod:web`
|
208 |
|
209 | ### Plugins
|
210 |
|
211 | Plugins allow you to manipulate fields in the ggg.js file at runtime.
|
212 |
|
213 | gogogo plugins override a single deploy parameter (such as hosts) and are a
|
214 | simple file that exports a single function with the following signature:
|
215 |
|
216 | ``` JavaScript
|
217 | module.exports = function(opts, cb) {
|
218 | cb(err, overrides)
|
219 | }
|
220 | ```
|
221 | where opts is a hash of user definied options, and overrides is the value to
|
222 | replace the field with.
|
223 |
|
224 |
|
225 | Currently, there is one bundled plugin, chefHosts, which integrates with
|
226 | opscode's knife to retrieve a list of servers to deploy to. An example of using
|
227 | a plugin is shown below.
|
228 |
|
229 | ``` JavaScript
|
230 | plugins: {
|
231 | "chefHosts" : {
|
232 | overrides: "hosts", // required field! defines the property to override
|
233 | opts: {
|
234 | role: "myapp",
|
235 | env: "production"
|
236 | }
|
237 | },
|
238 | "./plugins/myPlugin" { // user plugins are supported, relative to cwd
|
239 | overrides: "install"
|
240 | }
|
241 | },
|
242 | ```
|
243 |
|
244 | ### Multiple servers
|
245 |
|
246 | To deploy to multiple servers, just add multiple servers to the config file
|
247 |
|
248 | ``` JavaScript
|
249 | // ggg.js
|
250 | module.exports = {
|
251 | servers: {
|
252 | dev: "deploy@dev.mycompany.com",
|
253 | staging: "deploy@staging.mycompany.com"
|
254 | }
|
255 | }
|
256 | ```
|
257 |
|
258 | Then deploy to them separately
|
259 |
|
260 | gogogo deploy dev master
|
261 | gogogo deploy staging master
|
262 |
|
263 | ### Multiple branches on the same server
|
264 |
|
265 | You can deploy any branch over your old remote by pushing to it. To have
|
266 | multiple versions of an app running at the same time, call `ggg create`
|
267 | with different names and the same server.
|
268 |
|
269 | ``` JavaScript
|
270 | // ggg.js
|
271 | module.exports = {
|
272 | servers: {
|
273 | dev: "deploy@dev.mycompany.com",
|
274 | featurex: "deploy@dev.mycompany.com"
|
275 | }
|
276 | }
|
277 | ```
|
278 |
|
279 | Then deploy to them separately
|
280 |
|
281 | ggg deploy dev master
|
282 | ggg deploy featurex featurex
|
283 |
|
284 | Note that for web servers you'll want to change the port in your featurex
|
285 | branch or it will conflict.
|
286 |
|
287 | ### Deploying without start
|
288 | If you want to deploy code without having to run anything (such as machines
|
289 | that only do cron) just don't define a start command or override it with an
|
290 | empty string.
|
291 |
|
292 | ### SSH key host checking warning
|
293 | SSH is run with host key checking disabled. It's up to you to verify the
|
294 | authenticity of your hosts.
|