Setting up private gitlab server for build automation with event notifications to slack

Saurabh Mhatre
CodeClassifiers
Published in
3 min readSep 17, 2017

The purpose of this tutorial is to automate android build generation process using CI tools
like Gitlab CI and send event notifications to slack using webhooks.
We are going to use docker for creating local instance of gitlab server and push a simple
android mobile application to gitlab server running on localhost. All the push events
are monitored by sending push event notifications to slack channel.

Goals:

  1. Deploy gitlab community edition on localhost using docker-compose
  2. Install slack on phone/desktop and connect it to to gitlab instance using webhooks

Prerequisites:

  1. Install docker and docker-compose on your workstation by following the instructions in the following tutorial:
    a)Docker :- https://docs.docker.com/engine/installation/
    b)Docker-compose:- https://docs.docker.com/compose/
  2. Install slack desktop/mobile client:
    https://slack.com/downloads/linux

Steps:

  1. Setup docker compose script for getting docker compose instance up and running:
version: '2'services:
redis:
restart: always
image: sameersbn/redis:latest
command:
- --loglevel warning
volumes:
- /srv/docker/gitlab/redis:/var/lib/redis:Z
postgresql:
restart: always
image: sameersbn/postgresql:9.6-2
volumes:
- /srv/docker/gitlab/postgresql:/var/lib/postgresql:Z
environment:
- DB_USER=admin
- DB_PASS=password
- DB_NAME=gitlabhq_production
- DB_EXTENSION=pg_trgm
gitlab:
restart: always
image: sameersbn/gitlab:9.4.5
depends_on:
- redis
- postgresql
ports:
- "10080:80"
- "10022:22"
volumes:
- /srv/docker/gitlab/gitlab:/home/git/data:Z
environment:
- DEBUG=false
- DB_ADAPTER=postgresql
- DB_HOST=postgresql
- DB_PORT=5432
- DB_USER=admin
- DB_PASS=password
- DB_NAME=gitlabhq_production
- REDIS_HOST=redis
- REDIS_PORT=6379
- TZ=Asia/Kolkata
- GITLAB_TIMEZONE=Kolkata
- GITLAB_HTTPS=false
- SSL_SELF_SIGNED=false
- GITLAB_HOST=localhost
- GITLAB_PORT=10080
- GITLAB_SSH_PORT=10022
- GITLAB_URL=http://localhost:10080
- GITLAB_APP_ID='123345234'
- GITLAB_APP_SECRET='somesecret'
- GITLAB_CI_SECRETS_SESSION_KEY_BASE="new session key to be added below command"
- GITLAB_CI_SECRETS_DB_KEY_BASE="new session key to be added below command"
- GITLAB_SECRETS_DB_KEY_BASE="new session key to be added below command"
- GITLAB_SECRETS_SECRET_KEY_BASE="new session key to be added below command"
- GITLAB_SECRETS_OTP_KEY_BASE="new session key to be added below command"
- GITLAB_CI_EMAIL=ci@example.com
- GITLAB_CI_SUPPORT=support@example.com
- GITLAB_CI_NOTIFY_ON_BROKEN_BUILDS="true"
- GITLAB_CI_NOTIFY_PUSHER=false
- GITLAB_CI_BACKUPS=daily
- GITLAB_CI_BACKUP_TIME=01:00

I have used the github repo uploaded here: Dockercompose.yml

You can generate your own session and secret keys using following command in terminal and then add them to above yml file:

pwgen -Bsv1 64

2. Next get Gitlab docker instance up and running using the following command:

docker-compose up

3. Now you sign into gitlab docker instance using gitlab credentials on the following address:

http://localhost:10080/

4. Now we can push some sample project to gitlab instance. I have pushed a simple android application which I had created earlier.

5. Next we need to connect slack client to gitlab instance to listen to repo activities and send appropriate alerts to developers on slack channel.
Headover to slack web version and add web hooks by following the steps in official link below:
https://docs.gitlab.com/ee/user/project/integrations/slack.html

6.Once you have completed the setup you should see notifications to your slack channel as follows:

slack notifications

7.Next we can setup Gitlab CI runner to automate build generation process:
You will have to install gitlab CI on your workstation by following the official documentation:
Official docs
Then we need to register the runner on gitlab instance as follows:
Registration

8.Next we need to configure runners required as per the project. For example for android applications we can use the following yml file which needs to be added to the root folder of target repo(Android application folder):
AndroidFile

9.Once the runner is set up the build process or other scheduled jobs can be configured accordingly within gitlab repo settings.

This concludes today’s tutorial for setting up personal gitlab server instance. You can follow technoetics facebook page to receive updates on upcoming tutorials: TechnoeticsClub

Keep reading and learning new things everyday :D

--

--