diff --git a/tests/Unit/SnapshotTest.php b/tests/Unit/SnapshotTest.php index 2c079c4..efde332 100755 --- a/tests/Unit/SnapshotTest.php +++ b/tests/Unit/SnapshotTest.php @@ -17,6 +17,7 @@ class SnapshotTest extends TestCase 'drupal', 'drupal-commerce-kickstart', 'drupal-localgov', + 'fractal', ]; public function testCompareFiles(): void @@ -41,10 +42,12 @@ public function testCompareFiles(): void private function runCliTool(string $config): void { + $configFilePath = getcwd() . "/tests/snapshots/configs/{$config}.yaml"; + $cliCommand = sprintf( "%s app:generate --config-file %s --output-dir %s", getcwd() . '/bin/build-configs', - getcwd() . "/tests/snapshots/configs/{$config}.yaml", + $configFilePath, getcwd() . "/.ignored/snapshots/output/{$config}", ); diff --git a/tests/snapshots/configs/fractal.yaml b/tests/snapshots/configs/fractal.yaml new file mode 100644 index 0000000..06f9248 --- /dev/null +++ b/tests/snapshots/configs/fractal.yaml @@ -0,0 +1,15 @@ +name: docker-fractal +language: javascript +type: fractal + +node: + version: 20-bullseye-slim + +dockerfile: [] + +docker-compose: + services: + - node + +experimental: + createGitHubActionsConfiguration: true diff --git a/tests/snapshots/output/fractal/.dockerignore b/tests/snapshots/output/fractal/.dockerignore new file mode 100644 index 0000000..1cce59b --- /dev/null +++ b/tests/snapshots/output/fractal/.dockerignore @@ -0,0 +1,3 @@ +Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs. + +README.md diff --git a/tests/snapshots/output/fractal/.env.example b/tests/snapshots/output/fractal/.env.example new file mode 100644 index 0000000..9f91cb6 --- /dev/null +++ b/tests/snapshots/output/fractal/.env.example @@ -0,0 +1,8 @@ +# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs. + +export DOCKER_UID=1000 + +export COMPOSE_PROJECT_NAME=docker-fractal +export COMPOSE_PROFILES=node + +export DOCKER_WEB_VOLUME=.:/app diff --git a/tests/snapshots/output/fractal/.githooks/prepare-commit-msg b/tests/snapshots/output/fractal/.githooks/prepare-commit-msg new file mode 100755 index 0000000..6ff8ea0 --- /dev/null +++ b/tests/snapshots/output/fractal/.githooks/prepare-commit-msg @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs. + +# Load the issue ID from an `.issue-id` file within the project and replace the +# `ISSUE_ID` placeholder within a Git commit message. +# +# For example, running `echo "OD-123" > .issue-id` will add `Refs: OD-123` to +# the commit message. +# +# This also works with multiple issue IDs in the same string, e.g. +# "OD-123 OD-456", or IDs on multiple lines. + +set -o errexit +set -o nounset +set -o pipefail + +PROJECT_DIR=$(git rev-parse --show-toplevel) +ISSUE_FILE="$PROJECT_DIR/.issue-id" + +if [ -f "${ISSUE_FILE}" ]; then + ISSUE_IDS=$(cat "${ISSUE_FILE}" | tr '\n' ',' | tr ' ' ',' | sed 's/,$//' | sed 's/,/, /g') + + if [ -n "${ISSUE_IDS}" ]; then + sed -i.bak "s/# Refs:/Refs: $ISSUE_IDS/" "$1" + fi +fi diff --git a/tests/snapshots/output/fractal/.github/workflows/ci.yml b/tests/snapshots/output/fractal/.github/workflows/ci.yml new file mode 100644 index 0000000..e2b03e3 --- /dev/null +++ b/tests/snapshots/output/fractal/.github/workflows/ci.yml @@ -0,0 +1,25 @@ +name: CI + +on: + pull_request: + push: + workflow_dispatch: + +env: + COMPOSE_DOCKER_CLI_BUILD: 1 + DOCKER_BUILDKIT: 1 + DOCKER_UID: 1001 + +jobs: + build: + name: Build + + runs-on: ubuntu-latest + + steps: + - name: Checkout the code + uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4 + + - name: Build + run: | + ./run ci:build diff --git a/tests/snapshots/output/fractal/.gitignore b/tests/snapshots/output/fractal/.gitignore new file mode 100644 index 0000000..2a8d0e8 --- /dev/null +++ b/tests/snapshots/output/fractal/.gitignore @@ -0,0 +1,9 @@ +# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs. + +node_modules + +# Docker. +.env +docker-compose.override.yaml + + diff --git a/tests/snapshots/output/fractal/.hadolint.yaml b/tests/snapshots/output/fractal/.hadolint.yaml new file mode 100644 index 0000000..d87bf88 --- /dev/null +++ b/tests/snapshots/output/fractal/.hadolint.yaml @@ -0,0 +1,2 @@ +ignore: + - DL3059 diff --git a/tests/snapshots/output/fractal/.yarnrc b/tests/snapshots/output/fractal/.yarnrc new file mode 100644 index 0000000..6dcecd4 --- /dev/null +++ b/tests/snapshots/output/fractal/.yarnrc @@ -0,0 +1,3 @@ +# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs. + +--modules-folder /node_modules diff --git a/tests/snapshots/output/fractal/Dockerfile b/tests/snapshots/output/fractal/Dockerfile new file mode 100644 index 0000000..401685e --- /dev/null +++ b/tests/snapshots/output/fractal/Dockerfile @@ -0,0 +1,20 @@ +FROM node:20-bullseye-slim AS base + +WORKDIR /app + +RUN mkdir /node_modules \ + && chown node:node -R /app /node_modules + +COPY --chown=node:node package*.json *yarn* /app + +USER node + +################################################################################ + +FROM base AS build + +RUN yarn install --frozen-lockfile + +COPY --chown=node:node . . + +CMD ["bash"] diff --git a/tests/snapshots/output/fractal/docker-compose.yaml b/tests/snapshots/output/fractal/docker-compose.yaml new file mode 100644 index 0000000..5aa3f79 --- /dev/null +++ b/tests/snapshots/output/fractal/docker-compose.yaml @@ -0,0 +1,44 @@ +# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs. + +x-proxy: &default-proxy + networks: + - default + - web + labels: + - "traefik.docker.network=traefik_proxy" + - "traefik.http.routers.${COMPOSE_PROJECT_NAME}.rule=Host( + `${COMPOSE_PROJECT_NAME}.localhost`, + )" + +x-app: &default-app + volumes: + - "${DOCKER_WEB_VOLUME:-./:/app}" + env_file: + - .env + restart: "${DOCKER_RESTART_POLICY:-unless-stopped}" + networks: + - default + deploy: + resources: + limits: + cpus: "${DOCKER_MYSQL_CPUS:-0}" + memory: "${DOCKER_MYSQL_MEMORY:-0}" + labels: + - "traefik.enabled=false" + tty: true + +services: + + node: + <<: [*default-proxy, *default-app] + build: + context: . + target: build + volumes: + - .:/app + profiles: [node] + +networks: + web: + external: true + name: traefik_proxy diff --git a/tests/snapshots/output/fractal/run b/tests/snapshots/output/fractal/run new file mode 100755 index 0000000..eb1ae03 --- /dev/null +++ b/tests/snapshots/output/fractal/run @@ -0,0 +1,113 @@ +#!/usr/bin/env bash + +# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs. + +set -o errexit +set -o pipefail + +PATH="$PATH:./node_modules/.bin" + +# 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 + +# Remove and generated or temporary files. +function build { + cmd fractal build "${@}" +} + +function ci:build { + cp -v --no-clobber .env.example .env + + docker network create traefik_proxy || true + + docker compose up -d + + build +} + +# Remove and generated or temporary files. +function clean { + rm -fr build node_modules + touch build/.keep +} + +# Disable Git hooks. +function git-hooks:off { + git config --unset core.hooksPath +} + +# Enable Git hooks. +function git-hooks:on { + git config core.hooksPath .githooks +} + +# Create a new Fractal component. +function fractal:new { + mkdir -p "components/${1}" + + echo "name: ${1}" > "components/${1}/${1}.config.yml" + echo "${1}" > "components/${1}/${1}.twig" +} + +# Display a list of all available commands. +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" +} + +# Start the project. +function start { + cp -v --no-clobber .env.example .env + docker compose up -d + } + +function sync { + clean + fractal build + + aws s3 sync "build/." s3://"${BUCKET_NAME}" \ + --acl "public-read" \ + --cache-control max-age=3600 +} + +# Run a command within the node container. +function cmd { + docker compose exec node yarn "${@}" +} + +# Stop the project +function stop { + docker compose down +} + +# Execute yarn commands. +function yarn { + cmd node yarn "${@}" +} + +function _run { + local service="${1}" + local command="${2}" + + docker compose run \ + --entrypoint "${command}" \ + --no-deps \ + --rm \ + -T \ + "${service}" "${@}" +} + +# Include any local tasks. +[[ -e run.local ]] && source run.local + +TIMEFORMAT=$'\nTask completed in %3lR' +time "${@:-help}" + +# vim: ft=bash