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.
- Deploy gitlab community edition on localhost using docker-compose
- Install slack on phone/desktop and connect it to to gitlab instance using webhooks
- Install docker and docker-compose on your workstation by following the instructions in the following tutorial:
a)Docker :- https://docs.docker.com/engine/installation/
- Install slack desktop/mobile client:
- Setup docker compose script for getting docker compose instance up and running:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364version: '2'services:redis:restart: alwaysimage: sameersbn/redis:latestcommand:- --loglevel warningvolumes:- /srv/docker/gitlab/redis:/var/lib/redis:Zpostgresql:restart: alwaysimage: sameersbn/postgresql:9.6-2volumes:- /srv/docker/gitlab/postgresql:/var/lib/postgresql:Zenvironment:- DB_USER=admin- DB_PASS=password- DB_NAME=gitlabhq_production- DB_EXTENSION=pg_trgmgitlab:restart: alwaysimage: sameersbn/gitlab:9.4.5depends_on:- redis- postgresqlports:- "10080:80"- "10022:22"volumes:- /srv/docker/gitlab/gitlab:/home/git/data:Zenvironment:- 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_EMAILemail@example.com- GITLAB_CI_SUPPORTfirstname.lastname@example.org- 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:1pwgen -Bsv1 64
- Next get Gitlab docker instance up and running using the following command:
- Now you sign into gitlab docker instance using gitlab credentials on the following address:
- Now we can push some sample project to gitlab instance. I have pushed a simple android application which I had created earlier.
- 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:
- Once you have completed the setup you should see notifications to your slack channel as follows:
- 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:
Then we need to register the runner on gitlab instance as follows:
- 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):
- 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 😀