Skip to content

GranitTreff on 03.06.2020 talk Git in Software Development

Notifications You must be signed in to change notification settings

Gepardec/GranitTreff-030620

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Git in Software Development

This repository holds the sample application and CI/CD infrastructure definition for illustrating Git in Software Development.

Description

This repository provides a sample application which is build on the CI/CD infrastructure to illustrate the relation of Git Branches, Versions and CI/CD.

Description

This repository holds the sample application and CI/CD infrastructure definition used for illustrating the relation of Git Branches, Versions and CI/CD in action. The infrastructure consists of the following services and platforms.

  • Docker

  • Kubernetes

  • Jenkins CI/CD

  • Jenkins Docker JNLP Agent

  • Nexus Repsoitory Manager

Infrastructure
Figure 1. CI/CD Infrastructure

Preparations

Docker Hub

You will need a Docker Hub account where the built Container Images are pushed to during the builds.

Github

You will need a Github account and a personal access token for your user which is used to clone the repository.

Windows Host

Install Docker Desktop for Windows and ensure that

  • the daemon is exposed via tcp://localhost:2375,

  • that the C drive is shared

  • and that Kubernetes is started.

Important
Docker Desktop for Windows will create the Kubernetes configuration file ~/.kube/config which you will need to provide as a secret file.

WSL 2 (Ubuntu 20.04.LTS or Debian 10.x)

Install Docker as described here.

Important
If you start a docker container and get the error message cgroups: cannot find cgroup mount destination: unknown.. Apply the temporary fix as described here
Temporary fix for the mount issue
sudo mkdir /sys/fs/cgroup/systemd
sudo mount -t cgroup -o none,name=systemd cgroup /sys/fs/cgroup/systemd

Install kind as described here.

Create a Kubernetes within Docker
# With a custom configuration to bind the api server to '0.0.0.0:6443'
kind create cluster --config ./kind.yml
Important
kind will install Kubernetes in Docker and create the Kubernetes configuration file ~/.kube/config which you will need to provide as a secret file. Be aware that the config file will define the server as https://0.0.0.0:6443 whereby you will have to change the IP to the Docker Gateway IP.
Tip
I have implemented an Ansible bundle for setting up my WSL2 instance which you can use to setup a Debian WSL2 distro. The bundle will already take case about the systemd mount issue for you.

Configurations

Secret Files

Create the following secret files which are used in the docker/docker-compose.yml file. The content of the files is the secret value.

  • docker/secrets/kubeConfig.txt
    The base64 encoded Kubernetes config file.
    Ensure that only the configuration of the intended cluster is contained and the server address is properly set

  • docker/secrets/nexusPassword.txt
    The nexus password

  • docker/secrets/dockerHubPassword.txt
    The Docker Hub password of your user

  • docker/secrets/githubAccessToken.txt
    The Github personal access token of your user

  • docker/secrets/jenkinsAdminPassword.txt
    The Jenkins administrator password

Env File

The following environment variables needs to be defined for docker-compose. The simplest way to provide them is to create a .env file in the ./docker directory.

  • DOCKER_HOST_URI
    The Docker Host URI in the form of tcp://<HOST>:<PORT>

  • JNLP_JENKINS_URL
    The Jenkins URL used by the jnlp docker agent in the form of http://<HOST>:<PORT>;

  • JNLP_NEXUS_URL
    The Nexus URL used by the builds within a jnlp docker agent in the form of http://<HOST>:<PORT>;

  • RUN_AS
    Defines with which use the jenkins container shall run. Either root or jenkins

  • JENKINS_PORT
    The port Jenkins is exposed to

  • GITHUB_USERNAME
    Your github username

  • NEXUS_PORT
    The port Nexus shall be exposed to

  • DOCKER_HUB_REGISTRY_REPOSITORY
    The docker Hub repository name

  • DOCKER_HUB_USERNAME
    The docker Hub username

  • KUBERNETES_URL
    The api url of your Kubernetes cluster

  • JENKINS_AGENT_IMAGE_TAG
    Either you use my build cchet/jenkins-inbound-agent-custom:1.0 available on Docker Hub or you build it yourself (agent/Dockerfile) and make it available to your Docker environment

Important
With Docker Desktop for Windows set the environment varibales to:
DOCKER_HOST_URI=tcp://host.docker.internal:2375
RUN_AS=root
JNLP_JENKIS_URL=http://host.docker.internal:<JENKINS_PORT>
JNLP_NEXUS_URL=http://host.docker.internal:<NEXUS_PORT>
KUBERNETES_URL=https://kubernetes.docker.internal:6443
With WSL2 or with a native Linux OS set the environment variables to:
DOCKER_HOST_URI=tcp://<DOCKER_GATEWAY_IP>:2375
RUN_AS=jenkins
JNLP_JENKIS_URL=http://<DOCKER_GATEWAY_IP>:<JENKINS_PORT>
JNLP_NEXUS_URL=http://<DOCKER_GATEWAY_IP>:<NEXUS_PORT>
KUBERNETES_URL=https://<DOCKER_GATEWAY_IP>:6443
See here why.
You can retrieve the DOCKER_GATEWAY_IP via docker network inspect bridge

Example configuration files are located at doc/examples/.

Kubernetes Dashboard (Optional)

  1. Install the dashboard
    kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.1/aio/deploy/recommended.yaml

  2. Start the kube-proxy
    kubectl proxy

  3. List the secrets in the kubernetes-dashbaord namespace
    kubectl get secret -n kubernetes-dashboard

  4. Get the secret token from the service account name like kubernetes-dashboard-token-xxxxx
    kubectl describe secret kubernetes-dashboard-token-xxxxx -n kubernetes-dashboard

  5. Go to localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/ and login with the retrieved token

Important
If you start the Kubernetes Proxy from within a WSL 2 instance, then you need to add the parameter --address 0.0.0.0, otherwise you won’t be able to access it from the Windows host.

Setup

  1. Go to ./docker/

  2. Execute docker-compose build

  3. Execute docker-compose up -d

  4. Execute docker-compose exec nexus cat /opt/sonatype/sonatype-work/nexus3/admin.password to get the generated admin password

  5. Go to http://localhost:<NEXUS_PORT>;

  6. Login with admin:<INITIAL_PASSWORD>

  7. Follow the wizard and define the new admin password NEXUS_PASSWORD

  8. Go to http://localhost:<JENKINS_PORT>;

  9. Login with admin:<JENKINS_ADMIN_PASSWORD>

  10. Got to the build job and see how they went

  11. Go to http://localhost:<NEXUS_PORT>/#browse/browse and see the pushed snapshot/release artifacts, which have a different version depending on the branch they have been build from

  12. Go to https://hub.docker.com/repository/docker/<DOCKER_HUB_REGISTRY_REPOSITORY>/microservice-quarkus and see the pushed images, which have a different tag depending on the branch they have been build from

  13. Go to http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/ and login with the Kubernetes Secret token and see if the deployments were successful.

Important
The first time your defined NEXUS_PASSWORD was most likely invalid, because you haven’t changed it before the builds started. Just trigger all of the builds and it will work

About

GranitTreff on 03.06.2020 talk Git in Software Development

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published