Skip to content

ronaldtse/kitchen-docker_cli

 
 

Repository files navigation

Kitchen::DockerCli

Gem Version
Build Status Circle CI
Join the chat at https://gitter.im/marcy-terui/kitchen-docker_cli

A Test Kitchen Driver(and Transport) for Docker command line interface.

This plugin is created with only Docker CLI functions.
We can test on the environment that has no extra software such as sshd.

Requirements

  • Test-Kitchen (>= 1.3)

  • Docker (>= 1.3) This driver uses docker exec command.

  • tar (GNU Tar)

Installation and Setup

gem install kitchen-docker_cli

or put Gemfile in your project directory.

source 'https://rubygems.org'

gem 'kitchen-docker_cli'

and

bundle install

Configuration

At first, put your .kitchen(.local).yml like this.

---
driver:
  name: docker_cli

transport:
  name: docker_cli

platforms:
  - name: ubuntu-12.04
  - name: centos-6.4

suites:
  - name: default
    run_list:
    attributes:

Driver Configuration

image

The Docker image's path.

The default value get from platform.name.

Examples:

  image: marcy/amzn

platform

The Docker image's platform.

The default value get from platform.name.

Examples:

  platform: centos

command

The command to be executed at docker run.

The default value is sh -c 'while true; do sleep 1d; done;'.

Examples:

  command: /bin/bash

run_command

Adds RUN command(s) to Dockerfile.

The default value is nil.

Examples:

  run_command:
    - yum -y install httpd
    - service httpd start

environment

Adds ENV command(s) to Dockerfile.

The default value is nil.

Examples:

environment:
  http_proxy: http://proxy.example.com:8080/
  LANG: ja_JP.UTF-8

build_context

Pass the basedir as the Docker build context: 'docker build .' Default is 'false'.

no_cache

Not use the cached image on docker build.

The default value is false.

Examples:

  no_cache: true

privileged

Give extended privileges to the suite container.

The default value is false.

Examples:

  privileged: true

container_name

Set the name of container to link other container(s).

Examples:

  container_name: web

network

Set the Network mode for the container.

  • bridge: creates a new network stack for the container on the docker bridge
  • none: no networking for this container
  • container:<name|id>: reuses another container network stack
  • host: use the host network stack inside the container

Examples:

  network: host

hostname

Set hostname to container.

Examples:

  hostname: example.local

instance_host_name

Use instance name to hostname.

The default value is false.

Examples:

  instance_host_name: true

dns

The IP addresses of your DNS servers.

  dns: 8.8.8.8
  dns:
    - 8.8.8.8
    - 8.8.4.4

link

Set container_name(and alias) of other container(s) that connect from the suite container.

Examples:

 link: mysql:db
  link:
    - mysql:db
    - redis:kvs

publish

Publish a container's port or a range of ports to the host.

The default value is nil.

Examples:

  publish: 80
  publish:
    - 80:8080
    - 22:2222

publish_all

Publish all exposed ports to the host interfaces. This option used to communicate between some containers.

The default value is false.

Examples:

  publish_all: true

expose

Expose a port or a range of ports from the container without publishing it to your host.

The default value is nil.

Examples:

  expose: 80
  expose:
    - 80
    - 22

add_host

Add additional lines to /etc/hosts.

Examples:

  add_host: myhost:127.0.0.1
  add_host:
    - myhost:127.0.0.1
    - yourhost:123.123.123.123

volume

Adds data volume(s) to the container.

Examples:

  volume: /data
  volume:
    - /tmp:/tmp
    - <%= Dir::pwd %>:/var:rw

volumes_from

Mount data volume(s) from other container(s).

Examples:

  volumes_from: container_name
  volumes_from:
    - container_a
    - container_b

dockerfile

Create test image using a supplied Dockerfile, instead of the default Dockerfile created.
And it can be written as ERB template.
For best results, please:

  • Ensure Package Repositories are updated
  • Ensure Dockerfile installs sudo, curl, and tar
  • If Ubuntu/Debian, Set DEBIAN_FRONTEND to noninteractive
  dockerfile: my/dockerfile

dockerfile_vars

Template variables for the custom Dockerfile.

Example:

  • .kitchen.yml
driver:
  image: marcy/hoge
  dockerfile: dockerfile.erb
  dockerfile_vars:
    envs:
      LANG: ja_JP.UTF-8
    cmds:
      - yum -y install httpd
  • dockerfile.erb
FROM <%= config[:image] %>
<% @envs.each do |k,v| %>
ENV <%= k %> <%= v %>
<% end %>
<% @cmds.each do |c| %>
RUN <%= c %>
<% end %>
  • Result
FROM marcy/hoge
ENV LANG ja_JP.UTF-8
RUN yum -y install httpd

memory_limit

Constrain the memory available.

  memory_limit: 256m

cpu_shares

Change the priority of CPU Time.
This option with value 0 indicates that the running container has access to all 1024 (default) CPU shares.

  cpu_shares: 512

Transport Configuration

lxc_driver

If you use the LXC Driver of Docker (CircleCI), please set true

The default value is false

  lxc_driver: true

docker_base

Base of docker command.

The default value is docker

Example:

  docker_base: sudo /path/to/docker

lxc_attach_base

Base of lxc-attach command.
This option is used on LXC driver only.

The default value is sudo lxc-attach

Example:

  docker_base: sudo /path/to/lxc-attach

lxc_console_base

Base of lxc-console command.
This option is used on LXC driver only.

The default value is sudo lxc-console

Example:

  docker_base: sudo /path/to/lxc-console

Development

Pull requests are very welcome! Make sure your patches are well tested. Ideally create a topic branch for every separate change you make. For example:

  1. Fork the repo
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Authors

Created and maintained by Masashi Terui (marcy9114@gmail.com)

License

Apache 2.0 (see LICENSE)

About

Docker native CLI driver for Test-Kitchen

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 99.6%
  • HTML 0.4%