Last active
June 14, 2016 11:28
-
-
Save Gisleburt/0176f78adf5d25bdb347531d565833e0 to your computer and use it in GitHub Desktop.
WIP: Attempting to bring up rancher server + rancher host
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
# Install required plugins | |
system "echo We will need your root access" | |
system "sudo echo Thankies!" | |
required_plugins = %w( vagrant-hostsupdater ) | |
required_plugins.each do |plugin| | |
system "vagrant plugin install #{plugin}" unless Vagrant.has_plugin? plugin | |
end | |
# Main Vagrant configuration | |
Vagrant.configure(2) do |config| | |
# MASTER | |
# This will run rancher-server and allow us to orchestrate our containers | |
config.vm.define "master" do |master| | |
master.vm.box = "coreos-beta" | |
master.vm.box_url = "https://storage.googleapis.com/beta.release.core-os.net/amd64-usr/current/coreos_production_vagrant.json" | |
master.vm.hostname = "master.localhost" | |
master.vm.network "private_network", ip: "192.168.100.101" | |
master.vm.network "forwarded_port", guest: 8080, host: 8080 | |
master.vm.provider "virtualbox" do |vb| | |
vb.memory = "768" | |
end | |
master.vm.provision "shell", inline: <<MASTER_SCRIPT | |
mkdir -p /var/lib/mysql | |
MASTER_SCRIPT | |
master.vm.provision "docker" do |docker| | |
docker.run "rancher/server:stable", | |
args: "-p 8080:8080 -v /var/lib/mysql:/var/lib/mysql --name rancher-master", | |
daemonize: true, | |
restart: "always" | |
end | |
end | |
# HOST | |
# This is where our containers will run | |
config.vm.define "host" do |host| | |
host.vm.box = "coreos-beta" | |
host.vm.box_url = "https://storage.googleapis.com/beta.release.core-os.net/amd64-usr/current/coreos_production_vagrant.json" | |
host.vm.hostname = "host.localhost" | |
host.vm.network "private_network", ip: "192.168.100.102" | |
# Registry | |
host.vm.network "forwarded_port", guest: 5000, host: 5000 | |
# Rancher Host | |
host.vm.network "forwarded_port", guest: 500, host: 500 | |
host.vm.network "forwarded_port", guest: 4500, host: 4500 | |
host.vm.provider "virtualbox" do |vb| | |
vb.memory = "8192" | |
end | |
host.vm.provision "shell", inline: <<HOST_SCRIPT | |
mkdir -p /var/lib/rancher | |
mkdir -p /var/lib/registry | |
mkdir -p /var/lib/jenkins | |
chmod a+rwX /var/lib/jenkins | |
HOST_SCRIPT | |
host.vm.provision "docker" do |docker| | |
docker.run "rancher/agent:v1.0.1", | |
args: "-e CATTLE_AGENT_IP='192.168.100.102' --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher --name rancher-agent-init", | |
cmd: "http://192.168.100.101:8080", | |
daemonize: true, | |
restart: "on-failure" | |
docker.run "registry:2.4.1", | |
args: "-p 5000:5000 -v /var/lib/registry:/tmp/registry-dev --name registry", | |
daemonize: true, | |
restart: "always" | |
docker.run "jenkins:1.651.2-alpine", | |
args: "-p 8080:8080 -p 50000:50000 -v /var/lib/jenkins:/var/jenkins_home --name jenkins", | |
daemonize: true, | |
restart: "always" | |
end | |
# Set up jenkins | |
host.vm.provision "shell", inline: <<HOST_SCRIPT_PART_2 | |
# Make sure Jenkins is up to date. | |
# Once this command is complete we can be sure Jenkins is running. | |
# We'll restart later | |
until docker exec -i jenkins java -jar /var/jenkins_home/war/WEB-INF/jenkins-cli.jar -s http://localhost:8080 list-plugins 2> /dev/null | awk '{print $1}' | xargs docker exec -i jenkins java -jar /var/jenkins_home/war/WEB-INF/jenkins-cli.jar -s http://localhost:8080 install-plugin 2> /dev/null | |
do | |
echo "Waiting for Jenkins to start..." | |
sleep 5 | |
done | |
# Add the pipeline plugin (legacy plugin name) | |
docker exec -i jenkins java -jar /var/jenkins_home/war/WEB-INF/jenkins-cli.jar -s http://localhost:8080 install-plugin workflow-aggregator | |
# Add global variable plugin (we'll use this to make Jenkinsfile more flexible) | |
docker exec -i jenkins java -jar /var/jenkins_home/war/WEB-INF/jenkins-cli.jar -s http://localhost:8080 install-plugin global-variable-string-parameter | |
# Add the git plugin | |
docker exec -i jenkins java -jar /var/jenkins_home/war/WEB-INF/jenkins-cli.jar -s http://localhost:8080 install-plugin git | |
# Finally restart | |
docker exec -i jenkins java -jar /var/jenkins_home/war/WEB-INF/jenkins-cli.jar -s http://localhost:8080 safe-restart | |
HOST_SCRIPT_PART_2 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment