Skip to content

Commit

Permalink
vagrant: Install docker and docker-compose via setup.sh
Browse files Browse the repository at this point in the history
Without this a user needs to run vagrant more than once the first time they
try this out, once to fetch the vagrant-docker-compose plugin and then again
to actually run through. Why go through that when we already have code for
install docker and docker-compose that we have to maintain seprately anyway
and leads to a better first experience too?

Another minor benefit is that we increase the code sharing between terraform
and vagrant's setup.sh, which is nice.

Signed-off-by: Manuel Mendez <[email protected]>
  • Loading branch information
mmlb committed Mar 18, 2022
1 parent d8005c6 commit 970eb48
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
8 changes: 0 additions & 8 deletions deploy/vagrant/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
PROVISIONER_IP = "192.168.56.4"
MACHINE1_IP = "192.168.56.43"

unless Vagrant.has_plugin?("vagrant-docker-compose")
system("vagrant plugin install vagrant-docker-compose")
puts "Dependencies installed, please try the command again."
exit
end

Vagrant.configure("2") do |config|
config.vm.provider :libvirt do |libvirt|
libvirt.qemu_use_session = false
Expand Down Expand Up @@ -37,8 +31,6 @@ Vagrant.configure("2") do |config|
override.vm.synced_folder "../compose/", "/vagrant/compose/", type: "rsync"
end

provisioner.vm.provision :docker
provisioner.vm.provision :docker_compose, compose_version: "1.29.2"
provisioner.vm.provision :shell, path: "setup.sh", args: [PROVISIONER_IP, MACHINE1_IP]
end

Expand Down
33 changes: 33 additions & 0 deletions deploy/vagrant/setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
#!/usr/bin/env bash

install_docker() {
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
update_apt
apt-get install --no-install-recommends containerd.io docker-ce docker-ce-cli
}

install_docker_compose() {
apt-get install --no-install-recommends python3-pip
pip install docker-compose
}

apt-get() {
DEBIAN_FRONTEND=noninteractive command apt-get \
--allow-change-held-packages \
--allow-downgrades \
--allow-remove-essential \
--allow-unauthenticated \
--option Dpkg::Options::=--force-confdef \
--option Dpkg::Options::=--force-confold \
--yes \
"$@"
}

update_apt() {
apt-get update
apt-get upgrade
}

setup_layer2_network() {
host_addr=$1
ip addr show dev eth1 | grep -q "$host_addr" && return 0
Expand Down Expand Up @@ -47,6 +76,10 @@ main() {
local host_addr=$1
local worker_addr=$2

update_apt
install_docker
install_docker_compose

setup_layer2_network "$host_addr"

setup_compose_env_overrides "$host_addr" "$worker_addr"
Expand Down

0 comments on commit 970eb48

Please sign in to comment.