Setup docker test kitchen for Chef cookbook examples


Setup docker test :

blu@ubuntu-test01:~$ cat setup_chefdk_ubuntu.sh
#wget https://packages.chef.io/files/stable/chefdk/1.3.43/ubuntu/16.04/chefdk_1.3.43-1_amd64.deb
#sudo dpkg -i chefdk_*.deb
#chef verify
#sleep 5
echo ‘eval “$(chef shell-init bash)”‘ >> ~/.bash_profile
source ~/.bash_profile
mkdir ~/chef-repo/.chef
blu@ubuntu-test01:~$

blu@ubuntu-test01:~$ cat setup_docker.sh
sudo apt-key adv –keyserver hkp://p80.pool.sks-keyservers.net:80 –recv-keys 58118E89F3A912897C070ADBF76221572C52609D
sudo apt-add-repository ‘deb https://apt.dockerproject.org/repo ubuntu-xenial main’
sudo apt-get update
apt-cache policy docker-engine
sudo apt-get install -y docker-engine
sudo systemctl status docker

#sudo usermod -aG docker $(whoami)

#sudo usermod -aG docker ## example : $ sudo usermod -aG docker blu
#docker docker-subcommand –help
docker info
#docker run hello-world
docker search ubuntu
docker pull ubuntu
docker run ubuntu
docker images

#docker run -it ubuntu
# https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04
# https://cloud.docker.com/
# https://docs.docker.com/engine/userguide/

blu@ubuntu-test01:~$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d8d0fb9aaa99 ubuntu “/bin/bash” 18 minutes ago Up 18 minutes networktest

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

kitchen test: ( on RHEL 7.0):

448 cd git_cookbook/
449 cat .kitchen.yml
450 berks install
451 kitchen init
452 kitchen create
453 sudo kitchen create
455 kitchen list
457 kitchen login
458 kitchen converge
459 kitchen verify

[chef@chefTest001 git_cookbook]$ pwd
/export/home/chef/cookbook/git_cookbook

[chef@chefTest001 git_cookbook]$ ls -la
total 36
drwxrwxr-x. 7 chef chef 4096 May 6 02:01 .
drwxrwxr-x. 10 chef chef 4096 May 6 00:21 ..
-rw-rw-r–. 1 chef chef 47 May 5 23:50 Berksfile
-rw——-. 1 chef chef 89 May 6 02:03 Berksfile.lock
-rw-rw-r–. 1 chef chef 1133 May 5 23:50 chefignore
drwxrwxr-x. 3 chef chef 64 May 5 23:50 .delivery
-rw-rw-r–. 1 chef chef 185 May 5 23:50 .gitignore
drwxrwxr-x. 3 chef chef 86 May 6 02:01 .kitchen
-rw-rw-r–. 1 chef chef 399 May 6 01:59 .kitchen.yml
-rw-rw-r–. 1 chef chef 603 May 5 23:50 metadata.rb
-rw-rw-r–. 1 chef chef 60 May 5 23:50 README.md
drwxrwxr-x. 2 chef chef 23 May 5 23:50 recipes
drwxrwxr-x. 3 chef chef 38 May 5 23:50 spec
drwxrwxr-x. 3 chef chef 20 May 5 23:50 test

[chef@chefTest001 git_cookbook]$ cat .kitchen.yml

driver:
name: docker
use_sudo: false

provisioner:
name: chef_solo
always_update_cookbooks: true

verifier:
name: inspec

platforms:
– name: ‘centos’
driver_plugin: docker
driver:
use_sudo: false
image: centos:7
suites:
– name: default
run_list:
– recipe[git_cookbook::default]
verifier:
inspec_tests:
– test/recipes
attributes:
[chef@chefTest001 git_cookbook]$

[chef@chefTest001 git_cookbook]$ sudo kitchen create
—–> Starting Kitchen (v1.13.2)
—–> Creating …
Sending build context to Docker daemon 63.49 kB
Step 1 : FROM centos:7
—> a8493f5f50ff
Step 2 : ENV container docker
—> Using cache
—> cd4f34c2a359
Step 3 : RUN yum clean all
—> Using cache
—> e57827f1b45a
Step 4 : RUN yum install -y sudo openssh-server openssh-clients which curl
—> Using cache
—> 98d0bbc9addc
Step 5 : RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ”
—> Using cache
—> ad964f0e4ec1
Step 6 : RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ”
—> Using cache
—> 1171ee68fc65
Step 7 : RUN if ! getent passwd kitchen; then useradd -d /home/kitchen -m -s /bin/bash -p ‘*’ kitchen; fi
—> Using cache
—> adf344a1c27e
Step 8 : RUN echo “kitchen ALL=(ALL) NOPASSWD: ALL” >> /etc/sudoers
—> Using cache
—> 9366130369e8
Step 9 : RUN echo “Defaults !requiretty” >> /etc/sudoers
—> Using cache
—> c84da9dac217
Step 10 : RUN mkdir -p /home/kitchen/.ssh
—> Using cache
—> a93af0df0297
Step 11 : RUN chown -R kitchen /home/kitchen/.ssh
—> Using cache
—> 40d10af1a509
Step 12 : RUN chmod 0700 /home/kitchen/.ssh
—> Using cache
—> f6ca60f49247
Step 13 : RUN touch /home/kitchen/.ssh/authorized_keys
—> Using cache
—> 786812c8cff7
Step 14 : RUN chown kitchen /home/kitchen/.ssh/authorized_keys
—> Using cache
—> b4769fcf9c5d
Step 15 : RUN chmod 0600 /home/kitchen/.ssh/authorized_keys
—> Using cache
—> 34137ca6012b
Step 16 : RUN echo ssh-rsa\ AAAAB3NzaC1yc2EAAAADAQABAAABAQD5OPccUfzFS7QWobVYo4ZcU953IV\+TMsYby8U1EwDApxktasuFvL5EeZKcIpoa9T7yTrcrc2eoHhLx3dzHZn5KiilZmj7ifI2\+c7nscNgP68Br15xbCCyRRILa3DNGdbwCvlNWPQST\+dIOgnhvB2krT8jm8ppB8E/3tyRCgwvKNWNs9jVOJKWqgQHfanpu4upQKsqbwv04cEOZ5fnivqTG90QvVOaG724czxcrdxkWcZMV6n9ztFwVTxcf11smyjZF0xCqHV9GoIxWhhbSCakn5uc9GnjHdrpeTcCPh9vDOn71TQrmaU8CFpwLK4dgVnvQGxVh1v4147XakGCGmbut\ kitchen_docker_key >> /home/kitchen/.ssh/authorized_keys
—> Running in 9e5593989577
—> f07bfba007d4
Removing intermediate container 9e5593989577
Successfully built f07bfba007d4
84dd0e5f49a7606b995cd82d3f85cc5932571814f5da5b42355be35dd44b413b
0.0.0.0:32771
[SSH] Established
Finished creating (0m3.20s).
—–> Kitchen is finished. (0m4.26s)

[chef@chefTest001 git_cookbook]$ sudo kitchen list
Instance Driver Provisioner Verifier Transport Last Action
default-centos Docker ChefSolo Inspec Ssh Created

[chef@chefTest001 git_cookbook]$ kitchen list
Instance Driver Provisioner Verifier Transport Last Action
default-centos Docker ChefSolo Inspec Ssh Created

[chef@chefTest001 git_cookbook]$ kitchen ssh
Could not find command “ssh”.

[chef@chefTest001 git_cookbook]$ kitchen login
Last login: Fri May 5 20:31:56 2017 from 172.17.0.1

[kitchen@84dd0e5f49a7 ~]$ exit
logout
Connection to localhost closed.

[chef@chefTest001 git_cookbook]$ kitchen converge
—–> Starting Kitchen (v1.13.2)
—–> Converging …
Preparing files for transfer
Preparing dna.json
Resolving cookbook dependencies with Berkshelf 5.2.0…
Removing non-cookbook files before transfer
Preparing solo.rb
—–> Installing Chef Omnibus (install only if missing)
Downloading https://omnitruck.chef.io/install.sh to file /tmp/install.sh
Trying curl…
Download complete.
el 7 x86_64
Getting information for chef stable for el…
downloading https://omnitruck.chef.io/stable/chef/metadata?v=&p=el&pv=7&m=x86_64
to file /tmp/install.sh.60/metadata.txt
trying curl…
sha1 f0eac57e53833d710334839fbe4e9b940d1c43c6
sha256 a3cb30fe2eb6e3ce5ea8914635d01562660f4978568fa3303b14336eefdb09ee
url https://packages.chef.io/files/stable/chef/13.0.118/el/7/chef-13.0.118-1.el7.x86_64.rpm
version 13.0.118
downloaded metadata file looks valid…
downloading https://packages.chef.io/files/stable/chef/13.0.118/el/7/chef-13.0.118-1.el7.x86_64.rpm
to file /tmp/install.sh.60/chef-13.0.118-1.el7.x86_64.rpm
trying curl…
Comparing checksum with sha256sum…

WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING

You are installing an omnibus package without a version pin. If you are installing
on production servers via an automated process this is DANGEROUS and you will
be upgraded without warning on new releases, even to new major releases.
Letting the version float is only appropriate in desktop, test, development or
CI/CD environments.

WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING

Installing chef
installing with rpm…
warning: /tmp/install.sh.60/chef-13.0.118-1.el7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 83ef826a: NOKEY
Preparing… ################################# [100%]
Updating / installing…
1:chef-13.0.118-1.el7 ################################# [100%]
Thank you for installing Chef!
Transferring files to
Starting Chef Client, version 13.0.118
[2017-05-05T20:34:14+00:00] WARN: Plugin Network: unable to detect ipaddress
[2017-05-05T20:34:14+00:00] WARN: Plugin Network: unable to detect ipaddress
Creating a new client identity for default-centos using the validator key.
resolving cookbooks for run list: [“git_cookbook::default”]
Synchronizing Cookbooks:
– git_cookbook (0.1.0)
Installing Cookbook Gems:
Compiling Cookbooks…
Converging 1 resources
Recipe: git_cookbook::default
* log[This is default git recipe] action write

Running handlers:
Running handlers complete
Chef Client finished, 1/1 resources updated in 01 seconds
Finished converging (0m28.97s).
—–> Kitchen is finished. (0m30.11s)
[chef@chefTest001 git_cookbook]$ kitchen verify
—–> Starting Kitchen (v1.13.2)
—–> Setting up …
Finished setting up (0m0.00s).
—–> Verifying …
Using `/export/home/chef/cookbook/git_cookbook/test/recipes/default` for testing

Target: ssh://kitchen@localhost:32771

User root
✔ should exist
○ This is an example test, replace with your own test.
Port 80
✔ should not be listening
○ This is an example test, replace with your own test.

Test Summary: 2 successful, 0 failures, 2 skipped
Finished verifying (0m0.73s).
—–> Kitchen is finished. (0m1.90s)

· © 2017 Cephswift · Designed by Cephswift.com ·