Skip to content
Merged
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
16 changes: 15 additions & 1 deletion .lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ services:
database:
type: mariadb:10.5.23
portforward: 32778
creds:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create database with credentials matching those now provided in .env.example

user: pressbooks_oss_user
password: secretpassword
database: pressbooks_oss
redis:
type: redis:5.0
portforward: 6380
Expand All @@ -32,6 +36,8 @@ services:
- scripts/pressbooks_required_libraries.sh
build:
- composer install
run_as_root:
- bash /app/scripts/prepare_test_environment.sh
mailhog:
hogfrom:
- appserver
Expand All @@ -51,7 +57,7 @@ tooling:
install-tests:
description: Install test requirements
cmd:
- appserver: scripts/prepare_tests_environment.sh
- appserver: scripts/prepare_test_environment.sh
test:
description: Run all Unit Tests
cmd:
Expand All @@ -68,3 +74,11 @@ tooling:
description: Run tests by filter
cmd:
- appserver: composer run filter_test
db-import-custom:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add new command for performing custom database import. Can remove after lando/core#384 is released

description: Import a SQL dump into the database defined in .env
cmd:
- appserver: scripts/import_db.sh
user: root
events:
post-start:
- database: bash /app/scripts/import_db.sh /app/pb_local_db.sql
21 changes: 8 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,22 @@ This repository uses Lando/Docker to provision a local instance of Pressbooks fo
```bash
lando start
```
During the build process, you may be asked for an installation folder for Prince:
This will create all the services needed to install a local instance of Pressbooks and import a sample database. During the build process, you may be asked for an installation folder for Prince:
```bash
Install directory
This is the directory in which Prince 20220930 will be installed.
Press Enter to accept the default directory or enter an alternative.
[/usr]:
```
Press `Enter` to accept the default directory.
8. Import the prepared sample database included in this repo:
```bash
lando db-import pb_local_db.sql
```
9. Install Pressbooks testing utilities
```bash
lando install-tests
```
10. [Optional] Tell your host machine to trust the default Lando Certificate Authority by following these instructions: https://docs.lando.dev/core/v3/security.html#trusting-the-ca
8. [Optional] Tell your host machine to trust the default Lando Certificate Authority by following these instructions: https://docs.lando.dev/core/v3/security.html#trusting-the-ca

### Web access
Once you have completed these steps, you should be able to use Pressbooks locally by visiting `http://pressbooks.test` or `https://pressbooks.test`.

### Running tests
Everything needed to run unit tests will be provided when you run `lando start`. You can re-install the Pressbooks test suite by running `lando install-tests`.

You can run tests inside your Lando instance with the following commands:
`lando test` (this is a shortcut which runs the core Pressbooks unit tests inside your container)

Expand All @@ -79,13 +73,14 @@ You can set up access to your database in your IDE by creating a new MariaDB con
2. In PHPStorm, open the `Database` menu (on the right side of the IDE), click the `+` button and add a new `MariaDB` connection.
3. Enter the following connection data:
- The `host` and `port` values obtained by running `lando info` earlier
- user: wordpress
- password: wordpress
- database: wordpress
- user: pressbooks_oss_user
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update values to match new defaults

- password: secretpassword
- database: pressbooks_oss

### Notes
- The sample database includes a single empty public book and a single super admin user with a username / password of `admin / admin`.
- The `.env.example` file provides some additional environment variables which can be used with your local Pressbooks installation but are commented out by default. If you wish to install the optional PB MathJax service, you can do so following the instructions here: https://github.com/pressbooks/pb-mathjax?tab=readme-ov-file#installation. Once you've launched the service, you can uncomment the relevant line in your local `.env` file. Similar sample `.env` variables are provided for optional DocRaptor, Sentry, Redis, and Algolia integrations.
- You can force a reimport of the sample DB by running `lando db-import-custom pb_local_db.sql --force`
- `lando info` provides a list of all the services and their ports.
- You can install or update dependencies in the container or any repo by navigating to the desired location and running `lando composer install` or `lando composer update`.
- For SSH access to the appserver you can run: `lando ssh` or `lando ssh -u root` (if you wish to access the appserver as the root user)
Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
}
],
"require": {
"php": ">=8.1",
"php": ">=8.2",
"composer/installers": "^2.2",
"owlsdepartment/multisite-url-fixer": "dev-main",
"pressbooks/pressbooks": "dev-dev",
Expand All @@ -55,9 +55,8 @@
"pressbooks/pressbooks-saml-sso": "dev-dev",
"roots/bedrock-autoloader": "^1.0",
"roots/bedrock-disallow-indexing": "^2.0",
"roots/wordpress": "^6.4",
"roots/wordpress": "^6.8",
"roots/wp-config": "1.0.0",
"roots/wp-password-bcrypt": "1.1.0",
"vlucas/phpdotenv": "^5.6"
},
"require-dev": {
Expand Down
63 changes: 63 additions & 0 deletions scripts/import_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash
# Safe automatic DB import for Lando with optional force import
# Usage:
# ./import_db.sh /app/pb_local_db.sql # safe import, skips if DB exists
# ./import_db.sh --force /app/pb_local_db.sql # force re-import

FORCE=false
SQL_FILE=""

# Parse arguments
for arg in "$@"; do
case $arg in
--force|-f)
FORCE=true
shift
;;
*)
SQL_FILE="$arg"
shift
;;
esac
done

if [ -z "$SQL_FILE" ]; then
echo "Usage: $0 [--force|-f] <file.sql>"
exit 1
fi

# Create .env from .env.example if .env doesn't exist
if [ ! -f /app/.env ]; then
cp /app/.env.example /app/.env
echo "Created .env from .env.example"
fi

# Load environment variables from .env
set -a
source /app/.env
set +a

if [ "$FORCE" = false ]; then
# Check if WordPress tables exist or if database is empty
WP_TABLES=$(mysql -h "$DB_HOST" -P 3306 -u "$DB_USER" -p"$DB_PASSWORD" "$DB_NAME" -e "SHOW TABLES LIKE 'wp_%';" 2>/dev/null | wc -l)

if [ "$WP_TABLES" -gt 0 ]; then
echo "Database '$DB_NAME' contains WordPress tables. Skipping import."
exit 0
fi
fi

echo "Database '$DB_NAME' will be created/imported..."

# Drop and recreate DB if force is true
if [ "$FORCE" = true ]; then
mysql -h "$DB_HOST" -P 3306 -u "$DB_USER" -p"$DB_PASSWORD" -e "DROP DATABASE IF EXISTS $DB_NAME;"
fi

# Ensure database exists
mysql -h "$DB_HOST" -P 3306 -u "$DB_USER" -p"$DB_PASSWORD" -e "CREATE DATABASE IF NOT EXISTS $DB_NAME;"

# Import SQL
mysql -h "$DB_HOST" -P 3306 -u "$DB_USER" -p"$DB_PASSWORD" "$DB_NAME" < "$SQL_FILE"

echo "Import complete!"
2 changes: 1 addition & 1 deletion scripts/pressbooks_required_libraries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ else
fi

# Install latest version of Node
curl -sL "https://deb.nodesource.com/setup_18.x" | bash - \
curl -sL "https://deb.nodesource.com/setup_22.x" | bash - \
&& apt-get install -y nodejs

# install missing xsl extension
Expand Down