UNPKG

8.68 kBMarkdownView Raw
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
12Shipit is an automation engine and a deployment tool written for node / iojs.
13
14Shipit 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
16You can automate anything with Shipit but most of the time you will want to deploy your project using
17the [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```
32npm install --global shipit-cli
33```
34
35### Locally
36
37```
38npm install --save-dev shipit-cli
39```
40
41## Getting Started
42
43Once shipit is installed, you must create a shipitfile.js.
44
45If you are familiar with grunt or gulp, you will feel at home.
46
47### Create a `shipitfile.js`
48
49```js
50module.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```
66shipit staging pwd
67```
68
69## Deploy using Shipit
70
71You 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
76module.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
97To deploy on staging, you must use the following command :
98
99```
100shipit staging deploy
101```
102
103You can rollback to the previous releases with the command :
104
105```
106shipit staging rollback
107```
108
109## Usage
110
111```
112shipit <environment> <tasks ...>
113```
114
115### Options
116
117#### servers
118
119Type: `String` or `Array<String>`
120
121Servers 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
125Type: `String`
126
127Path to SSH key
128
129### Events
130
131You can add custom event and listen to events.
132
133```js
134shipit.task('build', function () {
135 // ...
136 shipit.emit('built');
137});
138
139shipit.on('built', function () {
140 shipit.start('start-server');
141});
142```
143
144Shipit emits the `init` event once initialized, before any tasks are run.
145
146### Methods
147
148#### shipit.task(name, [deps], fn)
149
150Create 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
152For more documentation, please refer to [orchestrator documentation](https://github.com/orchestrator/orchestrator#orchestratoraddname-deps-function).
153
154```js
155shipit.task('pwd', function () {
156 return shipit.remote('pwd');
157});
158```
159
160#### shipit.blTask(name, [deps], fn)
161
162Create a new Shipit task that will block other tasks during its execution (synchronous).
163
164If you use these type of task, the flow will be exactly the same as if you use [grunt](http://gruntjs.com).
165
166```js
167shipit.blTask('pwd', function () {
168 return shipit.remote('pwd');
169});
170```
171
172#### shipit.start(tasks)
173
174Run Shipit tasks.
175
176For more documentation, please refer to [orchestrator documentation](https://github.com/orchestrator/orchestrator#orchestratorstarttasks-cb).
177
178```js
179shipit.start('task');
180shipit.start('task1', 'task2');
181shipit.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
186Run 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
189shipit.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
198Run a command remotely and streams the result. This command take a callback or return a promise.
199
200If you want to run a `sudo` command, the ssh connection will use the TTY mode automatically.
201
202It 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
205shipit.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
218Make a remote copy from a local path to a dest path.
219
220```js
221shipit.remoteCopy('/tmp/workspace', '/opt/web/myapp').then(...);
222```
223
224#### shipit.log()
225
226Log using Shipit, same API as `console.log`.
227
228```js
229shipit.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
239You can overwrite all default variables defined as part of the `default` object.
240
241```js
242module.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
272If you can't call `shipit.initConfig(...)` right away because
273you need to get data asynchronously to do so, you can return
274a promise from the module:
275
276```js
277module.exports = function (shipit) {
278 return getServersAsync().then( function( servers ) {
279 shipit.initConfig({
280 production: {
281 servers: servers,
282 // ...
283 }
284 })
285 } )
286}
287```
288
289If you need to use a function that works with callbacks
290instead of promises, you can wrap it manually:
291
292
293```js
294module.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
336MIT