martedì 10 aprile 2018

How to install a Jenkins Docker image with Chef

Inside the cookbooks folder in our chef-repo (read here for more info about chef-repo and here for open a free account on chef-server) we must create a cookbook named mydocker:
chef generate cookbook mydocker
in /mydocker folder we edit metadata.rb file and insert this:
depends 'docker', '~> 2.0'
edit default.rb in /mydocker/recipe/ and add this:
## install and start docker
docker_service 'default' do
  action [:create, :start]
end
## create a folder for volumes docker jenkins
execute "run a script" do
  user "root"
  command <<-EOH
  mkdir -p /home/jenkins_home/secrets/ /
  chmod -R 777 /home/jenkins_home/
  EOH
end
## pull the jenkins image
docker_image 'jenkins' do
    tag 'latest'
    action :pull
end

## run container
docker_container 'my_jenkins' do
    repo 'jenkins'
    tag 'latest'
    port '50000:50000'
    port '8081:8080'
    volumes "/home/jenkins_home/secrets/:/var/jenkins_home/secrets/"
end
with the terminal, inside the mydocker folder upload the cookbook on your chef-server:
berks install
berks upload
create a node relative to your machine (vps, vagrant etc…), for more info about this step read here:
knife bootstrap 127.0.0.1 --ssh-port 2200 --ssh-user myuser --sudo --identity-file /my/path/private_key -N nameofYourMachine
now add the mydocker cookbook to your node:
knife node run_list add nameOfYourNode "recipe[mydocker]"
From terminal, connected in ssh at your machine, launch chef-client command:
sudo chef-client
Now if we connect to the ip of the machine, at the port :8081 we shoud must see Jenkins run and ask us to insert the password:
we can find the password in our docker volumes; from terminal launch this command:
less /home/jenkins_home/secrets/initialAdminPassword
and we can see the password for jenkins installation:
Good Luck!

Nessun commento:

Posta un commento

Install Elasticsearch on Ubuntu

ELK STACK install Java sudo apt-get install default-jdk Elasticsearch 6 wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch...