Skip to content

πŸ“¦ Automatically deploy your code to server after push to repository.

License

Notifications You must be signed in to change notification settings

Kurzdor/nodeployed

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

74 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“¦ nodeployed

Automatically deploy your code to server after push to repository.

NPM version License All Contributors

Another deployer?!

I wanted to make the process of deploying code to server easier 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_PORT in location block:

  • For NGINX change 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 use git commands.

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 systemd

And 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/user

You can save current configuration of running applications if you run multiple instances of nodeployed:

$ pm2 save

Then you can see the status of pm2 system service by running:

$ systemctl status pm2-user

or start it:

$ sudo systemctl start pm2-user

or stop it by running next command:

$ sudo systemctl stop pm2-user

where user – username that gave you pm2 from running the pm2 startup systemd command.

Configure repository for nodeployed

GitHub:

  1. Go to the directory for which you would like to setup autodeploy to your server.
  2. Go to Settings page.
  3. Go to Webhooks page => Add webhook.
  4. Type in your GitHub password if prompted
  5. Setup webhook:
  1. Now on any push to this GitHub repository nodeployed should pull changes on server and run deploy commands.

GitLab:

  1. Go to the directory for which you would like to setup autodeploy to your server.
  2. Go to Settings => Integrations.
  3. Setup webhook:
  1. Now on any push to this GitLab repository nodeployed should pull changes on server and run deploy commands.

Bitbucket:

  1. Go to the directory for which you would like to setup autodeploy to your server.
  2. Go to Settings => Webhooks => Add webhook.
  3. Setup webhook:
  1. Now on any push to this Bitbucket repository nodeployed should 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
Paul Ekshmidt

πŸ’» πŸ“– 🚧 πŸ€”
Vladislav
Vladislav

πŸ’» πŸš‡

This project follows the all-contributors specification. Contributions of any kind welcome!