Up and Running with GitLab CI/CD on Alibaba Cloud

How Continuous Integration(CI) and Continuous Deployment (CD) evolved?

Without CI/CD

Once we get the requirements from the business team, the development team takes care of transforming the requirements into some form of functional code in the form of software. The whole activity is mostly performed within the development environment. The development might take months or years depending upon the requirement once this activity completes, the whole project is given to the operations team to test, deploy in the production environment.

  1. The time to market for the product is very high
  2. Teams work within their boundaries
  3. Inefficient resource utilization
  4. Time consuming process

With CI/CD

Once we get the requirements from the business team, the development team and operations team together work on deciding different configuration parameters for the environment. This collaboration ensures that the development environment is similar to the production environment or at least no issue arises when the developed project moves to the production environment.

  1. Faster delivery of features
  2. More stable operating environments
  3. Improved collaboration between different teams
  4. More time to innovate the product
  5. Less complexity to manage
  6. Continuous software delivery
  7. Swift resolution of problems

Setting up GitLab CI:

GitLab Community Edition (CE) is an open source end-to-end software development platform with built-in version control, issue tracking, code review, CI/CD, and more.


Since we are working with Gitlab continuous integration, we need a Gitlab instance installed on an Ubuntu 16.04 server on Alibaba Cloud Elastic Compute Service (ECS) instance. GitLab recommends a server with at least 2 CPU cores and 4GB of RAM.

What Are the Advantages of GitLab CI/CD?

Integrated: GitLab CI/CD is part of GitLab.

Saraths-MacBook-Pro:~ sarathchandrap$ ssh root@
root@'s password:
Welcome to Ubuntu 16.04.4 LTS (GNU/Linux 4.4.0-117-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
Welcome to Alibaba Cloud Elastic Compute Service !Last login: Sun Jul 15 04:06:56 2018 from
root@GITLABCICD:~# sudo systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2018-07-05 16:59:57 CST; 1 weeks 2 days ago
Docs: https://docs.docker.com
Main PID: 6102 (dockerd)
Tasks: 26
Memory: 826.4M
CPU: 35min 35.798s
CGroup: /system.slice/docker.service
├─6102 /usr/bin/dockerd -H fd://
└─6126 docker-containerd --config /var/run/docker/containerd/containerd.toml
root@GITLABCICD:~# dockerUsage:    docker COMMANDA self-sufficient runtime for containersOptions:
--config string Location of client config files (default "/root/.docker")
-D, --debug Enable debug mode
-H, --host list Daemon socket(s) to connect to
-l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/root/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
Management Commands:
config Manage Docker configs
container Manage containers
image Manage images
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
swarm Manage Swarm
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes
root@GITLABCICD:~# docker info
Containers: 3
Running: 0
Paused: 0
Stopped: 3
Images: 3
Server Version: 18.03.1-ce
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 773c489c9c1b21a6d78b5c538cd395416ec50f88
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
init version: 949e6fa
Security Options:
Profile: default
Kernel Version: 4.4.0-117-generic
Operating System: Ubuntu 16.04.4 LTS

Importing a GitHub Project

I will be using the following repository for demonstrating the Gitlab CI. The below is a NodeJS application.

image: node:carbonstages:
- build
- test
- node_modules/
stage: build
- npm install
- node_modules/
stage: test
script: npm test
image: node:carbon
- build
- test
- node_modules/
stage: build
- npm install
- node_modules/
stage: test
script: npm test

Triggering a CI Job

We will trigger a job in Gitlab by committing a new file to the repository.

Install and Configuring the GitLab CI Runner

Download the latest version of Gitlab CI Runner from the repository to the /tmp directory of the server by executing the follow command

curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh -o /tmp/gl-runner.deb.sh
sudo bash /tmp/gl-runner.deb.sh
sudo apt-get install gitlab-runner
  1. Shared Service
  2. Project Specific Service

Register a Gitlab CI Runner

Login to the server and run the following command

sudo gitlab-runner register
root@GITLABCICD:~# sudo gitlab-runner register
Running in system-mode.

Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
Please enter the gitlab-ci token for this runner:
Please enter the gitlab-ci token for this runner:
Please enter the gitlab-ci description for this runner:
[GITLABCICD]: This to demonstrate the dedicated Gitlab CI Runner
Please enter the gitlab-ci tags for this runner (comma separated):
Registering runner... succeeded runner=XzbRaWPE
Please enter the executor: shell, ssh, virtualbox, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, docker-ssh:
Please enter the default Docker image (e.g. ruby:2.1):
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com