Skip to content
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

Overhaul Vagrantfile and bootstrap.sh provisioner. #91

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.sublime*
*.ftpquota
scripts/datacache/
datacache/
blog/
bucket/
error_log
Expand All @@ -10,8 +11,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 +232,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 halt` 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]
79 changes: 70 additions & 9 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,74 @@
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 -eq 0 ]; then
echo '## Importing MySQL schema.'
mysql daves_mapper < provision/schema.sql
echo '## Importing scrubbed artist data.'
mysql daves_mapper < provision/artists.sql
echo '## Importing randomized dump containing 100 tiles.'
mysql daves_mapper < provision/tiles.sql
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
8 changes: 5 additions & 3 deletions admin/index.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php
define('PATH', dirname(__FILE__));
if(!defined('PATH')) {
define('PATH', dirname(dirname(__FILE__)));
}

include PATH . "/../cgi-bin/db_start.php";
include PATH . "/cgi-bin/db_start.php";
session_start();

$artist_icon_query = $pdo->query("SELECT icon FROM artists ORDER BY icon ASC");
Expand Down Expand Up @@ -435,4 +437,4 @@ function bounceOut(){ header("Location: /admin/"); exit; }
</script>
</body>
</html>
<?php include PATH . "/../cgi-bin/db_end.php"; ?>
<?php include PATH . "/cgi-bin/db_end.php"; ?>
Loading