Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre_create_command #249

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
11 changes: 11 additions & 0 deletions lib/kitchen/driver/docker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down