Skip to content

Latest commit

 

History

History
139 lines (112 loc) · 3.75 KB

SETUP.md

File metadata and controls

139 lines (112 loc) · 3.75 KB

SPW4 - Exercise 3 Setup Instructions

GitLab

Execute GitLab runner locally in a WSL 2 shell:

  1. Start WSL 2 shell, get root privileges, update and install packages:

    wsl -d Debian
    sudo -i
    apt update
    apt upgrade
    apt install nano curl git
  2. Create a Docker network for all containers:

    docker network create runner-net
  3. Download GitLab runner:

    cd /root
    # for Linux on Intel-based CPUs:
    curl -o gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
    # for macOS on Intel-based CPUs:
    curl -o gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-amd64
    # for macOS on ARM-based CPUs:
    curl -o gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-arm64
    chmod 755 gitlab-runner
  4. Register runner with docker executor:

    • default image for docker executor: maven:3.9.7-eclipse-temurin-21
    /root/gitlab-runner register
  5. Register runner with shell executor:

    /root/gitlab-runner register
  6. Tweak runner config:

    nano /etc/gitlab-runner/config.toml
    • add network_mode = "runner-net" to runner config, i.e.:
    [[runners]]
      ...
      executor = "docker"
      ...
      [runners.docker]
        ...
        network_mode = "runner-net"   # run containers in custom network
  7. Start the runner:

    • press Ctrl+C to terminate the runner
    /root/gitlab-runner run
  8. Remove everything, if the runner is not needed anymore:

    rm -rf /root/gitlab-runner
    rm -rf /root/builds
    rm -rf /etc/gitlab-runner
    docker network rm runner-net

GitHub

Setup local CI/CD environment for deployment job in GitHub Actions:

  1. Create and run a container for hosting the servlet using Tomcat:

    docker run -d --name github-runner --network runner-net -p 8081:8080 tomcat:9.0-jdk21
  2. Open a shell in the container:

    docker exec -it github-runner /bin/bash
  3. Update and install packages:

    apt update
    apt upgrade
    apt install maven curl
  4. Change permissions on /usr/local/tomcat/webapps to world read-/writeable:

    chmod 777 /usr/local/tomcat/webapps
  5. Create a new user for running the GitHub self-hosted runner and switch to that user:

    adduser github-runner
    su -l github-runner
  6. Install and run self-hosted runner for Linux X64 as explained in the settings of your repository (Settings → Actions → Runners)

  7. To stop the runner, press Ctrl+C.

  8. If the runner is not needed anymore, exit the container shell and then stop and remove the container:

    docker stop github-runner
    docker rm github-runner

SonarQube

Integrate SonarQube for static code quality analysis:

  1. Create and run a SonarQube container:

    # for Intel-based CPUs:
    docker run -d --name sonarqube --restart always \
               --network runner-net -p 9000:9000 \
               -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true \
               sonarqube:10.4.1-community
    
    # for ARM-based CPUs:
    docker run -d --name sonarqube --restart always \
               --network runner-net -p 9000:9000 \
               -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true \
               mwizner/sonarqube:9.4.0-community
  2. Log in to SonarQube (initial credentials: admin/admin), create a new project, and adapt CI/CD config accordingly