From c53d8fa9cb89e8a9cd4e194c644776240f2862b7 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Wed, 22 Jun 2016 12:00:45 -0400 Subject: [PATCH] setup.yml: cache buildimg container By far the longest step in provisioning a new VM is the building of the container. This helps alleviate things a little by caching it on the host. It's not a complete solution however. We also need to make it easy to update an existing container. Closes: #344 Approved by: cgwalters --- Vagrantfile | 2 +- vagrant/setup.yml | 44 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 998be56c..a5394d68 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -21,7 +21,7 @@ Vagrant.configure(2) do |config| # containers) config.vm.synced_folder ".", "/home/vagrant/sync", disabled: true config.vm.synced_folder ".", "/root/sync", type: "rsync", - rsync__exclude: [".git/"] + rsync__exclude: [".git/", "vagrant/*.tar.gz"] config.vm.provider "libvirt" do |libvirt, override| libvirt.cpus = 2 diff --git a/vagrant/setup.yml b/vagrant/setup.yml index 8835cc4d..b6368659 100644 --- a/vagrant/setup.yml +++ b/vagrant/setup.yml @@ -1,5 +1,6 @@ --- - hosts: all + gather_facts: no become: yes tasks: - name: add CAHC ostree remote @@ -13,14 +14,55 @@ - name: link nxs -> rpm-ostree file: src=/usr/bin/rpm-ostree dest=/usr/local/bin/nxs owner=0 group=0 state=link + # add a little bit of storage (default is 3G) or docker save complains + - name: resize root + shell: lvresize -L 4G -r /dev/atomicos/root && touch /root/.resized + args: + creates: /root/.resized + - name: check for builder image command: docker inspect rpm-ostree-builder failed_when: False changed_when: False register: inspect + - name: check for local cache of builder image + local_action: stat path=vagrant/buildimg.tar.gz + register: cache + become: no + + - set_fact: + # the image is available on the guest + on_guest: "{{ inspect.rc == 0 | bool }}" + # the image is available on the host + on_host: "{{ cache.stat.isreg is defined and cache.stat.isreg | bool }}" + + # sync them up, building if necessary + + # XXX: this is just a stopgap, we should also make it easy to update the + # container without having to rebuild it completely + + - name: copy cached builder image + copy: src=buildimg.tar.gz dest=/tmp + when: not on_guest and on_host + + - name: import cached builder image + shell: gunzip -c /tmp/buildimg.tar.gz | docker load + when: not on_guest and on_host + - name: build builder image command: make buildimg args: chdir: sync/vagrant - when: inspect.rc != 0 + when: not on_guest and not on_host + + - name: export builder image + shell: docker save rpm-ostree-builder | gzip -c > /tmp/buildimg.tar.gz + when: not on_host + args: + creates: /tmp/buildimg.tar.gz + + - name: fetch cached builder image + fetch: src=/tmp/buildimg.tar.gz dest=. flat=true + when: not on_host + become: no