Skip to content

The purpose is to locally spin up a pre-configured Jenkins instance that uses Jenkins Kubernetes Plugin to dynamically create containers on specific namespaces for CI builds.

Notifications You must be signed in to change notification settings

theJaxon/jenkins-config-as-code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 

Repository files navigation

jenkins-config-as-code

Jenkins Kustomize

Table of Contents generated with DocToc

The purpose is to locally spin up a pre-configured Jenkins instance that uses Jenkins Kubernetes Plugin to dynamically create containers on specific namespaces for CI builds.

Using the project

  • Dockerfile is used to handle the installation of all the required Plugins.
  • Instructions below are for building on Kontainer8 Worker node
vagrant ssh worker

git clone https://github.com/theJaxon/jenkins-config-as-code.git

cd jenkins-config-as-code

# Create new image with plugins specified in Dockerfile pre-installed
podman build --tag jenkins-local .

# Save the image into tar file
podman save jenkins-local -o jenkins-local.tar

# Use ctr to import the image 
sudo ctr -n=k8s.io images import jenkins-local.tar

# Apply resources inside Deployment directory via Kustomize 
kustomize build Manifests | kubectl apply -f -

# Login username and password are admin

Integration with Kubernetes

  • The current cluster setup is the same as Kontainter8 project setup
  • To give Jenkins access to Spin up pods in any namespace there's a service account created, this SA gets tied to the cluster role cluster-admin
  • All this is handled via kustomization.yaml
  • Kustomize generates a configMap from JCasC.yaml file then the file gets mounted at /var/jenkins_home/casc_configs/JCasC.yaml
  • Configuration as code file is loaded via the environment variable CASC_JENKINS_CONFIG
  • Persistent Volume is created Via local-path provisioner with is the default storage class for Kontainer8

Jenkins Kubernetes cloud configuration

  • The connection between dynamic pods and jenkins is handled via jnlp-slave
  • For this a Pod template is created where the container name is jnlp, when the name changed it caused errors so it's kept as jnlp and the Pod template name is also jnlp
  • The template is pre-configured via jcasc

Sample Pipeline that relies on Kubernetes Plugin

podTemplate(containers: [
    containerTemplate(name: 'buildah', image: 'quay.io/buildah/stable', command: 'sleep', args: '99d', privileged: true),
    containerTemplate(name: 'maven', image: 'maven:3.8.6-jdk-11', command: 'sleep', args: '99d')]
    ) {
   node(POD_LABEL) {
     stage('Compile') {
       container('maven') {
         git url: 'https://github.com/quarkusio/quarkus-quickstarts.git', branch: 'main'
           dir("getting-started"){
             sh "mvn package"
            }
          }
        }

        stage('Image Build'){
          container('buildah'){
            // https://github.com/quarkusio/quarkus-quickstarts/tree/main/getting-started
            dir("getting-started"){
              sh"""
              container=\$(buildah from --name "quarkus-container" docker.io/amazoncorretto:11)
              buildah copy \$container target/quarkus-app/lib/ /deployments/lib/
              buildah copy \$container target/quarkus-app/*.jar /deployments/
              buildah copy \$container target/quarkus-app/app/ /deployments/app/
              buildah copy \$container target/quarkus-app/quarkus/ /deployments/quarkus/
              buildah config --entrypoint "java -jar /deployments/quarkus-run.jar -Dquarkus.http.host=0.0.0.0" \$container
              buildah commit \$container 723178642448.dkr.ecr.us-east-1.amazonaws.com/quarkus:latest
              buildah images
              buildah login -u AWS -p ${LOGIN_TOKEN} 723178642448.dkr.ecr.us-east-1.amazonaws.com
              buildah push 723178642448.dkr.ecr.us-east-1.amazonaws.com/quarkus:latest
              """
            }
          }
        }
   }
}

About

The purpose is to locally spin up a pre-configured Jenkins instance that uses Jenkins Kubernetes Plugin to dynamically create containers on specific namespaces for CI builds.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published