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

Conversation

beporter
Copy link

@beporter beporter commented Oct 24, 2021

Resolves #41 by overhauling the Vagrant environment.

There are a few TODO tags in the changed code that have been previously discussed (SQL schema for example.)

The main goal here is to provide a more reliable, easier development platform from which people are able to contribute.

Testing

  • Check out this branch locally. (Maybe clone to a whole separate folder to ensure you're starting fresh.)
  • Make sure you have Virtualbox and Vagrant installed and up to date locally.
  • Run vagrant up.
  • Once the script is complete you should be able to visit http://localhost:4069, however the site can't be expected to load entirely properly due to missing DB schema & test data.
  • I added a test info.php file to the project root locally (did not commit) and put <?php phpinfo(); in it to test http://localhost:4069/info.php
  • You can test the idempotency by running vagrant reload --provision to reboot the VM and re-run all provisioning of top of what's already been done in the VM.
  • To start over completely, run vagrant destroy -f

Details

  • Updates the README with some basic "getting started" style data. This can surely be further improved, but it's a start and is intended to provide a high-level orientation for folks who want to work on the project.
  • Moves the bootstrap script out of .vagrant/ (to provision/) because most people will expect to have that entire folder in their global .gitignore.
  • Tweaks the top level .gitignore file a bit to conform with general Vagrant expectations and to prevent sensitive DB credentials from accidentally being committed back to the repo.
  • Deletes the redundant cgi-bin/.gitignore (the root level gitignore covers sub-directories.)
  • Removes the close ?> tags from db_start.php and db_end.php as this is a PHP best practice.
  • Makes cgi-bin/db_start.php.example the actual file copied into place for vagrant. This makes it a more practical example file.
  • Adds a stubbed provision/schema.sql to auto-load a starter schema into the DB in development (nobody else can really work on this project without the DB structure.)
    • ⚠️ This file still needs to be populated.
  • Enhances the Vagrantfile with:
    • Updates the base box to Ubuntu 20.04. bento/ubuntu was chosen because it provides boxes across all major Vagrant providers, so users with VMware benefit from the increased emulation speed compared to Virtualbox.
    • Moves the mapped project folder and Apache vhost inside the VM to /var/www/daves-mapper. This is where the folder will end up in production (typically) so it makes sense to make the dev environment match that as closely as possible.
    • The addition of an auto-correcting port exposing the MySQL database for more direct access in development.
    • A brief configuration hash.
    • A secondary "inline" provisioner that makes vagrant-specific tweaks to the VM. (This allows the bootstrap.sh file to more easily be multi-purpose for vagrant and production.)
  • Overhauls the bootstrap.sh provisioning script:
    • The script is written to be useful for both vagrant and to prepare a new production server (likely a VPS or cloud server instance).
    • The script is also designed to be relatively safe to re-run. In most cases, this will perform "upgrades" on all of the touched components. (The next level of complexity up from this single file would be to introduce Chef or Puppet or Ansible or another package intended for configuration management.)
    • Uses PHP 7.4 as the base. ⚠️ The app still needs to be tested against this version of PHP, but without a DB schema I am currently unable to do that locally.
    • The PHP version and extension list have also been extracted out into variables for easier maintenance of the script and PHP version upgrades in the future.
    • Switches from Apache's php module to php-fpm. This is more likely to be used in production runtimes and provides greater flexibility and scaling. There's some configuration overhead, but being able to experiment with that in development/vagrant eases that burden somewhat.
    • Configures specific error logging in /var/log/php_error.log and /var/log/apache2/daves-mapper/error.log for better debugging visibility.
    • Installs composer in the VM as a PHP best practice even though this is not yet in use in this project.
    • Sets up a ~/.my.cnf file inside the VM (or on the production server) to greatly easy mysql command line use and avoid the use of passwords in typed command lines. This password is already stored in plaintext on the server in db_start.php so there is no significant increase in security risk by doing this, but there is a significant convenience factor.
  • Finally, I cleaned up all of the PATH declarations to be consistent from the project root, and not to throw warnings when PATH is already declared in a calling file.

beporter added a commit to beporter/DavesMapper that referenced this pull request Oct 25, 2021
Builds on davmillar#91 to add the existing asset pipeline tooling to (only) the vagrant box.

This work conflicts with davmillar#90 somewhat. In general, davmillar#90 is preferable as it moves things forward and this PR merely meets the project where it's at. If anything, I'd recommend merging this one first, then adapting davmillar#90 to:

1. Not use yarn. It's unnecessary.
2. Replace yarn.lock with package-lock.json.
3. Remove the unnecessary yui-compressor from the Vagrantfile provisioning block.
@davmillar
Copy link
Owner

I've added the schema to the schema file and scrubbed/partial dumps for test data to the pull request.

I am running into a 500 error on the main index page after bringing up the new vagrant box, but neither the new log locations nor the previous expected locations are showing me anything. Most of the changes look good, though, and I appreciate the work you've put in so far. :)

@beporter
Copy link
Author

Confirmed I'm still seeing a 500 as well-- same as before the schema load.

The relevant log files are:

  • /var/log/apache2/daves-mapper.test/error.log
  • /var/log/php_error.log (not properly created!)

The error is:

[Sat Oct 30 14:22:57.461569 2021] [proxy_fcgi:error] [pid 14259:tid 140260705019648] [client 10.0.2.2:59134] AH01071: Got error 'PHP message: PHP Fatal error:  Uncaught Error: Call to a member function rowCount() on bool in /var/www/daves-mapper/includes/magic.php:14
Stack trace:
#0 /var/www/daves-mapper/index.php(27): include()
#1 {main}
  thrown in /var/www/daves-mapper/includes/magic.php on line 14', referer: http://localhost:4069/sw.js

This is due to the SQL query string declaring an expected database name in addition to table name:

-      $navdata = $pdo->query("SELECT url_slug, name FROM dmillar_cartography.artists ORDER BY name ASC");
+      $navdata = $pdo->query("SELECT url_slug, name FROM artists ORDER BY name ASC");

I've made this tweak, and I'm also updating the logging configs.

@beporter
Copy link
Author

I've got the homepage loading now, although many of the sample tiles imported into the DB are missing their actual JPG asset files so there are a lot of broken images in the window and 404's in the browser's dev tools

missing-jpgs-for-tiles

.

@beporter
Copy link
Author

beporter commented Oct 30, 2021

@davmillar If I might humbly request: I want to be really transparent about this work having been done in the tradition of Hacktoberfest and while we've both worked on this as time presented itself over a few weeks, I'm a little anxious now that it's October 30th. 😅

I definitely don't expect the PR to get merged immediately if there are still things to tweak or testing to be done, but I'd be quite grateful if you'd be willing to add the hacktoberfest-accepted label to this PR (and to #92) before October 31st so that I might get credit. 🙇‍♂️

beporter added a commit to beporter/DavesMapper that referenced this pull request Oct 30, 2021
Builds on davmillar#91 to add the existing asset pipeline tooling to (only) the vagrant box.

This work conflicts with davmillar#90 somewhat. In general, davmillar#90 is preferable as it moves things forward and this PR merely meets the project where it's at. If anything, I'd recommend merging this one first, then adapting davmillar#90 to:

1. Not use yarn. It's unnecessary.
2. Replace yarn.lock with package-lock.json.
3. Remove the unnecessary yui-compressor from the Vagrantfile provisioning block.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve vagrantfile and provision script.
2 participants