Lab 5 - Integration Server Setup Dependencies:
- ansible 2.9.1
- Python 3.10
- docker 19.03
- gitlab-ce 13.2
- Gitlab-runner 14.3.2
Step A: Create the Integration Server
-
Navigate to the working directory:
cd ~/devops-master/pipeline/s2-automate-build/integration-server
-
Create the missing data folder:
mkdir ../../data # or sudo rm -R ../../data && mkdir ../../data
-
Create the integration server using Vagrant:
vagrant up
note: check Vagrantfile content and fix IP 192.168.33.9 >> 192.168.56.9
Step B: Configure GitLab
-
Connect to the integration server:
vagrant ssh
-
Edit the GitLab configuration file:
sudo nano /etc/gitlab/gitlab.rb
-
Replace
external_url http://hostname
with:external_url 'http://192.168.56.9/gitlab'
-
Replace
# unicorn['port'] = 8080
with:unicorn['port'] = 8088
-
-
Reconfigure and restart GitLab:
sudo gitlab-ctl reconfigure sudo gitlab-ctl restart unicorn sudo gitlab-ctl restart
-
Access GitLab in your browser at http://192.168.56.9/gitlab/ and create a user with a password (minimum 8 characters). (12345678)
-
Create a second user in GitLab:
- Visit http://192.168.56.9/gitlab/users/sign_in
- Enter the following details:
- Username: dev
- Email: [email protected]
- Password: 12345678
If you need to reset a GitLab user's password, follow the instructions here.
- Use the root account to approve user registrations:
- Go to http://192.168.56.9/gitlab/admin/users?filter=blocked_pending_approval
- Logout of gitlab but not vagrant
Step C: Configure Docker
-
Add the current user to the docker group to access the CLI:
sudo usermod -aG docker vagrant
-
Validate the Docker installation with the hello-world example:
docker run --name hello-world hello-world
Expected output:
Hello from Docker!
-
Remove the Docker container and image:
- To remove the container & the image:
docker rm hello-world docker rmi hello-world
- To remove the container & the image:
Step D: Use GitLab as VCS
-
Exit the Vagrant session:
exit
-
Change to the project directory:
cd ~/devops-master/pipeline/s1-create-skeleton/MavenHelloWorldProject
-
Login to GitLab using the non-root account and create a project at http://192.168.56.9/gitlab/projects/new#blank_project.
-
Configure Git globally with your user name and email:
git config --global user.name "dev" git config --global user.email "[email protected]"
-
Ensure the
pom.xml
file is in the root of the local repository. -
Create a
.gitignore
file to exclude logs, dev settings, and binaries:nano .gitignore
Add the following contents to the
.gitignore
file:# Binaries target/ # Log files *Log # Dev settings .settings
-
Initialize the Git repository, add the remote origin, commit, and push the project:
git init git remote add origin http://192.168.56.9/gitlab/dev/mavenhelloworldproject.git git add . git commit -m "Initial commit" git push -u origin master
Step E: Automate Build
-
Navigate to the integration server directory:
cd ~/devops-master/pipeline/s2-automate-build/integration-server
-
Connect to the integration server:
vagrant ssh
-
Install GitLab Runner:
sudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/v14.3.2/binaries/gitlab-runner-linux-amd64 sudo chmod +x /usr/local/bin/gitlab-runner sudo gitlab-runner install -u gitlab-runner gitlab-runner --version
-
Get the runner token for the project at http://192.168.56.9/gitlab/dev/mavenhelloworldproject/-/settings/ci_cd.
-
Register the runner:
sudo gitlab-runner register
Follow the prompts and use the provided token. Specify the runner description, tags, executor, and Docker image.
-
GitLab instance URL enter: http://192.168.56.9/gitlab/
-
Enter the token generated use previously generated
-
Enter for the description: docker
-
Enter the gitlab-ci tag: integration
-
Enter the executor: docker
-
For the docker image enter: alpine:latest
-
-
Restart the runner:
sudo gitlab-runner restart
-
Change the runner configuration to accept jobs without tags at http://192.168.56.9/gitlab/dev/mavenhelloworldproject/runners/1/edit.
Step F: Create GitLab CI
-
Exit the Vagrant session:
exit
-
Change to the project directory:
cd ~/devops-master/pipeline/s1-create-skeleton/MavenHelloWorldProject
-
Create a
.gitlab-ci.yml
configuration file:nano .gitlab-ci.yml
Add the following contents to the
.gitlab-ci.yml
file:image: maven:latest stages: - build - test - run cache: paths: - target/ build_app: stage: build script: - mvn compile test_app: stage: test script: - mvn test run_app: stage: run script: - mvn package - mvn exec:java -Dexec.mainClass="com.jcg.maven.App"
-
Push the changes to GitLab:
git add . git commit -m "Added GitLab CI" git push -u origin master
-
Inspect the CI/CD pipelines at http://192.168.56.9/gitlab/dev/mavenhelloworldproject/-/pipelines.
Step G: Storing the "Binary"
-
Modify the
.gitlab-ci.yml
file to include a deploy stage:nano .gitlab-ci.yml
Add - deploy to "stages" as below, and add a "deploy_app" with stage with artifact storage:
stages: - build - test - run - deploy deploy_app: stage: deploy script: - echo "Deploy review app" artifacts: name: "my-app" paths: - target/*.jar
-
Push the changes to GitLab:
git add . git commit -m "Added deploy step to GitLab pipeline" git push -u origin master
-
Inspect the CI/CD pipelines at http://192.168.56.9/gitlab/dev/mavenhelloworldproject/-/pipelines.
These organized and concise instructions guide you through setting up an automated build process using GitLab, Docker, and GitLab Runner.