Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Latest commit d57b395 Mar 21, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md random fixes Mar 21, 2019
hugo.yaml add second example: hugo in a container Mar 18, 2019
tmux-top-tests.yaml add first part: containerized tests Mar 17, 2019

README.md

Building container images with Ansible

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.

Requirements

We'll do two common use cases in this workshop:

  1. Containerizing a test suite.
  2. Running a web app in a container.

Containerizing your tests

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

Hugo in a container

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
You can’t perform that action at this time.