Git Product home page Git Product logo

jenkins-config-as-code's Introduction

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
              """
            }
          }
        }
   }
}

jenkins-config-as-code's People

Contributors

thejaxon avatar yoyoraso avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

yoyoraso

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.