diff --git a/Managing a Complex Multi-tier Jenkins environment - A Practical Approach of using Job DSL and GitOps.pdf b/Managing a Complex Multi-tier Jenkins environment - A Practical Approach of using Job DSL and GitOps.pdf index 2d82f58..59110a7 100644 Binary files a/Managing a Complex Multi-tier Jenkins environment - A Practical Approach of using Job DSL and GitOps.pdf and b/Managing a Complex Multi-tier Jenkins environment - A Practical Approach of using Job DSL and GitOps.pdf differ diff --git a/README.md b/README.md index 90d97ee..26e74d5 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ Beyond the original tutorial covering mostly base Jenkins and Docker topics some * [PR #2](https://github.com/Cervator/modern-jenkins/pull/2) - Better Gradle and Groovy integration * [PR #3](https://github.com/Cervator/modern-jenkins/pull/3) - Hooking up Job DSL including samples (later enhanced further) * [PR #4](https://github.com/Cervator/modern-jenkins/pull/4) - Hobo GitOps! Expand control further to include external DSL and Manifest repos +* [PR #5](https://github.com/Cervator/modern-jenkins/pull/5) - Use Gitea for embedded Git repos + sync files from workspace into Docker At this stage to see the new stuff in action from a fresh clone using Vagrant do the following: @@ -41,10 +42,15 @@ At this stage to see the new stuff in action from a fresh clone using Vagrant do * `cd /vagrant/images/jenkins-base` + `./build.sh` to build the first Docker image (the base for the other two images) * `cd ../jenkins-master/` + `./build.sh` to build the second image - this contains the Jenkins master itself * `cd ../jenkins-plugins/` + `./build.sh` to build the third and final image - this contains plugins, init scripts, and DSL stuff -* `cd ../../deploy/master/` + `./start.sh` to then actually use Docker Compose to stand up everything involved, launching Jenkins to http://localhost:8080 +* `cd ../../deploy/master/` + `./restart.sh` to then actually use Docker Compose to stand up everything involved + * Jenkins will be available at http://localhost:8080 + * Gitea will be available at http://localhost:3000 + * If you want to *wipe* volumes for both then use `./wipe.sh` instead of the restart script A presentation PDF is included with the repo that covers "Hobo GitOps" - eventually a webinar recording of some sort should become available :-) +A second presentation PDF is also included for a similar talk focusing on Incident Management + ## Future stuff Plans and ideas diff --git a/Vagrantfile b/Vagrantfile index a3fa1c5..89c36f9 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -12,7 +12,11 @@ Vagrant.configure("2") do |config| # Forward expected guest Jenkins to host 8080 config.vm.network "forwarded_port", guest: 8080, host: 8080 - # Use root on subsequent vagrant ssh calls because easy and secure, right? Throwaway dev box :-) + # Forward Gitea + config.vm.network "forwarded_port", guest: 3000, host: 3000 + config.vm.network "forwarded_port", guest: 2222, host: 2222 + + # Use root on subsequent vagrant ssh calls because easy and secure, right? Throwaway dev box, not for production! :-) if VAGRANT_COMMAND == "ssh" config.ssh.username = 'root' config.ssh.insert_key = 'false' @@ -35,4 +39,11 @@ Vagrant.configure("2") do |config| cp /home/vagrant/.ssh/authorized_keys /root/.ssh SHELL + + # Place a little script that'll run on boot (vagrant up / reload) and sync /vagrant -> /var/vagrant (for inner Docker sync) + config.vm.provision "file", source: "sync.sh", destination: "/tmp/sync.sh" + config.vm.provision "shell", inline: "mv /tmp/sync.sh /opt/sync.sh" + config.vm.provision "shell", inline: "chmod a+x /opt/sync.sh" + config.vm.provision "shell", inline: "/opt/sync.sh > /dev/null 2>&1 &", run: "always" + end diff --git a/deploy/master/docker-compose.yml b/deploy/master/docker-compose.yml index c94c3df..3c7e9d5 100644 --- a/deploy/master/docker-compose.yml +++ b/deploy/master/docker-compose.yml @@ -19,6 +19,11 @@ services: - dsl:/var/jenkins_home/dslScripts - ${PWD}/../../secure:/secure:ro + # This gets a little tricky. Vagrant maps the root of this workspace into /vagrant inside the Vagrant guest + # If that is mapped via Docker to be accessible inside a container then in some cases it may not sync "twice" + # As a solution we use a little rsync script that simply pushes files from the Vagrant mapping to this Docker one + - /var/vagrant:/var/vagrant + # Jenkins plugins' configuration plugins: image: modernjenkins/jenkins-plugins @@ -28,10 +33,39 @@ services: - groovy:/usr/share/jenkins/ref/init.groovy.d - dsl:/usr/share/jenkins/ref/dslScripts + # Bundled Gitea for easy access Git repos inside the setup + # NOTE: Having a local address (say for a Jenkins job's Git target) within the containers gets tricky + # See https://github.com/docker/for-linux/issues/264 - `gateway` seems to work on Linux, but may not on Win/Mac .. + web: + image: gitea/gitea:1.7.1 + volumes: + - data:/data + ports: + - "3000:3000" + - "2222:22" + depends_on: + - db + restart: always + db: + image: mariadb:10 + restart: always + environment: + - MYSQL_ROOT_PASSWORD=changeme + - MYSQL_DATABASE=gitea + - MYSQL_USER=gitea + - MYSQL_PASSWORD=changeme + volumes: + - db:/var/lib/mysql + # Define named volumes. These are what we use to share the data from one # container to another, thereby making our jenkins.war and plugins available volumes: + # Jenkins stuff plugins: warfile: groovy: dsl: + + # Gitea stuff + db: + data: \ No newline at end of file diff --git a/deploy/master/logs b/deploy/master/logs new file mode 100644 index 0000000..7a2ce69 --- /dev/null +++ b/deploy/master/logs @@ -0,0 +1,3 @@ +#!/bin/bash -el + +docker-compose logs -f \ No newline at end of file diff --git a/deploy/master/restart.sh b/deploy/master/restart.sh new file mode 100644 index 0000000..8a35237 --- /dev/null +++ b/deploy/master/restart.sh @@ -0,0 +1,9 @@ +#!/bin/bash -el + +echo "INFO: (re)Starting Jenkins & Gitea without volume wipe" +docker-compose stop +docker-compose up -d + +echo "INFO: Use the following command to watch the logs: " +echo "docker-compose logs -f (or just ./logs for short)" + diff --git a/deploy/master/start.sh b/deploy/master/wipe.sh old mode 100755 new mode 100644 similarity index 51% rename from deploy/master/start.sh rename to deploy/master/wipe.sh index 29bd546..134e7b7 --- a/deploy/master/start.sh +++ b/deploy/master/wipe.sh @@ -1,9 +1,9 @@ #!/bin/bash -el -echo "INFO: (re)Starting Jenkins" +echo "INFO: (re)Starting Jenkins & Gitea WITH volume wipe" docker-compose down -v docker-compose up -d echo "INFO: Use the following command to watch the logs: " -echo "docker-compose logs -f" +echo "docker-compose logs -f (or just ./logs for short)" diff --git a/sync.sh b/sync.sh new file mode 100755 index 0000000..b55144e --- /dev/null +++ b/sync.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# This script is meant to run inside Vagrant, synchronizing its mapping to the host OS to a secondary path +# That secondary path is then Docker-mapped into the Jenkins Master volume and accessible from there +# There is a limitation if trying to directly map the root of the workspace into /vagrant then directly into Docker + +# Delay just a bit - this gets triggered pretty early, may avoid some race conditions with the OS startup +sleep 10; + +while true; do + + rsync -avu --delete "/vagrant/" "/var/vagrant"; + + sleep 1; + +done