Automated Deployment with Self-hosted Gitlab & Ubuntu 16.04

It’s painful to remote to the server every time we want to deploy our website.

It’s painful to remote to the server every time we want to deploy our website.

“Two men in a steelworks with a crane moving the material over their heads” by Ant Rozetsky on Unsplash

Tools 🛠

  • Gitlab Integration Webhook
  • node-gitlab-webhook — Gitlab Webhooks handler based on Node.js. Support multiple handlers.
  • pm2 — Advanced, production process manager for Node.js
  • shelljs — Unix shell commands for Node.js

Get Started — The Quite Hard Part

Create Bash Script for pulling and building our script

Create Node.js Application for Listening for Webhook

You need to have Node.js and npm installed on your server.

Create project directorymkdir node-hook

Change Directory to the projectcd node-hook

Initialize NPMnpm init -y

Install Needed Packagesnpm install shelljs node-gitlab-webhook — save

Create Entry Pointtouch index.js

index.js

Installing PM2sudo npm i -g pm2

Run the Applicationpm2 start index.js

Automated Startup (Optional)sudo pm2 startup ubuntu

Configuration Gitlab Project — The Simple Part

Go to YourProject > Setting > Integrations

There are two input fields, URL and Secret Token

URL : http://YOUR_PUBLIC_IP:7777/webhook

Secret Token : superS3cret

You can also Trigger other events like Tag, Comments, Issues and more.

Enable SSL verificationHTTPS
This is not perfect enough but it works

Congratulations!