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
203 changes: 203 additions & 0 deletions .ahoy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
---
ahoyapi: v2

commands:
build:
usage: Build or rebuild project.
cmd: |
ahoy clean \
&& if [ "$COMPOSER" != "composer.json" ]; then ahoy composer-merge; fi \
&& if [ "$COMPOSER" != "composer.json" ]; then ahoy link-package; fi \
&& (docker network prune -f > /dev/null && docker network inspect amazeeio-network > /dev/null || docker network create amazeeio-network) \
&& ahoy up -- --build --force-recreate \
&& ahoy install-dev \
&& if [ "$COMPOSER" != "composer.json" ] && [ "$DRUPAL_PROFILE" ]; then ahoy init-profile; fi \
&& ahoy install-site \
&& if [ "$COMPOSER" != "composer.json" ]; then ahoy init-module; fi \
&& if [ "$COMPOSER" != "composer.json" ]; then ahoy drush pm-enable tide_test -y; fi \
&& ahoy line "Build complete" \
&& ahoy info 1

info:
usage: Print information about this project.
cmd: |
ahoy line "Site URL : " ${LOCALDEV_URL}:${LOCAL_PORT:-80}/
ahoy line "Path to project : " ${APP}
ahoy line "Path to docroot : " ${APP}/${WEBROOT}
ahoy line "DB port on host : " $(docker port $(docker-compose ps -q mariadb) 3306 | cut -d : -f 2)
ahoy line "Mailhog URL : " http://mailhog.docker.internal:${LOCAL_PORT:-80}/
if [ "$1" ]; then
ahoy line "One-time login : " $(ahoy login -- --no-browser)
fi

up:
usage: Build and start Docker containers.
cmd: |
docker-compose up -d "$@" \
&& ahoy cli "dockerize -wait tcp://mariadb:3306 -timeout 1m" \
&& if docker-compose logs | grep -q "\[Error\]"; then docker-compose logs; exit 1; fi \
&& docker ps -a --filter name=^/${COMPOSE_PROJECT_NAME}_ &&
# Add Bay SSH key before fetching DB.
# During local development, pygmy injects SSH key from the host, so specifying
# key as $BAY_KEY environment variable is not required (the host key of every
# developer must be added to Bay during project onboarding).
if [ "$BAY_KEY" ]; then
ahoy cli "mkdir -p /home/.ssh && echo -e \"$BAY_KEY\" > /home/.ssh/key && chmod 600 /home/.ssh/key;"
fi

down:
usage: Stop Docker containers and remove container, images, volumes and networks.
cmd: docker-compose down --volumes

start:
usage: Start existing Docker containers.
cmd: docker-compose start "$@"

stop:
usage: Stop running Docker containers.
cmd: docker-compose stop "$@"

restart:
usage: Restart all stopped and running Docker containers.
cmd: docker-compose restart

logs:
usage: Show Docker logs.
cmd: docker-compose logs "$@"

pull:
usage: Pull latest docker images.
cmd: |
docker image ls --format \"{{.Repository}}:{{.Tag}}\" | grep singledigital/ | grep -v none | xargs -n1 docker pull | cat \
&& docker image ls --format \"{{.Repository}}:{{.Tag}}\" | grep amazeeio/ | grep -v none | xargs -n1 docker pull | cat

cli:
usage: Start a shell inside CLI container or run a command.
cmd: if \[ "$@" \]; then docker exec -i $(docker-compose ps -q cli) bash -c "$@"; else docker exec -it $(docker-compose ps -q cli) bash; fi

drush:
usage: Run drush commands in the CLI service container.
cmd: docker exec -i $(docker-compose ps -q cli) drush -r ${APP}/${WEBROOT} -l ${LOCALDEV_URL} "$@"

login:
usage: Login to a website.
cmd: ahoy drush user:unblock -q "$(ahoy drush user:information --uid=1 --fields=name --format=string)" 2>/dev/null && ahoy drush user:login --no-browser

doctor:
usage: Find problems with current project setup.
cmd: scripts/doctor.sh

# @note: Call this on the host before starting containers.
composer-merge:
usage: Merge composer files.
cmd: scripts/composer-merge.sh

install-dev:
usage: Install dependencies.
cmd: ahoy cli "composer install -n --ansi --prefer-dist --no-suggest"

install-site:
usage: Install site.
cmd: |
ahoy flush-redis
if [ "$INSTALL_NEW_SITE" == "1" ]; then
ahoy cli -- ./scripts/drupal/install-new-site.sh
else
ahoy cli -- ./scripts/rebuild-env.sh
fi

db-import:
usage: Import the production database.
cmd: ahoy cli -- ./scripts/rebuild-env.sh

fix-bay-token:
usage: Fix the bay token by re-importing.
cmd: |
pygmy stop \
&& sleep 1 \
&& pygmy start \
&& docker ps -a | grep Exit | cut -d ' ' -f 1 | xargs docker rm \
&& docker-compose up -d --force \
&& pygmy stop \
&& sleep 1 \
&& pygmy start

link-package:
usage: Link package from current repository root.
cmd: scripts/link-package.sh
hide: true

init-module:
usage: Install a module from current repository root.
cmd: ahoy cli "INSTALL_SUGGEST=$INSTALL_SUGGEST scripts/drupal-init-module.sh"
hide: true

init-profile:
usage: Install a profile from current repository root.
cmd: ahoy cli "INSTALL_SUGGEST=$INSTALL_SUGGEST scripts/drupal-init-profile.sh"
hide: true

clean:
usage: Remove all build files.
cmd: |
ahoy down \
&& ([ -d .git ] && git ls-files --directory --other -i --exclude-from=.gitignore ${WEBROOT} | grep -v "settings.local.php" | grep -v "services.local.yml" | xargs chmod -Rf 777 || true) \
&& ([ -d .git ] && git ls-files --directory --other -i --exclude-from=.gitignore ${WEBROOT} | grep -v "settings.local.php" | grep -v "services.local.yml" | xargs rm -Rf || true) \
&& rm -Rf vendor \
&& rm -Rf screenshots \
&& rm -Rf composer.build.*

clean-full:
usage: Remove all development files.
cmd: |
ahoy clean \
&& ([ -d .git ] && git ls-files --directory --other . | grep -v ".idea" | xargs chmod -Rf 777 || true) \
&& ([ -d .git ] && git ls-files --directory --other . | grep -v ".idea" | xargs rm -Rf || true)

deploy:
usage: Deploy or re-deploy a branch in Bay.
cmd: ./scripts/bay-deploy.sh "$@"

lint:
usage: Lint code.
cmd: ahoy cli "vendor/bin/phpcs ${PHPCS_TARGETS}"

lint-fix:
usage: Fix lint errors.
cmd: ahoy cli "vendor/bin/phpcbf ${PHPCS_TARGETS}"

test-behat:
usage: Run Behat tests.
cmd: ahoy cli "./vendor/bin/behat --strict --colors ${BEHAT_PROFILE} $@"

flush-redis:
usage: Flush Redis cache.
cmd: docker exec -i $(docker-compose ps -q redis) redis-cli flushall > /dev/null

# Utilities.
line:
cmd: printf "$(tput -Txterm setaf 2)${1}$(tput -Txterm sgr0)${2}\n"
hide: true

entrypoint:
- bash
- "-c"
- |
[ -f .env ] && export $(grep -v '^#' .env | xargs) && [ -f .env.local ] && export $(grep -v '^#' .env.local | xargs)
export DOCKER_BUILDKIT=0
export COMPOSE_DOCKER_CLI_BUILD=0
export PROJECT_NAME=${PROJECT_NAME:-$(basename $(pwd))}
export APP=${APP:-/app}
export WEBROOT=${WEBROOT:-docroot}
export MYSQL_HOST=${MYSQL_HOST:-mariadb}
export MYSQL_PORT=${MYSQL_PORT:-3306}
export COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME:-$PROJECT_NAME}
export LOCALDEV_URL=${LOCALDEV_URL:-http://content-sdp.docker.internal}
export COMPOSER=${COMPOSER:-composer.json}
export DRUPAL_PROFILE=${DRUPAL_PROFILE:-}
export DRUPAL_MODULE_PREFIX=${DRUPAL_MODULE_PREFIX:-mysite}
PHPCS_TARGETS=${PHPCS_TARGETS:-.} && export PHPCS_TARGETS=${PHPCS_TARGETS//,/ }
if [ "$CI" ]; then export ES_TPL=elasticsearch.ci.yml; fi
bash -c "$0" "$@"
- '{{cmd}}'
- '{{name}}'
15 changes: 15 additions & 0 deletions .circleci/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
##
# Build site in CI.
#
set -e

echo "==> Validate composer configuration"
composer validate --ansi --strict --no-check-all --no-check-lock

# Process Docker Compose configuration. This is used to avoid multiple
# docker-compose.yml files.
sed -i -e "/###/d" docker-compose.yml
sed -i -e "s/##//" docker-compose.yml

ahoy build
70 changes: 70 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
version: 2
aliases:
# Re-usable job to run different types of builds.
- &job-build
working_directory: /app
docker:
- image: &builder-image "ghcr.io/dpc-sdp/bay/ci-builder:6.x"
environment:
INSTALL_NEW_SITE: 1
LAGOON_ENVIRONMENT_TYPE: ci
steps:
- attach_workspace:
at: /workspace
- checkout
- setup_remote_docker:
docker_layer_caching: true
- run: .circleci/build.sh
- run: .circleci/test.sh
- run:
name: Copy artifacts
command: .circleci/test-artifacts.sh
when: always
- store_artifacts:
path: /tmp/artifacts

jobs:
build:
<<: *job-build

build_suggest:
<<: *job-build
docker:
- image: *builder-image
environment:
INSTALL_NEW_SITE: 1
LAGOON_ENVIRONMENT_TYPE: ci
INSTALL_SUGGEST: 1
BEHAT_PROFILE: "--profile=suggest"

phpunit_tests:
<<: *job-build
steps:
- attach_workspace:
at: /workspace
- checkout
- setup_remote_docker:
docker_layer_caching: true
- run: .circleci/build.sh
- run:
name: Run phpunit tests and generate coverage
command: |
.circleci/phpunit_tests.sh
.circleci/phpunit_coverage.sh
- run:
name: Copy test results
command: |
.circleci/phpunit_results.sh
when: always
- store_artifacts:
path: /tmp/phpunit
- store_test_results:
path: /tmp/phpunit

workflows:
version: 2
main:
jobs:
- build
- build_suggest
- phpunit_tests
20 changes: 20 additions & 0 deletions .circleci/mirror.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
##
# Mirror repo branch.
#
set -e

MIRROR_GIT_BRANCH=${MIRROR_GIT_BRANCH:-$1}
MIRROR_GIT_REMOTE=${MIRROR_GIT_REMOTE:-origin}
# Flag to push the branch.
MIRROR_GIT_PUSH=${MIRROR_GIT_PUSH:-}

[ "$MIRROR_GIT_BRANCH" == "" ] && echo "ERROR: Git branch is not provided" && exit 1

git checkout -b $MIRROR_GIT_BRANCH

if [ "$MIRROR_GIT_PUSH" == "1" ]; then
git push $MIRROR_GIT_REMOTE $MIRROR_GIT_BRANCH --force
else
echo "Would push to $MIRROR_GIT_BRANCH"
fi
7 changes: 7 additions & 0 deletions .circleci/phpunit_coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
##
# Generate coverage report
#
set -e
echo "==> Generate coverage report"
ahoy cli "phpdbg -qrr vendor/bin/phpunit ./dpc-sdp --coverage-html /app/phpunit/coverage-report"
6 changes: 6 additions & 0 deletions .circleci/phpunit_results.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
##
# Moves phpunit results from inside container to outside.
#
set -e
docker cp $(docker-compose ps -q cli):/app/phpunit/ /tmp/
9 changes: 9 additions & 0 deletions .circleci/phpunit_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
##
# Run phpunit tests in CI.
#
set -e

ahoy cli "mkdir -p /app/phpunit"
echo "==> Run phpunit tests"
ahoy cli "vendor/bin/phpunit ./dpc-sdp --log-junit /app/phpunit/junit.xml"
13 changes: 13 additions & 0 deletions .circleci/test-artifacts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
##
# Copy artifacts from the app container to the build host for storage.
#
set -e

# Create screenshots directory in case it was not created before. This is to
# avoid this script to fail when copying artifacts.
ahoy cli "mkdir -p /app/screenshots"

# Copy from the app container to the build host for storage.
mkdir -p /tmp/artifacts/behat
docker cp $(docker-compose ps -q cli):/app/screenshots /tmp/artifacts/behat
29 changes: 29 additions & 0 deletions .circleci/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
##
# Run tests in CI.
#
set -e

echo "==> Lint code"
ahoy lint

echo "==> Run Behat tests"
mkdir -p /tmp/artifacts/behat
ahoy cli "./vendor/bin/behat --strict --colors --tags="~@skipped" tests"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The order matters a lot since some modules depend on others, which also makes it hard to fully isolate the tests. So please don't change the run order. more modules will be added soon.

ahoy cli "drush en tide_api -y"
ahoy cli "./vendor/bin/behat --strict --colors --tags="~@skipped" modules/tide_api"
ahoy cli "drush en tide_webform -y"
ahoy cli "./vendor/bin/behat --strict --colors --tags="~@skipped" modules/tide_webform"
ahoy cli "drush en tide_media -y"
ahoy cli "./vendor/bin/behat --strict --colors --tags="~@skipped" modules/tide_media"
ahoy cli "drush en tide_event -y"
ahoy cli "./vendor/bin/behat --strict --colors --tags="~@skipped" modules/tide_event"
ahoy cli "drush en tide_grant -y"
ahoy cli "./vendor/bin/behat --strict --colors --tags="~@skipped" modules/tide_grant"
ahoy cli "drush en tide_news -y"
ahoy cli "./vendor/bin/behat --strict --colors --tags="~@skipped" modules/tide_news"
ahoy cli "drush en tide_landing_page -y"
ahoy cli "./vendor/bin/behat --strict --colors --tags="~@skipped" modules/tide_landing_page"
ahoy cli "drush en tide_site -y"
ahoy cli "./vendor/bin/behat --strict --colors modules/tide_site"

9 changes: 9 additions & 0 deletions .docker/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
content-sdp.docker.internal:80 {
reverse_proxy nginx:8080
}
elasticsearch.docker.internal:80 {
reverse_proxy elasticsearch:9200
}
mailhog.docker.internal:80 {
reverse_proxy mailhog:8025
}
Loading