Skip to content

prgcont/workshop-ansible-containers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published