Skip to content

Commit

Permalink
Overhaul Vagrantfile and bootstrap.sh provisioner.
Browse files Browse the repository at this point in the history
  • Loading branch information
beporter committed Oct 24, 2021
1 parent 1d35fc3 commit 50798ac
Show file tree
Hide file tree
Showing 9 changed files with 334 additions and 297 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ tiles/
tiles/**/*
google*.html
*.sql
.vagrant/bootstrap.sh
.vagrant/machines/
cgi-bin/db_start.php
.vagrant/
.well-known/brave-payment-verification.txt
9A4F12FD1854F031824A5EE0E710E4F0.txt

Expand Down Expand Up @@ -231,4 +231,4 @@ pip-log.txt
#Mr Developer
.mr.developer.cfg

*.code-workspace
*.code-workspace
56 changes: 0 additions & 56 deletions .vagrant/bootstrap.sh.example

This file was deleted.

34 changes: 28 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
Dave's Mapper
=============
# Dave's Mapper


This is the code behind [Dave's Mapper](https://davesmapper.com). It's based on the Morph Mapper by Rob Lang, but vastly larger in scope and ambition.

License
-------

## Development

This project includes a Vagrantfile to bundle all necessary dependencies. Locally you will need:

* git v2.0+
* [Vagrant](https://www.vagrantup.com/downloads)
* [Virtualbox](https://www.virtualbox.org/wiki/Downloads)

The included `provision/boostrap.sh` script defines all other system-level dependencies including PHP, Apache and MySQL.

### Setup

1. Clone the repo.
2. Run `vagrant up` to download, provision and launch the development box.
* This will take some time during the first execution as the base VM image needs to be downloaded from the internet.
3. This local folder is mapped into the VM's `/app` folder. Changes to files in the project will be updated inside the VM nearly instantaneously.
4. Visit http://localhost:4069
5. When you are done, run `vagrant down` to halt the configured VM. (Subsequent `vagrant up` commands will boot this already-provisioned VM.)

Database credentials will be automatically configured in `cgi-bin/db_start.php` to work with Vagrant. This file is gitignore'd to prevent it from being committed back to the repo with sensitive credentials.

## License


Dave's Mapper
Copyright © 2010-2018 David Millar
Expand All @@ -22,7 +44,7 @@ License
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.

Contact
-------
## Contact


I can be reached at [email protected] or [email protected]
75 changes: 66 additions & 9 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,70 @@
project_name = "mapper"

Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/bionic64"
config.vm.box_version = "1.0.282"
config.vm.synced_folder ".", "/vagrant"
config.vm.provision :shell, path: ".vagrant/bootstrap.sh"
config.vm.network :forwarded_port, host: 4069, guest: 80
config.vm.provider "virtualbox" do |v|
conf = {
PROJECT_NAME: 'daves-mapper',
PROJECT_ROOT: '/var/www/daves-mapper',
PROJECT_PORT: 4069,
}

Vagrant.require_version '>= 2.0.0'

Vagrant.configure('2') do |config|
config.vm.box = 'bento/ubuntu-20.04'

config.vm.network :forwarded_port,
host: conf[:PROJECT_PORT],
guest: 80
config.vm.network :forwarded_port,
host: 3307,
guest: 3306,
auto_correct: true

config.vm.synced_folder '.', conf[:PROJECT_ROOT]

config.vm.provider 'virtualbox' do |v|
v.name = "Dave's Mapper Vagrant"
v.gui = false
end

config.vm.provision :shell,
name: 'bootstrap',
path: 'provision/bootstrap.sh',
args: [
conf[:PROJECT_ROOT],
"#{conf[:PROJECT_NAME]}.test",
'vagrant'
]

config.vm.provision :shell,
name: 'vagrant specific',
privileged: false,
inline: <<~VAGRANTONLYSCRIPT
cd #{conf[:PROJECT_ROOT]}
echo '## Creating a limited vagrant-only DB user.'
cat <<SQL | mysql
CREATE USER IF NOT EXISTS 'vagrant'@'%' IDENTIFIED BY 'vagrant';
GRANT ALL ON daves_mapper.* TO 'vagrant'@'%';
FLUSH PRIVILEGES;
SQL
if [ ! -f cgi-bin/db_start.php ]; then
echo '## Copying db_start.php into place.'
cp cgi-bin/db_start.php.example cgi-bin/db_start.php
fi
TABLE_COUNT=$(mysql --batch --skip-column-names -e 'SELECT count(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = "daves_mapper";')
if [ $TABLE_COUNT -gt 0 ]; then
echo '## Importing MySQL schema.'
mysql daves_mapper < provision/schema.sql #TODO this sql file needs to get populated.
fi
echo '## Setting convenience login dir.'
if grep -vq 'cd #{conf[:PROJECT_ROOT]}' ~/.profile; then
echo 'cd #{conf[:PROJECT_ROOT]}' >> ~/.profile
fi
VAGRANTONLYSCRIPT

# TODO: Define a safety trigger to export MySQL data before destroying the VM.

config.vm.post_up_message = "VM is up! Visit http://localhost:#{conf[:PROJECT_PORT]}"
end
Loading

0 comments on commit 50798ac

Please sign in to comment.