Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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
Expand Down
13 changes: 12 additions & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
34 changes: 34 additions & 0 deletions deploy/master/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
3 changes: 3 additions & 0 deletions deploy/master/logs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash -el

docker-compose logs -f
9 changes: 9 additions & 0 deletions deploy/master/restart.sh
Original file line number Diff line number Diff line change
@@ -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)"

4 changes: 2 additions & 2 deletions deploy/master/start.sh → deploy/master/wipe.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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)"

16 changes: 16 additions & 0 deletions sync.sh
Original file line number Diff line number Diff line change
@@ -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