Vagrantfile: Support docker provider.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
Anders Kaseorg 2019-05-20 04:07:25 +00:00 committed by Tim Abbott
parent 4c8f9f07d7
commit 684ebc2a5e
3 changed files with 62 additions and 1 deletions

7
Vagrantfile vendored
View File

@ -159,6 +159,13 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
vb.vmx["numvcpus"] = vm_num_cpus vb.vmx["numvcpus"] = vm_num_cpus
end end
config.vm.provider "docker" do |d, override|
override.vm.box = nil
d.build_dir = File.join(__dir__, "tools", "setup", "dev-vagrant-docker")
d.has_ssh = true
d.create_args = ["--ulimit", "nofile=1024:65536"]
end
$provision_script = <<SCRIPT $provision_script = <<SCRIPT
set -x set -x
set -e set -e

View File

@ -310,7 +310,13 @@ def install_apt_deps(deps_to_install, retry=False):
# setup-apt-repo does an `apt-get update` # setup-apt-repo does an `apt-get update`
run_as_root(["./scripts/lib/setup-apt-repo"]) run_as_root(["./scripts/lib/setup-apt-repo"])
run_as_root(["apt-get", "-y", "install", "--no-install-recommends"] + deps_to_install) run_as_root(
[
"env", "DEBIAN_FRONTEND=noninteractive",
"apt-get", "-y", "install", "--no-install-recommends",
]
+ deps_to_install
)
def install_yum_deps(deps_to_install, retry=False): def install_yum_deps(deps_to_install, retry=False):
# type: (List[str], bool) -> None # type: (List[str], bool) -> None

View File

@ -0,0 +1,48 @@
FROM ubuntu:18.04
# Basic packages and dependencies of docker-systemctl-replacement
RUN echo locales locales/default_environment_locale select en_US.UTF-8 | debconf-set-selections \
&& echo locales locales/locales_to_be_generated select "en_US.UTF-8 UTF-8" | debconf-set-selections \
&& apt-get update \
&& apt-get install --no-install-recommends -y \
ca-certificates \
curl \
locales \
lsb-release \
openssh-server \
python3 \
sudo \
systemd \
&& rm -rf /var/lib/apt/lists/*
RUN \
# We use https://github.com/gdraheim/docker-systemctl-replacement
# to make services we install like postgres, redis, etc. normally
# managed by systemd start within Docker, which breaks normal
# operation of systemd.
dpkg-divert --add --rename /bin/systemctl \
&& curl -so /bin/systemctl 'https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/b0588e003562f9a8eb76c98512c6d61146a81980/files/docker/systemctl3.py' \
&& chmod +x /bin/systemctl \
&& ln -nsf /bin/true /usr/sbin/policy-rc.d \
&& mkdir -p /run/sshd \
# docker-systemctl-replacement doesnt work with template units yet:
# https://github.com/gdraheim/docker-systemctl-replacement/issues/62
&& ln -ns /lib/systemd/system/postgresql@.service /etc/systemd/system/postgresql@10-main.service \
&& ln -s /etc/systemd/system/postgresql@10-main.service /etc/systemd/system/multi-user.target.wants/ \
# redis fails to start with the default configuration if IPv6 is disabled:
# https://github.com/antirez/redis/pull/5598
&& dpkg-divert --add --rename /etc/default/redis-server \
&& printf 'ULIMIT=65536\nDAEMON_ARGS="/etc/redis/redis.conf --bind 127.0.0.1"\n' > /etc/default/redis-server \
&& mkdir /etc/systemd/system/redis-server.service.d \
&& printf '[Service]\nExecStart=/usr/bin/redis-server /etc/redis/redis.conf --bind 127.0.0.1\n' > /etc/systemd/system/redis-server.service.d/override.conf \
# Set up the vagrant user and its SSH key (globally public)
&& useradd -ms /bin/bash vagrant \
&& mkdir -m 700 ~vagrant/.ssh \
&& curl -so ~vagrant/.ssh/authorized_keys 'https://raw.githubusercontent.com/hashicorp/vagrant/be7876d83644aa6bdf7f951592fdc681506bcbe6/keys/vagrant.pub' \
&& chown -R vagrant: ~vagrant/.ssh \
&& echo 'vagrant ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/vagrant
CMD ["/bin/systemctl"]
EXPOSE 22
EXPOSE 9991