-
Notifications
You must be signed in to change notification settings - Fork 848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Monolithic Docker provider #2632
Changes from all commits
22ad4b4
c9ec449
62c5796
ace8de7
92758fd
0b6b2ac
188bcaf
a646c93
ce156b6
a40ab54
e78b6f9
d80d105
79a57ea
48ab479
23464a6
7fd737e
76a008b
b8a0c44
fdade8b
d6ed345
a8101df
636a530
da3b697
de8c959
58a2c88
729da51
08c4db5
1cda256
ff1b71b
d103405
4acaa62
f0ae39a
39d794f
47057c8
8252690
bb58041
42efd1c
fabccb8
d442355
1da5dd1
00d7499
ef6106b
4a5d545
a488c4b
1a5394a
af1209f
42f99f1
3ee80e4
a11e359
c0f4a6c
22fd603
4c7e6bf
206e661
69a65af
60c5532
459e5e2
c67bb0c
1f0c981
c005314
bd53f8f
6d14048
906b15e
abea1f5
07f1111
cd3d1e3
e634188
798b6b6
9f5f064
b8f3745
1000b3e
f4696ea
2dfd0e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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. | ||
|
@@ -229,6 +230,26 @@ vvv_config['hosts'] = vvv_config['hosts'].uniq | |
|
||
vvv_config['vagrant-plugins'] = {} unless vvv_config['vagrant-plugins'] | ||
|
||
# Early mapping of the hosts to be added. | ||
vvv_config['utilities'].each do |name, extensions| | ||
extensions = {} unless extensions.is_a? Array | ||
extensions.each do |extension| | ||
if extension == 'tideways' | ||
vvv_config['hosts'] += ['tideways.vvv.test'] | ||
vvv_config['hosts'] += ['xhgui.vvv.test'] | ||
end | ||
end | ||
end | ||
vvv_config['extensions'].each do |name, extensions| | ||
extensions = {} unless extensions.is_a? Array | ||
extensions.each do |extension| | ||
if extension == 'tideways' | ||
vvv_config['hosts'] += ['tideways.vvv.test'] | ||
vvv_config['hosts'] += ['xhgui.vvv.test'] | ||
end | ||
end | ||
end | ||
|
||
# Create a global variable to use in functions and classes | ||
$vvv_config = vvv_config | ||
|
||
|
@@ -307,6 +328,8 @@ if show_logo | |
provider_version = '??' | ||
when 'hyperv' | ||
provider_version = 'n/a' | ||
when 'docker' | ||
provider_version = VagrantPlugins::DockerProvider::Driver.new.execute("docker", "-v").gsub("Docker version ", "") | ||
else | ||
provider_version = '??' | ||
end | ||
|
@@ -439,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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can avoid this by using a dockerfile and layering over a general ubuntu 20 container There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That'd be preferrable for me as well |
||
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'] } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. noting that if we used docker compose then traefik can be used and goodhosts becomes optional There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. traefik will not handle domains unless we have some true real life domain available, like vvv.dev or something on those lines. This is all explained here. Traefik would be useful if we wanted to have multi-container nginx, or node apps supports or something, so that you can access different things based on, for example, paths: Example In this example, and since all sites are accesed on port 80, and just different apps, traefik will forward traffic to each container, and in the case of nginx containers, they'll use the configured php upstream containers as needed. Since i don't think we need node apps forwarding for the time being, and also, we're not thinking of supporting multiple versions of nginx in the foreseable future. We don't need traefik, and we can just expose nginx port 80. vvv.test will never load in traefik (or nginx) unless your machine can resolve vvv.test to 127.0.0.1. there's only a few ways this can happen:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That is something I'd like in the future, particularly for MariaDB/ES/Mailhog. I can see an argument for there being an Nginx container too, and in the long run it also allows us to be more flexible with PHP versions and php logging on a per site basis There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also note that Altis Local Server manages this somehow with Traefik There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can look into the code, but it's likely with one of the 3 options above. Is the project open source for the altis solution? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I can see, they are not generating entries, at least not directly in the project. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even more so, they state this on the docs
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's ok, I'm not seeing any crazy hacks to map it though, they're just saying go to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the grand scheme of things though, I don't think this is the highest priority, I'd prioritise extracting improvements that aren't strictly docker related that could be merged in advance, and having a docker file to remove the need for the pentatonic docker image so we can layer things in the future There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, so goodhosts stays for the foreseable future as it solves this problem about the more prioritary things, totally onboard with doing those that can be merged in advance |
||
end | ||
|
||
# Virtualbox. | ||
config.vm.provider :virtualbox do |_v, override| | ||
# Default Ubuntu Box | ||
|
@@ -492,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. | ||
# | ||
|
@@ -794,10 +830,6 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
vvv_config['utilities'].each do |name, extensions| | ||
extensions = {} unless extensions.is_a? Array | ||
extensions.each do |extension| | ||
if extension == 'tideways' | ||
vvv_config['hosts'] += ['tideways.vvv.test'] | ||
vvv_config['hosts'] += ['xhgui.vvv.test'] | ||
end | ||
tomjn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
config.vm.provision "extension-#{name}-#{extension}", | ||
type: 'shell', | ||
keep_color: true, | ||
|
@@ -812,10 +844,6 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
vvv_config['extensions'].each do |name, extensions| | ||
extensions = {} unless extensions.is_a? Array | ||
extensions.each do |extension| | ||
if extension == 'tideways' | ||
vvv_config['hosts'] += ['tideways.vvv.test'] | ||
vvv_config['hosts'] += ['xhgui.vvv.test'] | ||
end | ||
config.vm.provision "extension-#{name}-#{extension}", | ||
type: 'shell', | ||
keep_color: true, | ||
|
@@ -870,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' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
Comment on lines
+30
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. noting this would be better in a dockerfile |
||
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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,5 +58,7 @@ function git_after_packages() { | |
vvv_info " * Git hasn't been told how to merge branches, setting pull.rebase false for the merge strategy" | ||
noroot git config --global pull.rebase false | ||
fi | ||
git config --global --add safe.directory '*' # Allow git to work well under docker provider | ||
noroot git config --global --add safe.directory '*' # Allow git to work well under docker provider | ||
Comment on lines
+61
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these might be needed regardless of wether we use docker or not, could these be a separate PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be extracted into a separate PR |
||
} | ||
vvv_add_hook after_packages git_after_packages |
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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could be extracted into a separate PR |
||
vvv_info " * Starting the mariadb service" | ||
service mariadb start | ||
else | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
Comment on lines
+112
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could be extracted into a separate PR |
||
} | ||
export -f phpfpm_setup | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could be extracted into a separate PR |
||
} | ||
export -f cleanup_vvv | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks like a nice self contained change