Skip to content

Instantly share code, notes, and snippets.

@yorkshire-pudding
Created March 25, 2023 17:30
Show Gist options
  • Save yorkshire-pudding/0da8ef666cf0e14a0d2eee4749ed55fc to your computer and use it in GitHub Desktop.
Save yorkshire-pudding/0da8ef666cf0e14a0d2eee4749ed55fc to your computer and use it in GitHub Desktop.
backdropNewSiteLando
name: ???
# Use existing Backdrop recipe, then customise below.
recipe: backdrop
config:
# Where Backdrop resides, relative to this file.
webroot: docroot
database: mariadb:10.2
php: '?.?'
backdrush: 1.x-1.x
proxy:
mailhog:
- mail.???.lndo.site
phpmyadmin:
- db.???.lndo.site
services:
appserver:
extras:
- apt-get update -y
- apt-get install sudo nano jq -y
- wget -qO bee.zip https://github.com/backdrop-contrib/bee/archive/1.x-1.x.zip
- unzip -q bee.zip && rm bee.zip
- mv bee-1.x-1.x /usr/local/bin/bee
phpmyadmin:
type: phpmyadmin
hosts: database
mailhog:
type: mailhog
hosts: mailhog
hogfrom:
- appserver
tooling:
bee:
service: appserver
cmd: /usr/local/bin/bee/bee.php --root=/app/docroot
phpcs:
service: appserver
cmd:
- "/app/docroot/vendor/bin/phpcs -n --report=full --standard=Backdrop --ignore=vendor/*,README.md --extensions=install,module,php,inc,theme"
# Allow Drush to be run from any directory.
drush:
service: appserver
cmd: drush --root=/app/docroot --uri=http://???.lndo.site
# Create a snapshot of the site.
snapshot:
service: appserver
description: Create a snapshot of the site
cmd:
- mysqldump --add-drop-database -Bu root -h database -P 3306 backdrop > /app/backdrop.sql
- gzip -f /app/backdrop.sql
- cd /app/docroot/files/config_* && tar -czf /app/config.tar.gz active
- echo 'Snapshot created successfully'
# Revert the site using the snapshot.
revert:
service: appserver
description: Reset the site using the snapshot
cmd:
- cd /app/docroot/files/config_* && rm -r active && tar -xzf /app/config.tar.gz
- gunzip /app/backdrop.sql.gz
- mysql -u root -h database -P 3306 backdrop < /app/backdrop.sql
- gzip -f /app/backdrop.sql
- echo 'Site reverted successfully'
# Reset the site (drop db and remove config files).
reset:
service: appserver
description: Reset the site (drop db and remove config files)
cmd:
- drush sql-drop -y
- cd /app/docroot/files/config_* && rm -r active
- drush si standard --db-url=mysql://root:backdrop@localhost/backdrop --site-name=???
# Currently, specifying the admin account password is not possible.
# See: https://github.com/backdrop-contrib/drush/issues/151
- drush upwd admin --password="password"
# INstall and enable devel and devel_generate.
- drush dl devel
- drush en devel devel_generate
# Enable all errors, and disable CSS and JS aggregation.
- cd active
- jq --indent 4 '.error_level = "all" | .preprocess_css = 0 | .preprocess_js = 0' system.core.json > tmp.$$.json
- mv tmp.$$.json system.core.json
#!/bin/bash
## Get details
# Ask for project name
read -e -p "What should the app or project name be?: " RAW_PROJECT_NAME
# If left empty, then exit
if [[ -z "${RAW_PROJECT_NAME}" ]]; then
echo "You must enter a project name. The script will now exit."
exit 1
fi
# Change any uppercase to lowercase and change spaces or other characters to hyphen (Lando does not like uppercase in app name)
typeset -l PROJECT_NAME
PROJECT_NAME=${RAW_PROJECT_NAME//[^a-z,0-9]/-}
if [[ "${PROJECT_NAME}" != "${RAW_PROJECT_NAME}" ]]; then
echo "Project name has been set to ${PROJECT_NAME}. It must be lowercase with no spaces or special characters"
fi
# check for PHP version but provide default
PHP_DEFAULT="7.4"
PHP_VERSIONS=("7.1" "7.2" "7.3" "7.4" "8.0" "8.1")
echo "Please select a PHP version by choosing an option from 1 to ${#PHP_VERSIONS[@]}"
PS3="Enter option (1-${#PHP_VERSIONS[@]}): "
select PHP_SELECT in "${PHP_VERSIONS[@]}"; do
if [[ -z "${PHP_SELECT}" ]]; then
PHP_SELECT=${PHP_DEFAULT}
fi
break
done
echo "PHP version set to ${PHP_SELECT}"
## Get the files
# Create folder and go there
echo "Creating folder ${PROJECT_NAME} in ~/projects/backdrop"
mkdir ~/projects/backdrop/$PROJECT_NAME && cd ~/projects/backdrop/$PROJECT_NAME
# Download latest released version; add quiet flag but then reinstate progress display
echo "Download latest version of Backdrop"
wget https://github.com/backdrop/backdrop/releases/latest/download/backdrop.zip -q --show-progress
echo "Unpack it to the docroot..."
# Unzip the file
unzip -q backdrop.zip
# Move files to docroot folder
mkdir docroot && mv backdrop/* backdrop/.[!.]* ./docroot/
# Delete backdrop zip file and folder
rm -r backdrop.zip backdrop
## Create Lando
# Copy the lando template to the project folder
cp ../_TEMPLATES/.lando.yml ./.lando.yml
# Populate template placeholders with project parameters
# Project name
sed -i -e "s/???/${PROJECT_NAME}/g" .lando.yml
# PHP version
sed -i -e "s/'?.?'/'${PHP_SELECT}'/g" .lando.yml
# Start the lando app
lando start
## Install backdrop
# Ensure core install script is executable
echo "Ensuring install script that bee uses is executable"
chmod +x docroot/core/scripts/install.sh
# move to the docroot folder
cd docroot
# install Backdrop using bee
lando bee si --profile=standard --db-name=backdrop --db-user=root --db-pass=backdrop --username=admin --password=password --site-name=${PROJECT_NAME} --auto
# add to git server
# TODO
# Remove execute permission from core install script
echo "Remove execute permission from core install script as its no longer needed"
chmod -x ./core/scripts/install.sh
# End with short message
echo "Your Backdrop project (${PROJECT_NAME}) is now a Lando app"
cd ../
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment