1 | # Shipit
|
2 |
|
3 | [![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/shipitjs/shipit?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
4 |
|
5 | [![Build Status](https://travis-ci.org/shipitjs/shipit.svg?branch=master)](https://travis-ci.org/shipitjs/shipit)
|
6 | [![Dependency Status](https://david-dm.org/shipitjs/shipit.svg?theme=shields.io)](https://david-dm.org/shipitjs/shipit)
|
7 | [![devDependency Status](https://david-dm.org/shipitjs/shipit/dev-status.svg?theme=shields.io)](https://david-dm.org/shipitjs/shipit#info=devDependencies)
|
8 | [![Inline docs](http://inch-ci.org/github/shipitjs/shipit.svg?branch=master)](http://inch-ci.org/github/shipitjs/shipit)
|
9 |
|
10 | ![Shipit logo](https://cloud.githubusercontent.com/assets/266302/3756454/81df9f46-182e-11e4-9da6-b2c7a6b84136.png)
|
11 |
|
12 | Shipit is an automation engine and a deployment tool written for node / iojs.
|
13 |
|
14 | Shipit was built to be a Capistrano alternative for people who don't know ruby, or who experienced some issues with it. If you want to write tasks in JavaScript and enjoy the node ecosystem, Shipit is also for you.
|
15 |
|
16 | You can automate anything with Shipit but most of the time you will want to deploy your project using
|
17 | the [Shipit deploy task](https://github.com/shipitjs/shipit-deploy-task).
|
18 |
|
19 | **Features:**
|
20 |
|
21 | - Full JavaScript (all npm package availables)
|
22 | - Task flow based on [orchestrator](https://github.com/orchestrator/orchestrator) ([gulp](http://gulpjs.com/) core)
|
23 | - [Official deploy task](https://github.com/shipitjs/shipit-deploy)
|
24 | - Login and interactive SSH commands
|
25 | - Easily extendable
|
26 |
|
27 | ## Install
|
28 |
|
29 | ### Globally
|
30 |
|
31 | ```
|
32 | npm install --global shipit-cli
|
33 | ```
|
34 |
|
35 | ### Locally
|
36 |
|
37 | ```
|
38 | npm install --save-dev shipit-cli
|
39 | ```
|
40 |
|
41 | ## Getting Started
|
42 |
|
43 | Once shipit is installed, you must create a shipitfile.js.
|
44 |
|
45 | If you are familiar with grunt or gulp, you will feel at home.
|
46 |
|
47 | ### Create a `shipitfile.js`
|
48 |
|
49 | ```js
|
50 | module.exports = function (shipit) {
|
51 | shipit.initConfig({
|
52 | staging: {
|
53 | servers: 'myproject.com'
|
54 | }
|
55 | });
|
56 |
|
57 | shipit.task('pwd', function () {
|
58 | return shipit.remote('pwd');
|
59 | });
|
60 | };
|
61 | ```
|
62 |
|
63 | ### Launch command
|
64 |
|
65 | ```
|
66 | shipit staging pwd
|
67 | ```
|
68 |
|
69 | ## Deploy using Shipit
|
70 |
|
71 | You can easily deploy a project using Shipit and its plugin [shipit-deploy](https://github.com/shipitjs/shipit-deploy).
|
72 |
|
73 | ### Example `shipitfile.js`
|
74 |
|
75 | ```js
|
76 | module.exports = function (shipit) {
|
77 | require('shipit-deploy')(shipit);
|
78 |
|
79 | shipit.initConfig({
|
80 | default: {
|
81 | workspace: '/tmp/github-monitor',
|
82 | deployTo: '/tmp/deploy_to',
|
83 | repositoryUrl: 'https://github.com/user/repo.git',
|
84 | ignores: ['.git', 'node_modules'],
|
85 | rsync: ['--del'],
|
86 | keepReleases: 2,
|
87 | key: '/path/to/key',
|
88 | shallowClone: true
|
89 | },
|
90 | staging: {
|
91 | servers: 'user@myserver.com'
|
92 | }
|
93 | });
|
94 | };
|
95 | ```
|
96 |
|
97 | To deploy on staging, you must use the following command :
|
98 |
|
99 | ```
|
100 | shipit staging deploy
|
101 | ```
|
102 |
|
103 | You can rollback to the previous releases with the command :
|
104 |
|
105 | ```
|
106 | shipit staging rollback
|
107 | ```
|
108 |
|
109 | ## Usage
|
110 |
|
111 | ```
|
112 | shipit <environment> <tasks ...>
|
113 | ```
|
114 |
|
115 | ### Options
|
116 |
|
117 | #### servers
|
118 |
|
119 | Type: `String` or `Array<String>`
|
120 |
|
121 | Servers on which the project will be deployed. Pattern must be `user@myserver.com` if user is not specified (`myserver.com`) the default user will be "deploy".
|
122 |
|
123 | #### key
|
124 |
|
125 | Type: `String`
|
126 |
|
127 | Path to SSH key
|
128 |
|
129 | ### Events
|
130 |
|
131 | You can add custom event and listen to events.
|
132 |
|
133 | ```js
|
134 | shipit.task('build', function () {
|
135 | // ...
|
136 | shipit.emit('built');
|
137 | });
|
138 |
|
139 | shipit.on('built', function () {
|
140 | shipit.start('start-server');
|
141 | });
|
142 | ```
|
143 |
|
144 | Shipit emits the `init` event once initialized, before any tasks are run.
|
145 |
|
146 | ### Methods
|
147 |
|
148 | #### shipit.task(name, [deps], fn)
|
149 |
|
150 | Create a new Shipit task, if you are familiar with gulp, this is the same API. You can use a callback or a promise in your task.
|
151 |
|
152 | For more documentation, please refer to [orchestrator documentation](https://github.com/orchestrator/orchestrator#orchestratoraddname-deps-function).
|
153 |
|
154 | ```js
|
155 | shipit.task('pwd', function () {
|
156 | return shipit.remote('pwd');
|
157 | });
|
158 | ```
|
159 |
|
160 | #### shipit.blTask(name, [deps], fn)
|
161 |
|
162 | Create a new Shipit task that will block other tasks during its execution (synchronous).
|
163 |
|
164 | If you use these type of task, the flow will be exactly the same as if you use [grunt](http://gruntjs.com).
|
165 |
|
166 | ```js
|
167 | shipit.blTask('pwd', function () {
|
168 | return shipit.remote('pwd');
|
169 | });
|
170 | ```
|
171 |
|
172 | #### shipit.start(tasks)
|
173 |
|
174 | Run Shipit tasks.
|
175 |
|
176 | For more documentation, please refer to [orchestrator documentation](https://github.com/orchestrator/orchestrator#orchestratorstarttasks-cb).
|
177 |
|
178 | ```js
|
179 | shipit.start('task');
|
180 | shipit.start('task1', 'task2');
|
181 | shipit.start(['task1', 'task2']);
|
182 | ```
|
183 |
|
184 | #### shipit.local(command, [[options]](https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback), [callback])
|
185 |
|
186 | Run a command locally and streams the result. This command take a callback or return a promise. It returns a result object containing stdout, stderr and the child process object.
|
187 |
|
188 | ```js
|
189 | shipit.local('ls -lah', {cwd: '/tmp/deploy/workspace'}).then(function (res) {
|
190 | console.log(res.stdout);
|
191 | console.log(res.stderr);
|
192 | res.child.stdout.pipe(...);
|
193 | });
|
194 | ```
|
195 |
|
196 | #### shipit.remote(command, [[options]](https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback), [callback])
|
197 |
|
198 | Run a command remotely and streams the result. This command take a callback or return a promise.
|
199 |
|
200 | If you want to run a `sudo` command, the ssh connection will use the TTY mode automatically.
|
201 |
|
202 | It returns an array of result objects containing stdout, stderr and the child process object. The list of results matchs the list of servers specified in configuration.
|
203 |
|
204 | ```js
|
205 | shipit.remote('ls -lah').then(function (res) {
|
206 | console.log(res[0].stdout); // stdout for first server
|
207 | console.log(res[0].stderr); // stderr for first server
|
208 | res[0].child.stdout.pipe(...); // child of first server
|
209 |
|
210 | console.log(res[1].stdout); // stdout for second server
|
211 | console.log(res[1].stderr); // stderr for second server
|
212 | res[0].child.stdout.pipe(...); // child of second server
|
213 | });
|
214 | ```
|
215 |
|
216 | #### shipit.remoteCopy(src, dest, [options], [callback])
|
217 |
|
218 | Make a remote copy from a local path to a dest path.
|
219 |
|
220 | ```js
|
221 | shipit.remoteCopy('/tmp/workspace', '/opt/web/myapp').then(...);
|
222 | ```
|
223 |
|
224 | #### shipit.log()
|
225 |
|
226 | Log using Shipit, same API as `console.log`.
|
227 |
|
228 | ```js
|
229 | shipit.log('hello %s', 'world');
|
230 | ```
|
231 |
|
232 | ## Dependencies
|
233 |
|
234 | - [OpenSSH](http://www.openssh.com/) 5+
|
235 | - [rsync](https://rsync.samba.org/) 3+
|
236 |
|
237 | ### Customising environments
|
238 |
|
239 | You can overwrite all default variables defined as part of the `default` object.
|
240 |
|
241 | ```js
|
242 | module.exports = function (shipit) {
|
243 | shipit.initConfig({
|
244 | staging: {
|
245 | servers: 'staging.myproject.com',
|
246 | workspace: '/home/vagrant/website'
|
247 | branch: 'dev'
|
248 | },
|
249 | production: {
|
250 | servers: [{
|
251 | host: 'app1.myproject.com',
|
252 | user: 'john',
|
253 | }, {
|
254 | host: 'app2.myproject.com',
|
255 | user: 'rob',
|
256 | }],
|
257 | branch: 'production',
|
258 | workspace: '/var/www/website'
|
259 | }
|
260 | });
|
261 |
|
262 | ...
|
263 | shipit.task('pwd', function () {
|
264 | return shipit.remote('pwd');
|
265 | });
|
266 | ...
|
267 | };
|
268 | ```
|
269 |
|
270 | ### Async Config
|
271 |
|
272 | If you can't call `shipit.initConfig(...)` right away because
|
273 | you need to get data asynchronously to do so, you can return
|
274 | a promise from the module:
|
275 |
|
276 | ```js
|
277 | module.exports = function (shipit) {
|
278 | return getServersAsync().then( function( servers ) {
|
279 | shipit.initConfig({
|
280 | production: {
|
281 | servers: servers,
|
282 | // ...
|
283 | }
|
284 | })
|
285 | } )
|
286 | }
|
287 | ```
|
288 |
|
289 | If you need to use a function that works with callbacks
|
290 | instead of promises, you can wrap it manually:
|
291 |
|
292 |
|
293 | ```js
|
294 | module.exports = function (shipit) {
|
295 | return new Promise( function( resolve ) {
|
296 | getServersAsync( function( servers ) {
|
297 | shipit.initConfig({
|
298 | production: {
|
299 | servers: servers,
|
300 | // ...
|
301 | }
|
302 | })
|
303 | resolve()
|
304 | } )
|
305 | } )
|
306 | }
|
307 | ```
|
308 |
|
309 | ## Known Plugins
|
310 |
|
311 | ### Official
|
312 |
|
313 | - [shipit-deploy](https://github.com/shipitjs/shipit-deploy)
|
314 |
|
315 | ### Third Party
|
316 |
|
317 | - [shipit-shared](https://github.com/timkelty/shipit-shared)
|
318 | - [shipit-db](https://github.com/timkelty/shipit-db)
|
319 | - [shipit-assets](https://github.com/timkelty/shipit-assets)
|
320 | - [shipit-ssh](https://github.com/timkelty/shipit-ssh)
|
321 | - [shipit-utils](https://github.com/timkelty/shipit-utils)
|
322 | - [shipit-npm](https://github.com/callerc1/shipit-npm)
|
323 | - [shipit-aws](https://github.com/KrashStudio/shipit-aws)
|
324 | - [shipit-captain](https://github.com/timkelty/shipit-captain/)
|
325 | - [shipit-bower](https://github.com/willsteinmetz/shipit-bower)
|
326 | - [shipit-composer](https://github.com/jeremyzahner/shipit-composer)
|
327 |
|
328 | ## Who use Shipit?
|
329 |
|
330 | - [Le Monde](http://www.lemonde.fr)
|
331 | - [Ghost blogging platform](https://ghost.org/)
|
332 | - [Fusionary](http://fusionary.com)
|
333 |
|
334 | ## License
|
335 |
|
336 | MIT
|