Tuesday, February 15, 2022

ASSIGNMENT - Gitlab CICD (mvnrepo) with solution and yaml file config!

 


Assignment

Maven Project Gitlab CICD Pipeline


1. Create and Clone the Gitlab Private Repo (mavenRepo)

2. Setup an Access Token for your account for pulling and pushing the code into mavenRepo.

3. Generate a maven archetype and push those changes to the maven repo

4. Setup local git lab runner with some tags(localrunner,localshell)

5. Push the code from local repo into remote repo (mavenRepo).

6. Create .gitlab-ci.yml file for your ci cd pipeline

7. Create a build stage where a jar file into a target folder of your maven local project

8. Create a test stage you need to check that jar file exist in the target folder.

9. Create a parallel test case that is a dummy stage.(echo "Testing is done")

10 Deploy your application by running java -cp command


Solution:

1. Create and Clone the Gitlab Private Repo (mavenRepo)
- Created new repo on Gitlab (mavenRepo)
- Cloned repository to local system via ssh using: git clone git@gitlab.com:jeromechong02/mavenrepo.git
- > ls to check if folder had been cloned successfully (yes)

2. Setup an Access Token for your account for pulling and pushing the code into mavenRepo.
- On GitLab go to Edit Profile>Access Tokens and add a personal access token (select all scopes)
- Save token (glpat-fNU5x1ypYuMvVizfUiRS)

3. Generate a maven archetype and push those changes to the maven repo
- In CLI enter: mvn archetype:generate fill in properties
- Project created from Archetype in dir: /home/vagrant/mvnRepo
- To push changes to the maven repo:
- > mvn compile
- > cd mvnRepo/
- > ls
- > cp -r * /home/vagrant/mavenrepo/
- > cd ..
- > ls mavenrepo/
- > git status
- > cd mavenrepo/
- > git status
- > git add -A
- > git commit -m "mavenRepo project is added"
- > git push origin main
- Checked repo on GitLab to confirm if files are synced (yes) 

4. Setup local git lab runner with some tags(localrunner,localshell)
- On GitLab go to Settings>CD/CD>Runners and view specific runner details.
- In CLI enter: sudo gitlab-runner register
- Details: https://gitlab.com/; 6n4Wez_wb2Ue-yP_spfe; mavenRepo registration token; localrunner, localshell
- Check runner under “Available specific runners”

5. Push the code into mavenRepo.
- In CLI enter: ssh-keygen
- Key generated: SHA256:egt3utnq7nR+6uj0S4PGxpZw74+IQSz15ndVwP2CLeM
- touch test.js

6. Create .gitlab-ci.yml file for your ci cd pipeline
- On GitLab, Repository>Files> + New File (select template .gitlab-ci.yml)
- Commit changes and check (passed)



stages:
  - build
  - test
  - deploy
build:
    stage: build
    tags:
        - localrunner  
        - localshell
    script: 
        - cd /home/vagrant/mvnrepo
        - sudo mvn clean package
test:
    stage: test
    tags:
        - localrunner  
        - localshell
    script:
        - sudo ls /home/vagrant/mvnrepo/target/*.jar    
newtest:
    stage: test
    tags:
        - localrunner  
        - localshell
    script:
        - sudo touch /home/vagrant/mvnrepo/passtest    
deploy:
    stage: deploy
    tags:
        - localrunner  
        - localshell
    script:
        - cd /home/vagrant/mvnrepo 

- sudo java -cp target/myproj-1.0-SNAPSHOT.jar com.irfan.App 

No comments:

Post a Comment

Fluentd

Open-source log data collector > why logs? - for compliance (auditing, company, business) - for security (transparency, monitoring, admin...