Developing with Devbox
Jethro is an open source (GPL) project, with collaboration taking place mainly on issues on Github.
Local development with Devbox
Jethro's system requirements are listed in README.md.
A fast way to get Jethro running from source is with the bundled Devbox, a tool for isolated development environments. Jethro's source distribution comes with a devbox install script and a basic Devbox configuration, requiring just one command to bring up a Nginx web server, MariaDB database and PHP-FPM backend running Jethro.
To get started, run ./devbox services up -b
$ ./devbox services up -b
Starting all services: nginx-access, nginx-error, php-fpm, jethro, jethro_database_setup, mariadb, mariadb_logs, nginx
Process-compose is now running on port 38489
To stop your services, run `devbox services stop`
This will:
- download the full
devboxbinary if you don't already have it (./devboxis a stub 1 ). - download binaries for php, nginx and mariadb. This will take a few minutes the first time.
- install Jethro's PHP dependencies (the
vendor/directory) with Composer. Composer is bundled in the devbox environment (via the php package), so no separate install is needed. This includes the dev-only SMS mock server (jethro/smsmockserver), linked into the tree assmsmockserver/→vendor/jethro/smsmockserver. - launch a MariaDB database and Nginx web server in the background (
-b). - create a
jethrodatabase in the Devbox MariaDB
Point your browser at http://localhost:<port>, where <port> is printed by devbox.d/bin/jethro_utils freeport web
(stable for this checkout's path), and you should see Jethro's setup wizard.
Devbox overview
With Devbox, you can:
-
./devbox shellto enter the Jethro development environment, containing local versions of PHP, Nginx, MariaDB and other dev tools as specified indevbox.json. In this shell,mariadb(ormysql) connects to the devbox'sjethrodatabase (see below), other commands fromdevbox.d/binare added to your$PATH. Ctrl-C to exit the shell. -
./devbox run <script>to run one of the scripts defined indevbox.json. E.g.devbox run lint. -
./devbox services [up|up -b|down|ls]to manage the Nginx, MariaDB and other services Devbox provides, preconfigured to run Jethro from source. For example, if you ran./devbox services up -bearlier to start things,./devbox services lswill show something like:
$ ./devbox services ls
Services running in process-compose:
PID NAME NAMESPACE STATUS AGE HEALTH RESTARTS EXIT CODE
6908 jethro default Completed 0s - 0 0
6699 nginx default Running 1m48s Ready 0 0
6698 nginx-error default Running 1m48s - 0 0
6697 mariadb default Running 1m48s Ready 0 0
6701 mariadb_logs default Running 1m48s - 0 0
6826 jethro_database_setup default Completed 0s - 0 0
6696 nginx-access default Running 1m48s - 0 0
6700 php-fpm default Running 1m48s - 0 0
Devbox services
Devbox services are defined in process-compose.yml, augmented with services that devbox plugins provide. Devbox
services can be configured by editing:
devbox.d/nginx/nginx.templatedevbox.d/php/php-fpm.confdevbox.d/mariadb/my.cnf
You will see references to environment variables in those config files, and often it's possible to customize Devbox
services by setting a relevant environment variable in devbox.json's env rather than tweaking devbox.d/ files.
The init hook runs jethro_utils env, which resolves _default_ in
NGINX_WEB_PORT and FUNCTEST_WEB_PORT to ports derived from the checkout's physical path.
Replace either _default_ entry in devbox.json's env with a literal port to override it;
jethro_utils env prints only the variables it resolves from _default_, so a literal port is
never re-exported or overwritten.
Blank values are rejected. Like other config entries, these take precedence over
inherited shell values.
Read the configured value with ./devbox run -- printenv NGINX_WEB_PORT.
Devbox (at least, our fork of it) exports DEVBOX_RUNTIME_DIR, DEVBOX_LOG_DIR and DEVBOX_DATA_DIR
before expanding env. Project configuration sets MAILPIT_SOCKET_DIR to
$DEVBOX_RUNTIME_DIR/mailpit. The runtime namespace matches the plugin socket paths;
log/data roots are .devbox/logs and .devbox/data. Keep MariaDB and PHP-FPM on their
plugin-specific paths beneath those roots. Custom services must create private runtime
subdirectories before using them. The hook locates utilities through $DEVBOX_CONFIG_DIR.
Run devbox info mariadb / devbox info php / devbox info nginx to see what's available.
You will also see a .devbox directory created. This is where Devbox constructs its virtual environment. If deleted it
will be recreated on next devbox command. Of interest is:
.devbox/logs/process-compose.logfor service logs.devbox/logs/nginx/error.logfor Jethro stdout/stderr.devbox/virtenv/{mariadb,nginx,php}/process-compose.yamlfor definitions of default devbox services, augmenting./process-compose.yml.
How devbox services run Jethro
Devbox's Nginx plugin defaults its web root to devbox.d/web/; devbox.json overrides NGINX_WEB_ROOT to point at devbox.d/demo/ instead (the plugin still recreates an unused, gitignored devbox.d/web/index.html). devbox.d/demo/ contains ../.. symlinks to Jethro PHP files, except for devbox.d/demo/conf.php which configures Jethro to connect to the jethro MariaDB database on 127.0.0.1:3307.
We could actually just rely on Devbox's built-in .devbox/virtenv/*/process-compose.yaml services to bring up Jethro.
The ./process-compose.yml adds usability tweaks, notably a jethro_database_setup "service" which creates the
jethro MariaDB user and database if they do not exist, by invoking devbox.d/bin/mariadb_ensure_db jethro (which you
are free to invoke directly). It never touches existing data. devbox.d/bin/ contains other development scripts, and
that directory is added to your $PATH in a devbox shell:
mariadb_ensure_db DB...— create the database(s) if absent, granting access to thejethrousermariadb_recreate_db DB...— drop and recreate the database(s), empty (destroys data)jethro_load_demodata DB [SYSTEM_NAME]— recreateDBand fill it with the demo/functional-test datamariadb_dump_db DB [AS_NAME]— dump a database to stdout, normalized for reloading elsewheremariadb_as_root— amariadbclient connected as root over the unix socketjethro_compile [--nouse] [VERSION]— compile the CSS/JS bundles andinclude/version.txtin the checkoutjethro_build [--with-dev] [VERSION]—jethro_compile,composer installintovendor/(--no-devunless--with-dev), and (re)create thedist/webroot/symlink webroot: a production-ready checkout anddist/webroot/
Every devbox database is reachable as user jethro, password jethro, and devbox.d/mariadb/my.cnf makes that the
client default — so mariadb jethro_functest -e 'select 1' (no -u/-p) just works, in scripts and tests alike.
Initially http://localhost:<port> (devbox.d/bin/jethro_utils freeport web) will show the Jethro setup wizard, reflecting the empty state of the jethro database. If you'd like to load sample data, run devbox run demodata. To wipe the jethro database again, run devbox run initdb.