docker-example-drupal/run

151 lines
2.8 KiB
Plaintext
Raw Normal View History

2023-10-08 08:45:51 +00:00
#!/usr/bin/env bash
# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs.
2023-11-22 23:01:26 +00:00
set -o errexit
set -o pipefail
2023-10-08 08:45:51 +00:00
2023-12-16 09:03:02 +00:00
# If we're running in CI we need to disable TTY allocation for docker compose
# commands that enable it by default, such as exec and run.
TTY="${TTY:-}"
if [[ ! -t 1 ]]; then
TTY="-T"
fi
2023-10-08 08:45:51 +00:00
# Run automated tests as part of the Continuous Integration (CI) pipeline.
function ci:test {
lint:dockerfile
docker compose version
2024-07-17 19:17:36 +00:00
docker network create traefik_proxy || true
2023-10-08 08:45:51 +00:00
2024-07-17 19:17:36 +00:00
cp --no-clobber .env.example .env || true
2023-10-08 08:45:51 +00:00
docker compose build --progress plain
docker compose up --detach
docker compose logs
composer install --quiet --no-progress
test --testdox
quality
}
# Run a command within the php container.
function cmd {
docker compose exec php "${@}"
}
2024-07-20 12:57:25 +00:00
# Run coding standards checks.
2023-10-08 08:45:51 +00:00
function coding-standards {
cmd phpcs "${@}"
}
2024-07-20 12:57:25 +00:00
# Execute any Composer command.
2023-10-08 08:45:51 +00:00
function composer {
_exec php composer "${@}"
}
2024-07-20 12:57:25 +00:00
# Connect to the database.
function db {
[[ -f ".env" ]] && source .env
docker compose exec database mysql -u"$DB_USER" -p"$DB_PASSWORD" "$DB_NAME"
}
# Execute any Drush command.
2023-10-08 08:45:51 +00:00
function drush {
_exec php drush "${@}"
}
2024-07-20 12:57:25 +00:00
# Disable Git hooks.
2023-10-08 08:45:51 +00:00
function git-hooks:off {
git config --unset core.hooksPath
}
2024-07-20 12:57:25 +00:00
# Enable Git hooks.
2023-10-08 08:45:51 +00:00
function git-hooks:on {
git config core.hooksPath .githooks
}
# Display a list of all available commands.
function help {
printf "%s <task> [args]\n\nTasks:\n" "${0}"
compgen -A function | grep -v "^_" | cat -n
printf "\nExtended help:\n Each task has comments for general usage\n"
}
2023-12-16 17:09:04 +00:00
# Install Drupal.
function install {
drush site:install -y "${@}"
}
2024-07-20 12:57:25 +00:00
# Lint the Dockerfile.
2023-10-08 08:45:51 +00:00
function lint:dockerfile {
docker container run --rm -i \
2024-07-17 19:17:36 +00:00
hadolint/hadolint hadolint --ignore DL3008 --ignore DL3022 --ignore DL3059 -t style "${@}" - < Dockerfile
2023-10-08 08:45:51 +00:00
}
2024-07-20 12:57:25 +00:00
# Run code quality checks.
2023-10-08 08:45:51 +00:00
function quality {
coding-standards
static-analysis
}
2024-07-20 12:57:25 +00:00
# Start the project.
2023-10-08 08:45:51 +00:00
function start {
2024-01-21 21:58:53 +00:00
cp -v --no-clobber .env.example .env || true
2023-10-08 08:45:51 +00:00
docker compose up -d
}
function static-analysis {
cmd phpstan --memory-limit=-1 --no-progress "${@}"
}
function stop {
docker compose down
}
function test {
_exec php phpunit --colors=always "${@}"
}
function test:commit {
test --testdox --testsuite functional
test --testdox --testsuite kernel
test --testdox --testsuite unit
quality
}
function _exec {
2023-12-16 09:03:02 +00:00
docker compose exec ${TTY} "${@}"
2023-10-08 08:45:51 +00:00
}
function _run {
local service="${1}"
local command="${2}"
docker compose run \
--entrypoint "${command}" \
--no-deps \
--rm \
2023-12-16 09:03:02 +00:00
${TTY} \
2023-10-08 08:45:51 +00:00
"${service}" "${@}"
}
2023-11-14 13:04:07 +00:00
# Include any local tasks.
2024-07-31 00:21:57 +00:00
# https://stackoverflow.com/a/6659698
[[ -e "${BASH_SOURCE%/*}/run.local" ]] && source "${BASH_SOURCE%/*}/run.local"
2023-11-14 13:04:07 +00:00
2023-10-08 08:45:51 +00:00
TIMEFORMAT=$'\nTask completed in %3lR'
time "${@:-help}"
# vim: ft=bash