Code Monkey home page Code Monkey logo

devops-lab5's Introduction

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

  1. Navigate to the working directory:

    cd ~/devops-master/pipeline/s2-automate-build/integration-server
  2. Create the missing data folder:

    mkdir ../../data
    
    # or 
    sudo rm -R ../../data && mkdir ../../data
  3. 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

  1. Connect to the integration server:

    vagrant ssh
  2. 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
      
  3. Reconfigure and restart GitLab:

    sudo gitlab-ctl reconfigure
    sudo gitlab-ctl restart unicorn
    sudo gitlab-ctl restart
  4. Access GitLab in your browser at http://192.168.56.9/gitlab/ and create a user with a password (minimum 8 characters). (12345678)

  5. Create a second user in GitLab:

If you need to reset a GitLab user's password, follow the instructions here.

  1. Use the root account to approve user registrations:

Step C: Configure Docker

  1. Add the current user to the docker group to access the CLI:

    sudo usermod -aG docker vagrant
  2. Validate the Docker installation with the hello-world example:

    docker run --name hello-world hello-world

    Expected output:

    Hello from Docker!
    
  3. Remove the Docker container and image:

    • To remove the container & the image:
      docker rm hello-world
      docker rmi hello-world
      

Step D: Use GitLab as VCS

  1. Exit the Vagrant session:

    exit
  2. Change to the project directory:

    cd ~/devops-master/pipeline/s1-create-skeleton/MavenHelloWorldProject
  3. Login to GitLab using the non-root account and create a project at http://192.168.56.9/gitlab/projects/new#blank_project.

  4. Configure Git globally with your user name and email:

    git config --global user.name "dev"
    git config --global user.email "[email protected]"
  5. Ensure the pom.xml file is in the root of the local repository.

  6. 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
    
  7. 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

  1. Navigate to the integration server directory:

    cd ~/devops-master/pipeline/s2-automate-build/integration-server
  2. Connect to the integration server:

    vagrant ssh
  3. 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   
  4. Get the runner token for the project at http://192.168.56.9/gitlab/dev/mavenhelloworldproject/-/settings/ci_cd.

  5. Register the runner:

    sudo gitlab-runner register

    Follow the prompts and use the provided token. Specify the runner description, tags, executor, and Docker image.

    1. GitLab instance URL enter: http://192.168.56.9/gitlab/

    2. Enter the token generated use previously generated

    3. Enter for the description: docker

    4. Enter the gitlab-ci tag: integration

    5. Enter the executor: docker

    6. For the docker image enter: alpine:latest

  6. Restart the runner:

    sudo gitlab-runner restart
  7. 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

  1. Exit the Vagrant session:

    exit
  2. Change to the project directory:

    cd ~/devops-master/pipeline/s1-create-skeleton/MavenHelloWorldProject
  3. 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"
  4. Push the changes to GitLab:

    git add .
    git commit -m "Added GitLab CI"
    git push -u origin master
  5. Inspect the CI/CD pipelines at http://192.168.56.9/gitlab/dev/mavenhelloworldproject/-/pipelines.

Step G: Storing the "Binary"

  1. 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
  2. Push the changes to GitLab:

    git add .
    git commit -m "Added deploy step to GitLab pipeline"
    git push -u origin master
  3. 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.

devops-lab5's People

Contributors

milad-mrz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.