Creating development and testing environments with Weave footloose


I’ve been a long time user of Vagrant. It’s invaluable for spinning up local test and development environments. Recently I learned about Weave’s footloose project, which provides a similar experience to Vagrant. But instead of using virtual machines, it utilizes containers. To see if this project would improve my workflows, I spent some time with it last weekend. Getting started is super easy. First, you need to grab the footloose binary from the release page:

$ curl -L0 -o footloose https://github.com/weaveworks/footloose/releases/download/0.6.3/footloose-0.6.3-linux-x86_64 && chmod 755 footloose

To set up a new environment, you will first need to create a configuration file with the “config create” option:

$ footloose config create -n centos --replicas 3

This will create a file named footloose.yaml in your current working directory:

$ cat footloose.yaml

cluster:
  name: centos
  privateKey: cluster-key
machines:
- count: 3
    spec:
    backend: docker
    image: quay.io/footloose/centos7:0.6.3
    name: node%d
    portMappings:
    - containerPort: 22

The configuration file contains the name of the cluster, the number of containers to provision, the docker image to use, etc. To create a new cluster, you can run footloose with the “create” option:

$ time footloose create -c footloose.yaml

INFO[0000] Docker Image: quay.io/footloose/centos7:0.6.3 present locally
INFO[0000] Creating machine: cluster-node0 ...          
INFO[0001] Creating machine: cluster-node1 ...          
INFO[0002] Creating machine: cluster-node2 ...          

real  0m3.811s
user  0m0.796s
sys 0m0.763s

The first time I ran this, I was blown away! Less than four seconds to provision 3 working containers that look and feel like VMs. Nice! To see your footloose containers, you can use the “show” command:

$ footloose show

NAME           HOSTNAME   PORTS           IP           IMAGE                             CMD          STATE     BACKEND
centos-node0   node0      0->{22 32780}   172.17.0.2   quay.io/footloose/centos7:0.6.3   /sbin/init   Running   docker
centos-node1   node1      0->{22 32781}   172.17.0.3   quay.io/footloose/centos7:0.6.3   /sbin/init   Running   docker
centos-node2   node2      0->{22 32782}   172.17.0.4   quay.io/footloose/centos7:0.6.3   /sbin/init   Running   docker

You can also check the docker “ps” command to see the containers that were created:

$ docker ps -a | grep foot

30ae19361b43        quay.io/footloose/centos7:0.6.3   "/sbin/init"             6 seconds ago       Up 5 seconds        0.0.0.0:32782->22/tcp       centos-node2
b6249e884d71        quay.io/footloose/centos7:0.6.3   "/sbin/init"             7 seconds ago       Up 6 seconds        0.0.0.0:32781->22/tcp       centos-node1
da7580c41f30        quay.io/footloose/centos7:0.6.3   "/sbin/init"             9 seconds ago       Up 8 seconds        0.0.0.0:32780->22/tcp       centos-node0

Super cool! Now to take these for a drive. Footloose has a “ssh” option which can be used to interact with a footloose node:

$ footloose ssh -c footloose.yaml root@node0 uptime

 06:50:30 up 1 day, 19:09,  0 users,  load average: 0.65, 0.64, 0.63

You can also ssh in and interact with the container directly:

$ footloose ssh root@node0

$ ps auxww

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0  42956  3108 ?        Ss   07:38   0:00 /sbin/init
root        18  0.0  0.0  39084  2940 ?        Ss   07:38   0:00 /usr/lib/systemd/systemd-journald
root        46  0.0  0.0 112920  4312 ?        Ss   07:38   0:00 /usr/sbin/sshd -D
root        60  1.0  0.0 152740  5720 ?        Ss   07:43   0:00 sshd: root@pts/1
dbus        62  0.0  0.0  58108  2252 ?        Ss   07:43   0:00 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
root        63  0.3  0.0  26380  1660 ?        Ss   07:43   0:00 /usr/lib/systemd/systemd-logind
root        64  0.3  0.0  15260  1972 pts/1    Ss   07:43   0:00 -bash
root        77  0.0  0.0  55184  1868 pts/1    R+   07:43   0:00 ps auxww

$ yum -y install nginx

As part of my typical testing workflow, I use Ansible playbooks to customize my Vagrant boxes. This is also possible with footloose:

$ cat inventory

[all]
centos-node0 ansible_connection=docker
centos-node1 ansible_connection=docker
centos-node2 ansible_connection=docker

The inventory files specify docker as the connection type, allowing ansible and ansible-playbook to run against the footloose containers:

$ ansible -i inventory -a uptime all

centos-node2 | CHANGED | rc=0 >>
 06:59:19 up 1 day, 19:18,  0 users,  load average: 2.46, 1.06, 0.76
centos-node1 | CHANGED | rc=0 >>
 06:59:19 up 1 day, 19:18,  0 users,  load average: 2.46, 1.06, 0.76
centos-node0 | CHANGED | rc=0 >>
 06:59:19 up 1 day, 19:18,  0 users,  load average: 2.46, 1.06, 0.76

$ ansible-playbook -i inventory haproxy.yml all

Given the short boot times, and the fact that I can re-use my existing playbooks, I see myself making extensive use of footloose in the future!!!

This article was posted by on 2020-05-11 00:00:00 -0500 -0500