GithubHelp home page GithubHelp logo

mbagliojr / jenkins-slave Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 1.29 MB

This repository creates a Jenkins slave that utilizes the hosts Docker installation. This creates docker sibling containers unlike Docker-In-Docker

License: Apache License 2.0

Dockerfile 100.00%

jenkins-slave's Introduction

dind-jenkins-slave

Docker-in-Docker Jenkins Slave

Docker Container

Contains:

Can be used as Jenkins slave that can compile containers with Captain and run with docker or docker-compose.

Requirements

  • Docker installed
  • Jenkins master running inside Docker in same Host as Slaves (Can be scaled with Ambassador pattern to other hosts)
  • Jenkins master with open JNLP port (you may want to fix the port at "Manage Jenkins - Configure Global Security - TCP port for JNLP slave agents")
  • Jenkins master with Swarm Plugin installed

Run Docker-in-Docker Jenkins Slave

To run the Docker-in-Docker Jenkins Slave:

docker run -d -v /root/microservices-parent:/microservices-parent -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/bin/docker --name=jenkins-slave -e EXTRA_PARAMS="-master http://{HOST}:{PORT} -disableSslVerification -executors 2" mbagliojr/jenkins-slave:1.0.0```

It will:

* launch the container in `privileged` mode
* Connect the docker socket inside the container to reuse the running docker service
* Link jenkins master container
* Run in the background

In case more parameters are needed to be passed to swarm plugin CLI use **EXTRA_PARAMS** variable. Possible variables:

-autoDiscoveryAddress VAL : Use this address for udp-based auto-discovery (default 255.255.255.255) -description VAL : Description to be put on the slave -disableSslVerification : Disables SSL verification in the HttpClient. -executors N : Number of executors -fsroot FILE : Directory where Jenkins places files -help (--help) : Show the help screen -labels VAL : Whitespace-separated list of labels to be assigned for this slave. Multiple options are allowed. -master VAL : The complete target Jenkins URL like 'http://server :8080/jenkins'. If this option is specified, auto-discovery will be skipped -mode MODE : The mode controlling how Jenkins allocates jobs to slaves. Can be either 'normal' (utilize this slave as much as possible) or 'exclusive' (leave this machine for tied jobs only). Default is normal. -name VAL : Name of the slave -password VAL : The Jenkins user password -username VAL : The Jenkins username for authentication


Example:

docker run -d -v /root/microservices-parent:/microservices-parent -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/bin/docker --name=jenkins-slave -e EXTRA_PARAMS="-master http://{HOST}:{PORT} -disableSslVerification -executors 2" mbagliojr/jenkins-slave:1.0.0


# Run A Jenkins Master + Slave

To run a complete Jenkins Master + Slave pack, clone this project and use docker-compose inside the clonned directory:

docker-compose up -d


If you get a permissions error on startup, you need to give ownership to uid 1000 the /opt/jenkins directory where the docker engine runs.

For example if you use docker-machine and your machine name is 'dev', do:

docker-machine ssh dev 'chown -R 1000:1000 /opt/jenkins'


Once the stack is up with docker-compose (master+slave) then open a browser on port 8080 to connect with Jenkins:
- Manage Jenkins -> Manage Plugins -> Available: Install "Self-Organizing Swarm Plug-in Modules" (no restart needed)

Once install is finished, the slave will automatically be connected.

To test it:
- Create new Jobs -> Freestyle project
  - Restrict where this project can be run: swarm
  - Add Build Step -> Execute Shell: docker ps
- Build Now

On the job result you'll be able to see that slave has connected with the docker engine and shows the running containers.

jenkins-slave's People

Contributors

mbagliojr avatar sasmibagl 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.