UNPKG

5.96 kBMarkdownView Raw
1# now-pipeline
2
3> Single CI command to deploy new code to Zeit Now
4> Includes e2e tests and the alias switch
5
6[![NPM][npm-icon] ][npm-url]
7
8[![Build status][ci-image] ][ci-url]
9[![semantic-release][semantic-image] ][semantic-url]
10[![js-standard-style][standard-image]][standard-url]
11[![first-timers-only](http://img.shields.io/badge/first--timers--only-friendly-blue.svg)](https://github.com/bahmutov/now-pipeline/labels/first-timers-only)
12[![next-update-travis badge][nut-badge]][nut-readme]
13
14## First time contributors
15
16This repo is [first time OSS contributor friendly](http://www.firsttimersonly.com/).
17See [these issues](https://github.com/bahmutov/now-pipeline/labels/first-timers-only)
18to contribute in meaningful way.
19
20## What and why
21
22I am [super excited](https://glebbahmutov.com/blog/think-inside-the-box/)
23about [Zeit Now](https://zeit.co/now) tool; this is the "missing CI tool"
24for it. A single command `now-pipeline`
25
26- deploys new version
27- tests it
28- switches alias to the new deployment
29- takes down the old deployment
30
31Should be enough to automatically update the server or service running in
32the cloud without breaking anything.
33
34## Install and use
35
36```sh
37npm i -g now-pipeline
38```
39
40Set `NOW_TOKEN` CI environment variable with a token that you can get from
41[Zeit account page](https://zeit.co/account#api-tokens)
42
43Add CI command to `now-pipeline`. By default it will execute `npm test`
44and will pass the deployed url as `NOW_URL` environment variable. You can
45customize everything.
46
47## Example
48
49Simple Travis commands
50
51```yml
52script:
53 # after unit tests
54 - npm i -g now-pipeline
55 - now-pipeline
56```
57
58Prune existing deploys (if they do not have an alias) and show the deploy.
59
60```yml
61script:
62 - npm i -g now-pipeline
63 - now-pipeline-prune
64 - now-pipeline
65 - now-pipeline-list
66```
67
68Set [domain alias](https://zeit.co/world) if there is no existing one
69
70```yml
71script:
72 - npm i -g now-pipeline
73 - now-pipeline --alias foo.domain.com
74```
75
76Pass test command and name of the environment variable for deployed url
77
78```yml
79script:
80 - npm i -g now-pipeline
81 - now-pipeline --as HOST --test "npm run e2e"
82```
83
84## Example projects
85
86* [todomvc-express](https://github.com/bahmutov/todomvc-express/blob/master/.travis.yml)
87* [express-sessions-tutorial](https://github.com/bahmutov/express-sessions-tutorial/blob/master/.travis.yml)
88* [test-semantic-deploy-with-now](https://github.com/bahmutov/test-semantic-deploy-with-now)
89
90## Additional bin commands
91
92* `now-pipeline-list` - see the current deploys for the current project
93* `now-pipeline-prune` - remove all non-aliased deploys for the current project
94
95You can pass custom test command to the pipeline to be used after deploying
96fresh install using `--test "command"` argument. The command will get `NOW_URL`
97environment variable with new install. For example
98
99```sh
100npm i -g now-pipeline
101now-pipeline --test "npm run prod-test"
102```
103
104where the `package.json` has
105
106```json
107{
108 "scripts": {
109 "prod-test": "e2e-test $NOW_URL"
110 }
111}
112```
113
114## Details
115
116* `now-pipeline` uses [Zeit API](https://zeit.co/api) via [now-client](https://github.com/zeit/now-client).
117* You can see the list of recent actions at [Zeit dashboard](https://zeit.co/dashboard).
118* It discovers files to send using [pkgd](https://github.com/inikulin/pkgd),
119 you can see the files by using the following command
120 (read [Smaller published NPM modules](https://glebbahmutov.com/blog/smaller-published-NPM-modules/) for more details)
121```sh
122t="$(npm pack .)"; wc -c "${t}"; tar tvf "${t}"; rm "${t}"
123```
124* file `.npmignore` is considered an optional file
125
126## Related
127
128* [next-update](https://github.com/bahmutov/next-update) is a similar
129 "if tests pass, upgrade" tool for your NPM dependencies.
130
131### Small print
132
133Author: Gleb Bahmutov <gleb.bahmutov@gmail.com> © 2016
134
135* [@bahmutov](https://twitter.com/bahmutov)
136* [glebbahmutov.com](http://glebbahmutov.com)
137* [blog](http://glebbahmutov.com/blog)
138
139License: MIT - do anything with the code, but don't blame me if it does not work.
140
141Support: if you find any problems with this module, email / tweet /
142[open issue](https://github.com/bahmutov/now-pipeline/issues) on Github
143
144## MIT License
145
146Copyright (c) 2016 Gleb Bahmutov <gleb.bahmutov@gmail.com>
147
148Permission is hereby granted, free of charge, to any person
149obtaining a copy of this software and associated documentation
150files (the "Software"), to deal in the Software without
151restriction, including without limitation the rights to use,
152copy, modify, merge, publish, distribute, sublicense, and/or sell
153copies of the Software, and to permit persons to whom the
154Software is furnished to do so, subject to the following
155conditions:
156
157The above copyright notice and this permission notice shall be
158included in all copies or substantial portions of the Software.
159
160THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
161EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
162OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
163NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
164HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
165WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
166FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
167OTHER DEALINGS IN THE SOFTWARE.
168
169[npm-icon]: https://nodei.co/npm/now-pipeline.svg?downloads=true
170[npm-url]: https://npmjs.org/package/now-pipeline
171[ci-image]: https://travis-ci.org/bahmutov/now-pipeline.svg?branch=master
172[ci-url]: https://travis-ci.org/bahmutov/now-pipeline
173[semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
174[semantic-url]: https://github.com/semantic-release/semantic-release
175[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg
176[standard-url]: http://standardjs.com/
177[nut-badge]: https://img.shields.io/badge/next--update--travis-ok-green.svg
178[nut-readme]: https://github.com/bahmutov/next-update-travis#readme