Infrastructure test becomes more important. There are several tools for continuous delivery of infrastructure layer.
KitchenCI (test-kitchen) provides a test harness to execute infrastructure code on one or more platforms in isolation.
Although KitchenCI uses Vagrant to operate virtual machines in default, kitchen-docker enables docker driver to operate on docker container.
We can realize automated infrastructure test on drone.io by this plugin.
Docker in Docker
Drone runs a test on docker container. Because KitchenCI builds container and provisions Chef recipes into it, What executing KitchenCI on drone means building container in the container. It is called Docker in Docker (dind).
We need a small work to run dind, officially dind images are provided on docker hub. A tag including “dind” is for dind usage.
Firstly, you need to write services section in .drone.yml to enable dind. Port 2375 is docker port. You need to turn on “Trusted” flag on your project because dind image requires the privileged flag.
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
pipeline: | |
build: | |
image: aberrios85/drone-kitchen | |
commands: | |
– kitchen test | |
services: | |
docker: | |
image: plugins/docker | |
image: docker:1.12-dind | |
privileged: true | |
command: [ "–storage-driver=vfs", "–tls=false" ] |
Because the ChefDK package does not installed kitchen-docker, you must prepare installed docker image. This article uses aberrios85/drone-kitchen.
When using docker socket of dind from other containers, set DOCKER_HOST as follows, turn reference port to what set in the service section.
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
pipeline: | |
build: | |
image: docker:latest | |
environment: | |
– DOCKER_HOST=tcp://docker:2375 | |
commands: | |
– docker info |
Kitchen-docker Settings
To use dind docker socket in KitchenCI, change config file .kitchen.yml as follows. Socket section enables to change the docker port.
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
driver: | |
name: docker | |
socket: tcp://docker:2375 |
It will take a long time to create, converge, setup, verify and destroy, however, automated infrastructure test will work well.
Running dind containers without the trusted flag
The trusted flag can be set only administrators, the general user feels pain.
If only reliable users access to the drone, setting the environment variable DRONE_ESCALATE to docker on drone server, drone makes privileged enable automatically.