This workshop introduces the concept of building container images using Ansible playbooks as the definition format. We'll use ansible-bender to do the job, which utilizes ansible and buildah under the hood. For more info, see this slide deck.
- buildah is installed
- podman is installed
- ansible-bender is installed
- python 3.6+
- base image with python (can be 2)
- ansible 2.6+
We'll do two common use cases in this workshop:
- Containerizing a test suite.
- Running a web app in a container.
One of the common tasks in our team is to containerize our upstream test suite. Running tests in containers is awesome because the environment is the same no matter where it runs.
Let's run tests in a container for an existing project of mine: tmux-top. It is written in Go.
All we need to do is just write one Ansible playbook. Let's use this for a start:
---
- hosts: all
vars:
ansible_bender:
base_image: "fedora:29"
target_image:
name: tmux-top-tests
environment:
A: B
tasks: []
Our task now is to clone the upstream repo -
https://github.com/TomasTomecek/tmux-top/, and run the tests using make tests
.
For the complete solution, check tmux-top-tests.yaml.
You can then use the playbook to build the image:
$ ansible-bender build tmux-top-tests.yaml
And then run the tests afterwards:
$ podman run --rm -ti tmux-top-tests bash
$ cd /go/src/github.com/TomasTomecek/tmux-top/
$ make test
Let's containerize static site generator - Hugo.
The complete solution is available as hugo.yaml.
If we wanted to run this container in rootless podman, we would need to have podman 1.1+ because port forwarding for rootless is available since this version.
Let's run it in docker then! We need to push the image to dockerd first:
$ ansible-bender push docker-daemon:hugo:latest
Let's make sure that the metadata are correct:
$ docker inspect hugo
$ podman inspect hugo
We can run hugo now:
$ docker run -p 80:80 hugo
...and use sen to check it out:
$ sen