nodeployed v1.5.4
Another deployer?!
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.
Uses
Nodeployed uses Fastify as Node.js server, Execa to run such commands to deploy code and Minimist to parse command arguments.
Server preparation
To be able to use it sucessfully, you need:
- Install Node.js and npm on your server
Setup your Apache/NGINX server to reverse proxy all requests to
http://localhost:YOUR_PORTinlocationblock:For
NGINXchange your server block config to something like this:
# Your server in /etc/nginx/sites-available/example.com
server {
...
location /deploy/ {
proxy_pass http://localhost:YOUR_PORT;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
...
}- For
Apache2:
<VirtualHost *:*>
ProxyPass /deploy/ http://0.0.0.0:3000/
ServerName localhost
</VirtualHost>- Optionally: Install LetsEncrypt on that domain that you will use.
- Clone repository that you want to work with with
git clone - Run
sudo chown -R yourusername:webserverusername you-repo-dir-name/for your repository directory to make script able to fully usegitcommands.
Usage
Install package globally from NPM repo via npm and start the process with pm2:
$ npm i -g nodeployed pm2
$ pm2 start nodeployed -- --port 8234 --dir /absolute/path/to/git/dir/ --command "command1_to_run && command2_to_run ..."Go to http://example.com/deploy.
If script is properly working then you should see this message:
Nodeployed is working! You should set this link in your Webhooks configuration for your repository!We will configure our repository later in Configure repository for nodeployed section.
Also if you want to run nodeployed as system service pm2 can help you. For that run next commands:
$ pm2 startup systemdAnd then copy the command from the output and run it, example:
$ sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u user --hp /home/userYou can save current configuration of running applications if you run multiple instances of nodeployed:
$ pm2 saveThen you can see the status of pm2 system service by running:
$ systemctl status pm2-useror start it:
$ sudo systemctl start pm2-useror stop it by running next command:
$ sudo systemctl stop pm2-userwhere user – username that gave you pm2 from running the pm2 startup systemd command.
Configure repository for nodeployed
GitHub:
- Go to the directory for which you would like to setup autodeploy to your server.
- Go to
Settingspage. - Go to
Webhookspage =>Add webhook. - Type in your GitHub password if prompted
- Setup webhook:
- Payload: http://example.com/deploy/?token=YOUR_TOKEN_FROM_ARGUMENT
- Content Type: application/json
- Which events would you like to trigger this webhook? Just the push event.
- Active: check it
- Press
Add webhook
- Now on any push to this GitHub repository
nodeployedshould pull changes on server and run deploy commands.
GitLab:
- Go to the directory for which you would like to setup autodeploy to your server.
- Go to
Settings=>Integrations. - Setup webhook:
- URL: http://example.com/deploy/?token=YOUR_TOKEN_FROM_ARGUMENT
- Secret Token:
leave it empty - Trigger events: Push events
- Enable SSL verification: check it if you have installed
LetsEncrypt - Press
Add webhook
- Now on any push to this GitLab repository
nodeployedshould pull changes on server and run deploy commands.
Bitbucket:
- Go to the directory for which you would like to setup autodeploy to your server.
- Go to
Settings=>Webhooks=>Add webhook. - Setup webhook:
- Title: any value, e.g.
nodeployedto recognize it - URL: http://example.com/deploy/?token=YOUR_TOKEN_FROM_ARGUMENT
- Skip certificate verification: check it if you haven't installed
LetsEncrypt - Enable request history collection: check it
- Triggers: Repository push
- Press
Save
- Now on any push to this Bitbucket repository
nodeployedshould pull changes on server and run deploy commands.
Options
--port PORT
Default: 9000\
Maximum: 65535\
Type: number
Sets IPv4 port on which server will be running and listening for requests.
--token TOKEN
Type: string:required
Sets the token to validate server request.
--dir DIR_PATH
Type: string:required
Sets the absoulte path to target deploy GIT repository.
--command COMMANDS
Default: bash ./deploy.sh\
Type: string
Pass commands that needs to run after pull from repository/to deploy, e.g. --command "npm install && npm run build".
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.
--branch BRANCH_NAME
Default: master\
Type: string
Sets the working branch for target deploy GIT repository.
LICENSE
MIT
Contributors
Thanks goes to these wonderful people (emoji key):
| Paul Ekshmidt💻 📖 🚧 🤔 |
|---|
This project follows the all-contributors specification. Contributions of any kind welcome!
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago