Automated Deployment with Self-hosted Gitlab & Ubuntu 16.04

Seanghay
2 min readFeb 8, 2018

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 directory

mkdir node-hook

Change Directory to the project

cd node-hook

Initialize NPM

npm init -y

Install Needed Packages

npm install shelljs node-gitlab-webhook — save

Create Entry Point

touch index.js

index.js

Installing PM2

sudo npm i -g pm2

Run the Application

pm2 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.

Make sure the check box Enable SSL verification is unchecked if your IP is not HTTPS.

This is not perfect enough but it works

Congratulations!

--

--