Skip to content

Commit

Permalink
Add pre_create_command to driver
Browse files Browse the repository at this point in the history
This is following [equivalent work for
kitchen-docker](test-kitchen/kitchen-docker#249)

Example use case marcy-terui#1:  Logging into AWS ECR prior to running a kitchen test so the test images can be retrieved
Example use case marcy-terui#2:  Running `bundle exec berks update` to refresh the
Berksfile.lock prior to running tests
  • Loading branch information
ysgard committed May 7, 2018
1 parent c0992a4 commit a8c2c9d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,18 @@ Example:
docker_base: sudo /path/to/lxc-console
```

### pre_create_command

A script or shell command to run locally prior to creating the
container. Used to prep the build environment, e.g. performing a login
to a private docker repository where the test images are housed.

Example:

```yml
pre_create_command: ./path/to/script.sh
```

## <a name="development"></a> Development

* Source hosted at [GitHub][repo]
Expand Down
12 changes: 12 additions & 0 deletions lib/kitchen/driver/docker_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,22 @@ def default_platform
end

def create(state)
pre_create_command
state[:image] = build(state) unless state[:image]
state[:container_id] = run(state) unless state[:container_id]
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 destroy(state)
instance.transport.connection(state) do |conn|
begin
Expand Down

0 comments on commit a8c2c9d

Please sign in to comment.