Skip to content

Commit 7b009c9

Browse files
author
Kurzdor
committed
docs: add some lines about pm2, --command arg and many other things
1 parent df35ae9 commit 7b009c9

1 file changed

Lines changed: 113 additions & 13 deletions

File tree

README.md

Lines changed: 113 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,27 @@
77

88
## Another deployer?!
99

10-
I wanted to make easily the process of deploying code to server on each push to repository. I tried almost all suggested ways to do it but they didn't work. So I created this package. It supports Ubuntu servers and Bitbucket (GitHub and GitLab support in progress!) repos.
10+
I wanted to make easily the process of deploying code to server on each push to repository. I tried almost all suggested ways to do it but they didn't work. So I created this package. It supports Ubuntu servers and GitHub/GitLab/Bitbucket repos.
1111

1212
## Uses
1313

14-
Nodeployed uses [Fastify](https://www.fastify.io) as Node.js Server, [Execa](https://github.com/sindresorhus/execa) to run such commands to deploy code and [Minimist](https://github.com/substack/minimist) to parse command arguments.
14+
Nodeployed uses [Fastify](https://www.fastify.io) as Node.js server, [Execa](https://github.com/sindresorhus/execa) to run such commands to deploy code and [Minimist](https://github.com/substack/minimist) to parse command arguments.
1515

1616
## Server preparation
1717

1818
To be able to use it sucessfully, you need:
1919

2020
- Install Node.js and npm on your server
2121

22+
* Setup your Apache/NGINX server to _reverse proxy_ all requests to `http://localhost:YOUR_PORT` in `location` block:
2223

23-
- Setup your Apache/NGINX server to _reverse proxy_ all requests to `http://localhost:YOUR_PORT` in `location` block:
24-
25-
- For NGINX change your server block config to something like this:
24+
* For `NGINX` change your server block config to something like this:
2625

2726
```nginx
2827
# Your server in /etc/nginx/sites-available/example.com
2928
server {
3029
...
31-
location / {
30+
location /deploy/ {
3231
proxy_pass http://localhost:YOUR_PORT;
3332
proxy_http_version 1.1;
3433
proxy_set_header Upgrade $http_upgrade;
@@ -40,11 +39,11 @@ server {
4039
}
4140
```
4241

43-
- For Apache2:
42+
- For `Apache2`:
4443

4544
```apache
4645
<VirtualHost *:*>
47-
ProxyPass / http://0.0.0.0:3000/
46+
ProxyPass /deploy/ http://0.0.0.0:3000/
4847
ServerName localhost
4948
</VirtualHost>
5049
```
@@ -55,19 +54,108 @@ server {
5554

5655
## Usage
5756

58-
Install package globally from `NPM repo` via `npm` or `yarn` and start the process with [pm2](http://pm2.keymetrics.io/):
57+
Install package globally from `NPM repo` via `npm` and start the process with [pm2](http://pm2.keymetrics.io/):
5958

6059
```sh
6160
$ npm i -g nodeployed pm2
62-
$ pm2 start nodeployed [your settings]
61+
$ pm2 start nodeployed -- --port 8234 --dir /absolute/path/to/git/dir/ --command "command1_to_run && command2_to_run ..."
62+
```
63+
64+
Go to `http://example.com/deploy`.
65+
If script is properly working then you should see this message:
66+
67+
```plain
68+
Nodeployed is working! You should set this link in your Webhooks configuration for your repository!
69+
```
70+
71+
We will configure our repository later in `Configure repository for nodeployed` section.
72+
73+
Also if you want to run `nodeployed` as system service `pm2` can help you. For that run next commands:
74+
75+
```sh
76+
$ pm2 startup systemd
77+
```
78+
79+
And then `copy the command from the output` and run it, example:
80+
81+
```sh
82+
$ sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u user --hp /home/user
83+
```
84+
85+
You can save current configuration of running applications if you run multiple instances of `nodeployed`:
86+
87+
```sh
88+
$ pm2 save
89+
```
90+
91+
Then you can see the status of `pm2 system service` by running:
92+
93+
```sh
94+
$ systemctl status pm2-user
95+
```
96+
97+
or start it:
6398

99+
```sh
100+
$ sudo systemctl start pm2-user
64101
```
65102

103+
or stop it by running next command:
104+
66105
```sh
67-
$ yarn add global nodeployed pm2
68-
$ pm2 start nodeployed [your settings]
106+
$ sudo systemctl stop pm2-user
69107
```
70108

109+
where user – username that gave you `pm2` from running the `pm2 startup systemd` command.
110+
111+
## Configure repository for nodeployed
112+
113+
### GitHub:
114+
115+
1. Go to the directory for which you would like to setup autodeploy to your server.
116+
2. Go to `Settings` page.
117+
3. Go to `Webhooks` page => `Add webhook`.
118+
4. Type in your GitHub password if prompted
119+
5. Setup webhook:
120+
121+
- Payload: http://example.com/deploy/?token=YOUR_TOKEN_FROM_ARGUMENT
122+
- Content Type: application/json
123+
- Which events would you like to trigger this webhook? Just the push event.
124+
- Active: check it
125+
- Press `Add webhook`
126+
127+
6. Now on any push to this GitHub repository `nodeployed` should pull changes on server and run deploy commands.
128+
129+
### GitLab:
130+
131+
1. Go to the directory for which you would like to setup autodeploy to your server.
132+
2. Go to `Settings` => `Integrations`.
133+
3. Setup webhook:
134+
135+
- URL: http://example.com/deploy/?token=YOUR_TOKEN_FROM_ARGUMENT
136+
- Secret Token: `leave it empty`
137+
- Trigger events: Push events
138+
- Enable SSL verification: check it if you have installed `LetsEncrypt`
139+
- Press `Add webhook`
140+
141+
4. Now on any push to this GitLab repository `nodeployed` should pull changes on server and run deploy commands.
142+
143+
### Bitbucket
144+
145+
1. Go to the directory for which you would like to setup autodeploy to your server.
146+
2. Go to `Settings` => `Webhooks` => `Add webhook`.
147+
3. Setup webhook:
148+
149+
- Title: any value, e.g. `nodeployed` to recognize it
150+
- URL: http://example.com/deploy/?token=YOUR_TOKEN_FROM_ARGUMENT
151+
- Skip certificate verification: check it if you haven't installed `LetsEncrypt`
152+
- Enable request history collection: check it
153+
- Triggers: Repository push
154+
- Press `Save`
155+
156+
4. Now on any push to this Bitbucket repository `nodeployed` should pull changes on server and run deploy commands.
157+
158+
71159
## Options
72160

73161
### --port [PORT]
@@ -90,9 +178,21 @@ Type: `string:required`
90178

91179
Sets the `absoulte` path to target deploy GIT repository.
92180

181+
### --command [COMMANDS]
182+
183+
Default: `bash ./deploy.sh`\
184+
Type: `string`
185+
186+
Pass commands that needs to run after pull from repository/to deploy, e.g. `--command "npm install && npm run build"`.
187+
If nothing passed to `--command` it will fallback to command `bash ./deploy.sh` so you need to manually create this script with all needed commands.
188+
93189
### --branch [BRANCH_NAME]
94190

95191
Default: `master`\
96192
Type: `string`
97193

98-
Sets the working branch for target deploy GIT repository.
194+
Sets the working branch for target deploy GIT repository.
195+
196+
## LICENSE
197+
198+
MIT

0 commit comments

Comments
 (0)