This repo is a easy way to set up an entire devops CI/CD pipeline with nothing other than docker and an ubuntu machine.
The setup is preconfigured to work with npm as the build and package tool. The dockerfiles and ansible playbook are attached for anyone who wants to poke around
All the services are running on docker containers including ansible hosts
- Git : Source Code Management
- Jenkins : Continuous Integration port: 8080
- SonarQube : Static analysis port: 9000
- Sonatype nexus : Artifactory port: 8081
- Ansible cluster : Deployment (1 master, 3 hosts)
- Docker : Container runtime
- npm : To build the source code
- serve : To serve the final application ports: 4002, 4004, 4006 one per ansible host
you should atleast have 20gb free disk space and 8gb of ram since sonatype nexus requires atleast 4gb spare ram
Our setup involves three ansible host containers, individual containers running sonarqube and nexus and another running both ansible and jenkins
- Clone the repo, navigate to the directory
pipeline-on-ubuntu
, and run the setup.sh script file. Your setup is done, You are just configuring your project away from an up and running pipeline.
$ git clone <url>
$ cd pipeline-on-ubuntu/
$ ./setup.sh
- Your jenkins and nexus initial passwords will be fetched for you at the end of the execution of the script. Incase the nexus password is not fetched, wait for a moment and run
$ docker container exec pipelineonubuntu_nexus_1 cat /nexus-data/admin.password
-
Navigate to
localhost:9000
→ login User:admin
Password:admin
- Under my account → security → generate a security token → copy to clipboard
-
Navigate to
localhost:8081
→ login (User:admin
, password will be fetched by the script)- Under server administration and configuration create a a new repository with recipe:
raw (hosted
)
- Under server administration and configuration create a a new repository with recipe:
-
Navigate to
localhost:8080
→ login (initial admin password will be fetched by the script) and setup Jenkins. Install additional plugins- Sonarqube scanner
- Ansible
- Gitlab, gitlab hook (Incase you are using gitlab, like we are)
- Nexus artifact uploader
-
In your
gitlab.com
account → Settings → SSH Keys → add the public key of a key pair
-
Manage jenkins → Configure system
- SonarQube servers
-
Enable injection of SonarQube server configuration as build environment variables
- Add SonarQube →
- Give a name
- Server URL:
http://172.24.0.4:9000
- Sonarqube authentication token → Add → kind:
secret text
→ copy the generated SonarQube token → add the cred and use it
-
- Gitlab
- Enable authentication for '/project' end-point (uncheck if checked by deafult)
- SonarQube servers
-
Manage jenkins → Global tool configuration → SonarQube scanner
- Add sonarqube scanner → Give a name → save
- New Item → freestyle project → Ok
-
Source Code Management
- Git
- Repository URL:
ssh clone url
- Credentials → Add → kind:
SSH Username with private key
- Username:
gitlab username
- Private key → Enter directly → Add → private key of the key pair of which public key is configured in gitlab → Add cred and use it → Save
- Username:
-
Build triggers
-
Build when a change is pushed to GitLab. GitLab webhook URL:
http://localhost:8080/project/_jenkins-project-name_ → Enabled GitLab triggers- Push Events
- Accepted Merge Request Events
- Approved Merge Requests (EE-only)
- Comments
-
Navigate to
gitlab.com
→ project repo → Settings → Integrations- URL: http://localhost:8080/project/_jenkins-project-name_
(Gitlab wbhook URL)
- Trigger
- Push events
- SSL verification
- Enable SSL verification
(uncheck)
- Enable SSL verification
- Add webhook → Test → Push events
Hook executed successfully: HTTP 200
- URL: http://localhost:8080/project/_jenkins-project-name_
-
-
Build → Add build step
- Execute SonarQube Scanner → Analysis properties
sonar.projectKey = < Sonarqube project key > sonar.projectName = < Sonarqube project name > sonar.projectVersion = < Project version > sonar.sources = < path to src/ dir >
- Execute SonarQube Scanner → Analysis properties
-
Build → Add build step
- Execute shell → Command
npm install npm run build zip -r build.zip build/
- Execute shell → Command
-
Build → Add build step → Nexus artifact uploader
- Nexus Version:
NEXUS3
- Protocol:
HTTP
- Nexus URL:
172.24.0.12:8081
- Credentials: Add → kind → Username and Password →
Nexus username and password
→ Add and use it - GroupId:
< nexus group id >
- Version:
< version of code >
- Repository:
< name of the repository that was created in nexus >
- Artifacts
- ArtificatId:
$BUILD_ID
- Type:
zip
- Classifier:
build
- File:
build.zip
- ArtificatId:
- Nexus Version:
-
Build → Add build step → Invoke Ansible Playbook
- PlaybookPath:
/pb1.yml
- Inventory → File or host list
- File path or comma separated host list :
/inventory.txt
- File path or comma separated host list :
- PlaybookPath:
-
- Save
In your ubuntu machine change the name of the jenkins project name in the playbook inside the ansible container
$ docker container exec -it pipelineonubuntu_jekns-ans-master_1 bash
# nano /pb1.yml
...
tasks:
- name: copy zip file
copy:
src: /var/jenkins_home/workspace/ <JENKINS PROJECT NAME> /build.zip
...
# exit
- Jenkins dashboard → project → Build Now (To test)
- Go to your project directory → make a change → commit → push to git
The pipeline will be triggered by default by the gitlab webhook
→ the code will undergo static analysis by sonarqube of which the result will be available in sonarqube dashboard
→ will be built by npm
and compressed → stored in nexus
→ then deployed in the three ansible hosts
and served at ports 4002, 4004 and 4006
of localhost