From 1741e45011f14b7f8638b079f8fb643f0352232e Mon Sep 17 00:00:00 2001 From: Patricia Jung Date: Wed, 21 Dec 2016 10:16:05 +0100 Subject: [PATCH] pre_create_command --- README.md | 12 ++++++++++++ lib/kitchen/driver/docker.rb | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/README.md b/README.md index 95f540cf..9c80e830 100644 --- a/README.md +++ b/README.md @@ -476,6 +476,18 @@ Examples: net: br3 ``` +### pre_create_command + +A shell command which is run locally before creating the container. +Used to prepare the build environment (e.g. to generate files +to be copied in the build process or used in converge stage). + +Examples: + +```yaml + pre_create_command: ./my_shell_script.sh +``` + ## Development * Source hosted at [GitHub][repo] diff --git a/lib/kitchen/driver/docker.rb b/lib/kitchen/driver/docker.rb index 58a30236..0d8300b0 100644 --- a/lib/kitchen/driver/docker.rb +++ b/lib/kitchen/driver/docker.rb @@ -116,6 +116,7 @@ def default_platform end def create(state) + pre_create_command generate_keys state[:username] = config[:username] state[:ssh_key] = config[:private_key] @@ -286,6 +287,16 @@ def dockerfile end end + def pre_create_command + if config[:pre_create_command] + system(config[:pre_create_command]) + if $?.exitstatus.nonzero? + raise ActionFailed, + "pre_create_command '#{config[:pre_create_command]}' failed to execute (exit status #{$?.exitstatus})" + end + end + end + def parse_image_id(output) output.each_line do |line| if line =~ /image id|build successful|successfully built/i