#!/bin/bash set -eu . .env DOCKER_WEB_IMAGE_NAME="ghcr.io/opdavies/${COMPOSE_PROJECT_NAME}-web" TTY="" if [[ ! -t 1 ]]; then TTY="-T" fi DC="${DC:-exec}" function ci:build-images { docker image build . \ --file tools/docker/images/Dockerfile \ --tag ${DOCKER_WEB_IMAGE_NAME}:${DOCKER_TAG} \ --tag ${DOCKER_WEB_IMAGE_NAME}:latest \ --target=production } function ci:push-images { docker image push ${DOCKER_WEB_IMAGE_NAME}:${DOCKER_TAG} docker image push ${DOCKER_WEB_IMAGE_NAME}:latest } function cmd { # Run any command in the app container. _dc app "${@}" } function composer { DC=run _dc --entrypoint composer app "${@}" } function deploy { cd tools/deployment ansible-playbook deploy.yml "${@}" } function help { printf "%s [args]\n\nTasks:\n" "${0}" compgen -A function | grep -v "^_" | cat -n printf "\nExtended help:\n Each task has comments for general usage\n" } function artifact:build { DESTINATION_PATH="${2:-/var/www/oliverdavies.uk}" GIT_COMMIT_HASH=$1 # Clean up any old containers or files within the artifact directory. rm -fr ${DESTINATION_PATH}/* || true docker image pull ghcr.io/opdavies/oliverdavies-uk-web:${GIT_COMMIT_HASH} docker container run \ --entrypoint sh \ --name oliverdavies-uk-web \ ghcr.io/opdavies/oliverdavies-uk-web:${GIT_COMMIT_HASH} docker container cp oliverdavies-uk-web:/code ${DESTINATION_PATH} docker container rm oliverdavies-uk-web } function markdownlint:build { docker image build . \ -f markdownlint.Dockerfile \ -t markdownlint } function markdownlint:run { docker container run --rm \ -v $(pwd)/.markdownlint.yaml:/root/.markdownlint.yaml \ -v $(pwd)/source:/data \ markdownlint } function sh { DC=run _dc --entrypoint sh app } function test:quality { DC=run _dc --entrypoint phpstan app "${@}" analyze --memory-limit=-1 } function test:unit { DC=run _dc --entrypoint phpunit app "${@}" } function _dc { docker-compose ${DC} ${TTY} "${@}" } eval "${@:-help}"