Skip to content

Commit

Permalink
Merge pull request #29 from trevor-vaughan/support_rootless_podman
Browse files Browse the repository at this point in the history
Add Podman Support
  • Loading branch information
genebean authored Feb 14, 2021
2 parents 6358385 + 9d36b42 commit e823cd4
Show file tree
Hide file tree
Showing 5 changed files with 736 additions and 562 deletions.
96 changes: 83 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,94 @@ Beaker library to use docker hypervisor

This gem that allows you to use hosts with [docker](docker.md) hypervisor with [beaker](https://github.com/puppetlabs/beaker).

Beaker will automatically load the appropriate hypervisors for any given hosts file, so as long as your project dependencies are satisfied there's nothing else to do. No need to `require` this library in your tests.
Beaker will automatically load the appropriate hypervisors for any given hosts
file, so as long as your project dependencies are satisfied there's nothing else
to do. No need to `require` this library in your tests.

## With Beaker 3.x

This library is included as a dependency of Beaker 3.x versions, so there's nothing to do.

## With Beaker 4.x

As of Beaker 4.0, all hypervisor and DSL extension libraries have been removed and are no longer dependencies. In order to use a specific hypervisor or DSL extension library in your project, you will need to include them alongside Beaker in your Gemfile or project.gemspec. E.g.
In order to use a specific hypervisor or DSL extension library in your project,
you will need to include them alongside Beaker in your Gemfile or
project.gemspec. E.g.

~~~ruby
# Gemfile
gem 'beaker', '~>4.0'
gem 'beaker-aws'
gem 'beaker', '~> 4.0'
gem 'beaker-docker'
# project.gemspec
s.add_runtime_dependency 'beaker', '~>4.0'
s.add_runtime_dependency 'beaker-aws'
s.add_runtime_dependency 'beaker', '~> 4.0'
s.add_runtime_dependency 'beaker-docker'
~~~

## Nodeset Options

The following is a sample nodeset:

~~~yaml
HOSTS:
el8:
platform: el-8-x86_64
hypervisor: docker
image: centos:8
docker_cmd: '["/sbin/init"]'
# Run arbitrary things
docker_image_commands:
- 'touch /tmp/myfile'
dockeropts:
Labels:
thing: 'stuff'
HostConfig:
Privileged: true
el7:
platform: el-7-x86_64
hypervisor: docker
image: centos:7
# EL7 images do not support nested systemd
docker_cmd: '/usr/sbin/sshd -D -E /var/log/sshd.log'
CONFIG:
docker_cap_add:
- AUDIT_WRITE
~~~

## Privileged containers

Containers are **not** run in privileged mode by default for safety.

If you wish to enable privileged mode, simply set the following in your node:

~~~yaml
dockeropts:
HostConfig:
Privileged: true
~~~

## Cleaning up after tests

Containers created by this plugin may not be destroyed unless the tests complete
successfully. Each container created is prefixed by `beaker-` to make filtering
for clean up easier.

A quick way to clean up all nodes is as follows:

~~~sh
podman rm -f $( podman ps -q -f name="beaker-*" )
~~~

# Working with `podman`

If you're using a version of `podman` that has API socket support then you
should be able to simply set `DOCKER_HOST` to your socket and connect as usual.

You also need to ensure that you're using a version of the `docker-api` gem that
supports `podman`.

You may find that not all of your tests work as expected. This will be due to
the tighter system restrictions placed on containers by `podman`. You may need
to edit the `dockeropts` hash in your nodeset to include different flags in the
`HostConfig` section.

See the
[HostConfig](https://any-api.com/docker_com/engine/docs/Definitions/HostConfig)
portion of the docker API for more information.

# Spec tests

Spec test live under the `spec` folder. There are the default rake task and therefore can run with a simple command:
Expand All @@ -34,7 +103,8 @@ bundle exec rake test:spec

# Acceptance tests

There is a simple rake task to invoke acceptance test for the library:
There is a simple rake task to invoke acceptance test for the library:

```bash
bundle exec rake test:acceptance
```
Expand Down
24 changes: 13 additions & 11 deletions acceptance/config/nodes/hosts.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
HOSTS:
ubuntu1604-64-1:
platform: ubuntu-1604-x86_64
centos8:
platform: el-8-x86_64
hypervisor: docker
image: ubuntu:16.04
image: centos:8
roles:
- master
- agent
Expand All @@ -12,22 +12,24 @@ HOSTS:
- classifier
- default
docker_cmd: '["/sbin/init"]'
docker_cap_add:
- AUDIT_WRITE
dockeropts:
Labels:
one: '1'
two: '2'
ubuntu1604-64-2:
platform: ubuntu-1604-x86_64
centos7:
platform: el-7-x86_64
hypervisor: docker
image: ubuntu:16.04
image: centos:7
roles:
- agent
docker_cmd: '["/sbin/init"]'
docker_cmd: '/usr/sbin/sshd -D -E /var/log/sshd.log'
use_image_entrypoint: true
dockeropts:
HostConfig:
Privileged: true
CONFIG:
nfs_server: none
consoleport: 443
log_level: verbose
dockeropts:
Labels:
one: '3'
two: '4'
11 changes: 3 additions & 8 deletions beaker-docker.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,14 @@ Gem::Specification.new do |s|
# Testing dependencies
s.add_development_dependency 'rspec', '~> 3.0'
s.add_development_dependency 'rspec-its'
# pin fakefs for Ruby < 2.3
if RUBY_VERSION < "2.3"
s.add_development_dependency 'fakefs', '~> 0.6', '< 0.14'
else
s.add_development_dependency 'fakefs', '~> 0.6'
end
s.add_development_dependency 'rake', '~> 10.1'
s.add_development_dependency 'fakefs', '~> 1.3'
s.add_development_dependency 'rake', '~> 13.0'
s.add_development_dependency 'simplecov'
s.add_development_dependency 'pry', '~> 0.10'

# Run time dependencies
s.add_runtime_dependency 'stringify-hash', '~> 0.0.0'
s.add_runtime_dependency 'docker-api', '< 2.0.0'
s.add_runtime_dependency 'docker-api', '< 3.0.0'

end

Loading

0 comments on commit e823cd4

Please sign in to comment.