2021-12-03 08:44:26 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
TTY=""
|
|
|
|
if [[ ! -t 1 ]]; then
|
|
|
|
TTY="-T"
|
|
|
|
fi
|
|
|
|
|
2021-12-19 19:54:28 +00:00
|
|
|
export COMPOSE_DOCKER_CLI_BUILD=1
|
|
|
|
export DOCKER_BUILDKIT=1
|
|
|
|
|
2021-12-14 23:28:32 +00:00
|
|
|
function task:build-and-push-images {
|
|
|
|
export DOCKER_BUILDKIT=1
|
|
|
|
|
|
|
|
docker-compose build assets
|
|
|
|
docker-compose push assets
|
|
|
|
}
|
|
|
|
|
|
|
|
function task:copy-theme-assets {
|
2021-12-18 00:30:53 +00:00
|
|
|
docker container run --entrypoint sh --name oliverdavies-uk-assets ghcr.io/opdavies/oliverdavies-uk-assets:node-14
|
2021-12-14 23:28:32 +00:00
|
|
|
docker cp oliverdavies-uk-assets:/node/build web/themes/custom/opdavies
|
|
|
|
docker container rm oliverdavies-uk-assets
|
|
|
|
}
|
|
|
|
|
2021-12-04 21:20:36 +00:00
|
|
|
function task:bash {
|
|
|
|
task:exec bash "${@}"
|
2021-12-03 08:44:26 +00:00
|
|
|
}
|
|
|
|
|
2021-12-07 02:20:32 +00:00
|
|
|
function task:ci:build {
|
|
|
|
docker-compose build php
|
|
|
|
docker-compose push php
|
|
|
|
}
|
|
|
|
|
2021-12-08 20:29:43 +00:00
|
|
|
function task:ci:deploy {
|
2021-12-09 22:24:11 +00:00
|
|
|
ansible-galaxy install -r tools/deployment/requirements.yml
|
|
|
|
|
2021-12-08 20:29:43 +00:00
|
|
|
ansible-playbook tools/deployment/deploy.yml \
|
2021-12-09 22:24:11 +00:00
|
|
|
-e "ansistrano_deploy_branch=${1:-production}" \
|
2021-12-08 20:29:43 +00:00
|
|
|
-i tools/deployment/hosts.yml \
|
2021-12-09 22:24:11 +00:00
|
|
|
--vault-password-file="${2:-tools/deployment/.vault-pass.txt}" \
|
2021-12-08 20:29:43 +00:00
|
|
|
"${@}"
|
|
|
|
}
|
|
|
|
|
2021-12-04 21:20:36 +00:00
|
|
|
function task:ci:test {
|
|
|
|
task:lint:dockerfile
|
2021-12-03 08:45:36 +00:00
|
|
|
}
|
|
|
|
|
2021-12-04 21:20:36 +00:00
|
|
|
function task:exec {
|
2021-12-03 08:44:26 +00:00
|
|
|
# Run any command in the php container.
|
2021-12-09 22:24:43 +00:00
|
|
|
docker-compose exec $TTY php "${@}"
|
2021-12-03 08:44:26 +00:00
|
|
|
}
|
|
|
|
|
2021-12-04 21:20:36 +00:00
|
|
|
function task:composer {
|
2021-12-03 08:44:26 +00:00
|
|
|
# Execute Composer commands.
|
2021-12-04 21:20:36 +00:00
|
|
|
task:exec composer "${@}"
|
2021-12-03 08:44:26 +00:00
|
|
|
}
|
|
|
|
|
2021-12-04 21:20:36 +00:00
|
|
|
function task:db:export {
|
|
|
|
task:drush sql:dump \
|
2021-12-03 08:44:26 +00:00
|
|
|
--gzip \
|
|
|
|
--result-file=/app/drupal.sql
|
|
|
|
}
|
|
|
|
|
2021-12-04 21:20:36 +00:00
|
|
|
function task:drupal:install {
|
2021-12-03 08:44:26 +00:00
|
|
|
# Install Drupal.
|
2021-12-04 21:20:36 +00:00
|
|
|
task:drush site:install -y --account-pass admin123 --existing-config
|
2021-12-03 08:44:26 +00:00
|
|
|
}
|
|
|
|
|
2021-12-04 21:20:36 +00:00
|
|
|
function task:drush {
|
2021-12-03 08:44:26 +00:00
|
|
|
# Execute Drush commands.
|
2021-12-04 21:20:36 +00:00
|
|
|
task:exec drush "${@}"
|
2021-12-03 08:44:26 +00:00
|
|
|
}
|
|
|
|
|
2021-12-04 21:20:36 +00:00
|
|
|
function task:frontend:console {
|
2021-12-03 08:44:26 +00:00
|
|
|
docker-compose run --rm node
|
|
|
|
}
|
|
|
|
|
2021-12-04 21:20:36 +00:00
|
|
|
function task:help {
|
2021-12-03 08:44:26 +00:00
|
|
|
printf "%s <task> [args]\n\nTasks:\n" "${0}"
|
|
|
|
|
2021-12-04 21:20:36 +00:00
|
|
|
# Only show functions that have the "task:" prefix.
|
|
|
|
compgen -A function | sed -En 's/task:(.*)/\1/p' | cat -n
|
2021-12-03 08:44:26 +00:00
|
|
|
|
|
|
|
printf "\nExtended help:\n Each task has comments for general usage\n"
|
|
|
|
}
|
|
|
|
|
2021-12-04 21:20:36 +00:00
|
|
|
function task:lint:dockerfile {
|
2021-12-03 08:44:26 +00:00
|
|
|
docker container run --rm -i \
|
|
|
|
-v $(pwd)/.hadolint.yaml:/.config/hadolint.yaml \
|
|
|
|
hadolint/hadolint hadolint \
|
|
|
|
--ignore DL3008 \
|
|
|
|
--ignore DL3022 \
|
2021-12-28 01:28:23 +00:00
|
|
|
"${@}" - < Dockerfile
|
2021-12-03 08:44:26 +00:00
|
|
|
}
|
|
|
|
|
2021-12-04 21:20:36 +00:00
|
|
|
function task:test:functional {
|
|
|
|
run-tests --testsuite functional "${@}"
|
2021-12-03 08:44:26 +00:00
|
|
|
}
|
|
|
|
|
2021-12-04 21:20:36 +00:00
|
|
|
function task:test:integration {
|
2021-12-03 08:44:26 +00:00
|
|
|
# Run integration tests.
|
2021-12-04 21:20:36 +00:00
|
|
|
run-tests --testsuite kernel "${@}"
|
2021-12-03 08:44:26 +00:00
|
|
|
}
|
|
|
|
|
2021-12-04 21:20:36 +00:00
|
|
|
function task:test:quality {
|
2021-12-03 08:44:26 +00:00
|
|
|
# Run quality checks (code linting, static analysis, etc.).
|
2021-12-04 21:20:36 +00:00
|
|
|
docker-compose run --no-deps php phpcs
|
|
|
|
docker-compose run --no-deps php phpstan "--memory-limit=256M"
|
2021-12-03 08:44:26 +00:00
|
|
|
}
|
|
|
|
|
2021-12-04 21:20:36 +00:00
|
|
|
function task:test:unit {
|
2021-12-03 08:44:26 +00:00
|
|
|
# Run unit tests.
|
2021-12-04 21:20:36 +00:00
|
|
|
run-tests --testsuite unit "${@}"
|
2021-12-03 08:44:26 +00:00
|
|
|
}
|
|
|
|
|
2021-12-04 21:20:36 +00:00
|
|
|
function run-tests {
|
|
|
|
# Run PHPUnit tests.
|
2021-12-28 02:15:08 +00:00
|
|
|
docker-compose run --rm php --user ${DOCKER_WEB_USER} php phpunit "${@}"
|
|
|
|
}
|
|
|
|
|
|
|
|
function task:yarn:build:css {
|
|
|
|
# Build CSS assets, this is meant to be run from within the assets container.
|
|
|
|
local args=()
|
|
|
|
|
|
|
|
if [ "${NODE_ENV}" == "production" ]; then
|
|
|
|
args=(--minify)
|
|
|
|
else
|
|
|
|
args=(--watch)
|
|
|
|
fi
|
|
|
|
|
|
|
|
tailwindcss --postcss --input assets/css/tailwind.pcss \
|
|
|
|
--output build/app.css "${args[@]}"
|
2021-12-03 08:44:26 +00:00
|
|
|
}
|
|
|
|
|
2021-12-28 16:04:07 +00:00
|
|
|
function task:yarn:build:js {
|
|
|
|
# Build JS assets, this is meant to be run from within the assets container.
|
|
|
|
local args=()
|
|
|
|
|
|
|
|
if [ "${NODE_ENV}" == "production" ]; then
|
|
|
|
args=(--minify)
|
|
|
|
else
|
|
|
|
args=(--sourcemap --watch)
|
|
|
|
fi
|
|
|
|
|
|
|
|
esbuild assets/js/*.* --outdir=build --bundle "${args[@]}"
|
|
|
|
}
|
|
|
|
|
2021-12-04 21:20:36 +00:00
|
|
|
eval "task:${@:-help}"
|