diff --git a/Vagrantfile b/Vagrantfile index dcff88d..c2b494c 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -4,8 +4,7 @@ VAGRANT_CONFIG_VERSION = "2" Vagrant.configure(VAGRANT_CONFIG_VERSION) do |config| - # Using the "contrib" version for vboxsf module for synced folders - config.vm.box = "debian/contrib-buster64" + config.vm.box = "debian/bookworm64" # Main application folder config.vm.synced_folder "tildes/", "/opt/tildes/" @@ -16,18 +15,11 @@ Vagrant.configure(VAGRANT_CONFIG_VERSION) do |config| config.vm.network "forwarded_port", guest: 9090, host: 9090 config.vm.provision "ansible_local" do |ansible| + ansible.install = true ansible.install_mode = "pip" - - # Since Debian Buster still uses Python 2.7 by default and the pip bootstrap - # script is no longer compatible with 2.7, we need to specify the installation - # command manually. If we upgrade to a newer version of Debian that defaults to - # Python 3.6+, this should no longer be necessary. - ansible.pip_install_cmd = "sudo apt-get install -y python3-distutils && curl -s https://bootstrap.pypa.io/get-pip.py | sudo python3" - - # Vagrant doesn't currently recognize the new format for Ansible versions - # (e.g. "ansible [core 2.11.1]"), so the compatibility mode is set incorrectly. - # A new version of Vagrant should resolve this soon. - ansible.compatibility_mode = "2.0" + ansible.version = "10.6.0" + ansible.pip_install_cmd = "sudo apt-get install -y python3-pip" + ansible.pip_args = "--break-system-packages" # put the VM into the "dev" and "app_server" Ansible groups ansible.groups = { @@ -43,4 +35,19 @@ Vagrant.configure(VAGRANT_CONFIG_VERSION) do |config| vb.memory = "4096" vb.cpus = "4" end + + config.vm.provider "docker" do |d, override| + # Docker does not require config.vm.box + override.vm.box = nil + # Instead, specify build_dir where Dockerfile is located. + d.build_dir = "./docker" + d.dockerfile = "Dockerfile-for-vagrant" + + # Keep Docker container running indefinitely + d.remains_running = true + d.create_args = ["--detach", "--tty"] + + # SSH configuration + d.has_ssh = true + end end diff --git a/docker/Dockerfile-for-vagrant b/docker/Dockerfile-for-vagrant new file mode 100644 index 0000000..b119d41 --- /dev/null +++ b/docker/Dockerfile-for-vagrant @@ -0,0 +1,33 @@ +FROM debian:12 +ENV container docker + +RUN useradd --create-home vagrant \ + && echo "vagrant:vagrant" | chpasswd \ + && groupadd wheel \ + && usermod -a -G wheel vagrant + +# allow vagrant to login +RUN cd ~vagrant \ + && mkdir .ssh \ + && echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" > .ssh/authorized_keys \ + && chown -R vagrant:vagrant .ssh \ + && chmod 0700 .ssh \ + && chmod 0600 .ssh/authorized_keys + +EXPOSE 22 + +# install sudo, sshd, git, python3 +RUN apt-get update && apt-get install -y sudo openssh-server git python3 + +# Enable passwordless sudo for the "vagrant" user +RUN mkdir -p /etc/sudoers.d +RUN install -b -m 0440 /dev/null /etc/sudoers.d/vagrant +RUN echo 'vagrant ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/vagrant + +# Use systemd replacement script to simulate systemd in Docker +# https://github.com/gdraheim/docker-systemctl-replacement +COPY systemctl3.py /usr/bin/systemctl +RUN test -e /bin/systemctl || ln -sf /usr/bin/systemctl /bin/systemctl +RUN chmod 0755 /usr/bin/systemctl +RUN systemctl enable ssh +CMD ["/usr/bin/systemctl"]