Skip to content

Commit

Permalink
Merge pull request #2632 from Varying-Vagrant-Vagrants/docker-provider
Browse files Browse the repository at this point in the history
Monolithic Docker provider
  • Loading branch information
tomjn authored Aug 3, 2023
2 parents 4e599f0 + 2dfd0e4 commit b678676
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 61 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ WIP

### Enhancements

* Monolithic docker beta support ( #2632 )
* Added the GMP PHP extension to the default PHP installation ( #2676 )

### Maintenance
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ _VVV stands for Varying Vagrant Vagrants._

## How To Use

To use it, download and install [Vagrant](https://www.vagrantup.com) and [VirtualBox](https://www.virtualbox.org/). Then, clone this repository and run:
To use it, download and install [Vagrant](https://www.vagrantup.com) and a provider such as [VirtualBox](https://www.virtualbox.org/), Docker, or Parallels Pro. Then, clone this repository and run:

```shell
vagrant plugin install --local
Expand Down
22 changes: 18 additions & 4 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Vagrant.require_version '>= 2.2.4'
require 'yaml'
require 'fileutils'
require 'pathname'
require 'socket'

def sudo_warnings
red = "\033[38;5;9m" # 124m"
Expand Down Expand Up @@ -216,9 +217,9 @@ defaults['memory'] = 2048
defaults['cores'] = 1
defaults['provider'] = 'virtualbox'

# if Arm default to parallels
# if Arm default to docker
if Etc.uname[:version].include? 'ARM64'
defaults['provider'] = 'parallels'
defaults['provider'] = 'docker'
end

# This should rarely be overridden, so it's not included in the config/default-config.yml file.
Expand Down Expand Up @@ -461,6 +462,19 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
override.vm.box = 'bento/ubuntu-20.04'
end

# Docker use image.
config.vm.provider :docker do |d, override|
d.image = 'pentatonicfunk/vagrant-ubuntu-base-images:20.04'
d.has_ssh = true
d.ports = [ "80:80" ] # HTTP
d.ports += [ "443:443" ] # HTTPS
d.ports += [ "3306:3306" ] # MySQL
d.ports += [ "8025:8025" ] # Mailhog

## Fix goodhosts aliases format for docker
override.goodhosts.aliases = { '127.0.0.1' => vvv_config['hosts'], '::1' => vvv_config['hosts'] }
end

# Virtualbox.
config.vm.provider :virtualbox do |_v, override|
# Default Ubuntu Box
Expand Down Expand Up @@ -514,7 +528,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Access to the guest machine is only available to your local host. To provide access to
# other devices, a public network should be configured or port forwarding enabled.
#
# Note: If your existing network is using the 192.168.50.x subnet, this default IP address
# Note: If your existing network is using the 192.168.56.x subnet, this default IP address
# should be changed. If more than one VM is running through VirtualBox, including other
# Vagrant machines, different subnets should be used for each.
#
Expand Down Expand Up @@ -884,7 +898,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
if config.vagrant.plugins.include? 'vagrant-goodhosts'
config.goodhosts.aliases = vvv_config['hosts']
config.goodhosts.remove_on_suspend = true

# goodhosts already disables clean by default, but lets enforce this at both ends
config.goodhosts.disable_clean = true
elsif config.vagrant.plugins.include? 'vagrant-hostsmanager'
Expand Down
1 change: 1 addition & 0 deletions config/default-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ vm_config:
# provider: hyperv
# provider: parallels
# provider: vmware_desktop
# provider: docker

# General VVV options
general:
Expand Down
13 changes: 13 additions & 0 deletions config/homebin/vagrant_up
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,25 @@ if [[ -f /srv/config/homebin/vagrant_up_custom ]]; then
/srv/config/homebin/vagrant_up_custom
fi

# /etc/host doesn't survive restart on docker
vvv_info " * Reinit /etc/hosts"
vvv_update_guest_hosts

vvv_info " * Restarting Nginx"
sudo service nginx restart

vvv_info " * Restarting MariaDB"
sudo service mariadb restart

vvv_info " * Restarting PHP-FPM"
find /etc/init.d/ -name "php*-fpm" -exec bash -c 'sudo service "$(basename "$0")" restart' {} \;

vvv_info " * Restarting Memcache"
sudo service memcached restart

vvv_info " * Restarting Mailhog"
/usr/bin/env /usr/local/bin/mailhog > /dev/null 2>&1 &

if [ -x "$(command -v ntpdate)" ]; then
vvv_info " * Syncing clocks"
if sudo ntpdate -u ntp.ubuntu.com; then
Expand Down
11 changes: 6 additions & 5 deletions provision/core/mailhog/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,22 @@ function mailhog_setup() {

# Start on reboot
if [ "${VVV_DOCKER}" != 1 ]; then
# no systemd
vvv_info " * Enabling MailHog Service"
systemctl enable mailhog
# systemctl enable mailhog

vvv_info " * Starting MailHog Service"
systemctl start mailhog
# systemctl start mailhog
/usr/bin/env /usr/local/bin/mailhog > /dev/null 2>&1 &
vvv_info " * Started MailHog Service"
fi
}
export -f mailhog_setup

vvv_add_hook after_packages mailhog_setup

function mailhog_restart() {
if [ "${VVV_DOCKER}" != 1 ]; then
service mailhog restart
fi
killall mailhog; /usr/bin/env /usr/local/bin/mailhog > /dev/null 2>&1 &
}
export -f mailhog_restart

Expand Down
15 changes: 15 additions & 0 deletions provision/core/mariadb/config/debian.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# THIS FILE IS OBSOLETE. STOP USING IT IF POSSIBLE.
# This file exists only for backwards compatibility for
# tools that run '--defaults-file=/etc/mysql/debian.cnf'
# and have root level access to the local filesystem.
# With those permissions one can run 'mariadb' directly
# anyway thanks to unix socket authentication and hence
# this file is useless. See package README for more info.
[client]
user = root
password = root

[mysqladmin]
user = root
password = root
# THIS FILE WILL BE REMOVED IN A FUTURE DEBIAN RELEASE.
6 changes: 5 additions & 1 deletion provision/core/mariadb/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ function mysql_setup() {
chmod 0644 "/home/vagrant/.my.cnf"
vvv_info " * Copied /srv/provision/core/mariadb/config/root-my.cnf to /home/vagrant/.my.cnf"

# this file should been obsolete, but somehow mariadb init.d script use it
cp -f "/srv/provision/core/mariadb/config/debian.cnf" "/etc/mysql/debian.cnf"
vvv_info " * Copied /srv/provision/core/mariadb/config/debian.cnf to /etc/mysql/debian.cnf"

# Due to systemd dependencies, in docker, mysql service is not auto started
vvv_info " * Ensuring MariaDB service is started"
service mariadb restart
Expand All @@ -125,7 +129,7 @@ function mysql_setup() {
# MySQL gives us an error if we restart a non running service, which
# happens after a `vagrant halt`. Check to see if it's running before
# deciding whether to start or restart.
if [ $(service mariadb status|grep 'mysql start/running' | wc -l) -ne 1 ]; then
if [ $(service mariadb status|grep 'Uptime' | wc -l) -ne 1 ]; then
vvv_info " * Starting the mariadb service"
service mariadb start
else
Expand Down
5 changes: 5 additions & 0 deletions provision/core/php/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ function phpfpm_setup() {
fi
fi
done

if [[ ! -d "/run/php" ]]; then
mkdir -p "/run/php"
chown -R www-data:www-data "/run/php"
fi
}
export -f phpfpm_setup

Expand Down
2 changes: 1 addition & 1 deletion provision/core/vvv/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function cleanup_vvv(){
echo "127.0.0.1 tideways.vvv.test # vvv-auto" >> "/etc/hosts"
echo "127.0.0.1 xhgui.vvv.test # vvv-auto" >> "/etc/hosts"
fi
mv /tmp/hosts /etc/hosts
echo "$(</tmp/hosts)" | sudo tee -a /etc/hosts > /dev/null
}
export -f cleanup_vvv

Expand Down
Loading

0 comments on commit b678676

Please sign in to comment.