refactor: remove old code and templates

This commit is contained in:
Oliver Davies 2023-09-25 00:57:06 +01:00
parent ad86e066cb
commit 9176f34444
16 changed files with 2 additions and 520 deletions

View file

@ -6,7 +6,6 @@ namespace App\Action;
use App\DataTransferObject\Config;
use App\DataTransferObject\TemplateFile;
use App\Enum\Language;
use App\Enum\ProjectType;
use App\Enum\WebServer;
use Illuminate\Support\Arr;
@ -45,14 +44,14 @@ final class CreateListOfFilesToGenerate
new TemplateFile(data: 'fractal/justfile', name: 'justfile'),
]);
if (self::isDocker($configurationData)) {
if ($isDocker) {
$filesToGenerate->push(new TemplateFile(data: 'fractal/.env.example', name: '.env.example'));
$filesToGenerate->push(new TemplateFile(data: 'fractal/.dockerignore', name: '.dockerignore'));
$filesToGenerate->push(new TemplateFile(data: 'fractal/.hadolint.yaml', name: '.hadolint.yaml'));
$filesToGenerate->push(new TemplateFile(data: 'fractal/.yarnrc', name: '.yarnrc'));
$filesToGenerate->push(new TemplateFile(data: 'fractal/Dockerfile', name: 'Dockerfile'));
$filesToGenerate->push(new TemplateFile(data: 'fractal/docker-compose.yaml', name: 'docker-compose.yaml'));
} elseif (self::isFlake($configurationData)) {
} elseif ($isFlake) {
$filesToGenerate->push(new TemplateFile(data: 'fractal/.envrc', name: '.envrc'));
$filesToGenerate->push(new TemplateFile(data: 'fractal/flake.nix', name: 'flake.nix'));
}
@ -118,29 +117,6 @@ final class CreateListOfFilesToGenerate
break;
}
// TODO: remove?
if ($isDocker) {
$filesToGenerate->push(new TemplateFile(data: 'common/.dockerignore', name: '.dockerignore'));
$filesToGenerate->push(new TemplateFile(data: 'common/.hadolint.yaml', name: '.hadolint.yaml'));
$filesToGenerate->push(new TemplateFile(data: 'env.example', name: '.env.example'));
}
// TODO: remove?
if ($isFlake) {
$filesToGenerate->push(new TemplateFile(data: 'common/envrc', name: '.envrc'));
$filesToGenerate->push(new TemplateFile(data: 'common/flake.nix', name: 'flake.nix'));
}
// TODO: remove?
if (false !== Arr::get($configurationData, "justfile", true)) {
$filesToGenerate[] = new TemplateFile(data: 'justfile', name: 'justfile');
}
// TODO: remove?
if (isset($configurationData['dockerCompose']) && $configurationData['dockerCompose'] !== null) {
$filesToGenerate[] = new TemplateFile(data: 'docker-compose.yaml', name: 'docker-compose.yaml');
}
$filesToGenerate[] = new TemplateFile(
data: 'common/.githooks/prepare-commit-msg',
name: 'prepare-commit-msg',

View file

@ -1,4 +0,0 @@
/README.md
{% if experimental.createGitHubActionsConfiguration %}
/.github/
{%-endif-%}

View file

@ -1,2 +0,0 @@
ignore:
- DL3059

View file

@ -1,3 +0,0 @@
# {{ managedText }}
use flake

View file

@ -1,23 +0,0 @@
{
inputs = {
devshell.url = "github:numtide/devshell";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [ inputs.devshell.flakeModule ];
systems = [ "x86_64-linux" ];
perSystem = { config, self', inputs', pkgs, system, ... }: {
devshells.default = {
packages = with pkgs; [
{% for package in flake.devshell.packages %}
"{{ package }}"
{% endfor %}
];
};
};
};
}

View file

@ -1,105 +0,0 @@
# {{ managedText | raw }}
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`,
{% for host in web.extra_hosts | default([]) -%}
{{ '`' ~ host ~ '`,' }}
{%- endfor %}
)"
x-app: &default-app
volumes:
- "${DOCKER_WEB_VOLUME:-./{{ "drupal" == type ? drupal.docroot : '' }}:{{ project_root }}{{ "drupal" == type ? '/' ~ drupal.docroot : '' }}}"
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:
{% if "web" in dockerCompose.services %}
web:
<<: [*default-proxy, *default-app]
build:
context: .
target: web
depends_on:
- php
profiles: [web]
{% endif %}
{% if "php" == language %}
{% set anchors = [
"apache" in php.version ? "*default-proxy" : null,
"*default-app",
] -%}
php:
<<: [{{ anchors | filter(item => item is not null) | join(", ") }}]
build:
context: .
target: build
args:
- "DOCKER_UID=${DOCKER_UID:-1000}"
volumes:
- .:{{ project_root }}
{% if "database" in dockerCompose.services -%}
depends_on:
- database
{% endif -%}
profiles: [php]
{% elseif "node" == language %}
node:
{{ type is same as "fractal" ? "<<: [*default-proxy, *default-app]" : "<<: *default-app" }}
build:
context: .
target: build
volumes:
- .:{{ project_root }}
{% if "database" in dockerCompose.services -%}
depends_on:
- database
{% endif -%}
profiles: [node]
{% endif %}
{% if "database" in dockerCompose.services %}
database:
image: {{ database.type }}:{{ database.version }}
deploy:
resources:
limits:
cpus: "${DOCKER_MYSQL_CPUS:-0}"
memory: "${DOCKER_MYSQL_MEMORY:-0}"
volumes:
- db-data:/var/lib/mysql
{{ database.extra_databases is not empty ? '- ./tools/docker/images/database/root/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d' : '' }}
env_file:
- .env
labels:
- "traefik.enabled=false"
environment:
MYSQL_RANDOM_ROOT_PASSWORD: true
profiles: [database]
volumes:
db-data: {}
{% endif -%}
networks:
web:
external: true
name: traefik_proxy

View file

@ -1,20 +0,0 @@
# {{ managedText | raw }}
export DOCKER_UID=1000
{% if dockerCompose %}
export COMPOSE_PROJECT_NAME={{ name }}
export COMPOSE_PROFILES=web,php,database
export DOCKER_WEB_VOLUME=.:{{ project_root }}
{% endif %}
{% if experimental.useNewDatabaseCredentials %}
export MYSQL_DATABASE=app
export MYSQL_PASSWORD=app
export MYSQL_USER=app
{% else %}
export MYSQL_DATABASE=drupal
export MYSQL_PASSWORD=drupal
export MYSQL_USER=drupal
{% endif %}

View file

@ -1,121 +0,0 @@
# {{ managedText | raw }}
{% set isFlake = flake is defined %}
default:
@just --list
# Start the project
start:
cp -v --no-clobber .env.example .env
docker compose up -d
# Stop the project
stop:
docker compose down
{% if "php" is same as language %}
composer *args:
{{ "just _exec php composer {{ args }}" | raw }}
alias phpunit := test
test *args:
{% if "drupal" is same as type %}
{{ "just _exec php phpunit --colors=always {{ args }}" | raw }}
{% else %}
{{ "just _run php phpunit --colors=always {{ args }}" | raw }}
{% endif %}
{% endif %}
{% if "drupal" is same as type %}
drush *args:
{{ "just _exec php drush {{ args }}" | raw }}
install *args:
{{ "just _exec php drush site:install -y {{ args }}" | raw }}
{% endif %}
{% if "node" is same as language %}
yarn *args:
{% if isFlake %}
{{ "just _exec yarn {{ args }}" | raw }}
{% else %}
{{ "just _exec node yarn {{ args }}" | raw }}
{% endif %}
{% endif %}
{% if "fractal" is same as type %}
fractal *args:
{{ "just yarn fractal {{ args }}" | raw }}
clean:
rm -fr build
build *args:
{{ "just fractal build {{ args }}" | raw }}
sync: clean build
#!/usr/bin/env bash
set -eux
aws s3 sync "build/." s3://"${BUCKET_NAME}" \
--acl "public-read" \
--cache-control max-age=3600
{% endif %}
{% if "laravel" is same as type %}
artisan *args:
{{ "just _run artisan {{ args }}" | raw }}
{% endif %}
# Enable or disable Git hooks
git-hooks command:
#!/usr/bin/env bash
set -euo pipefail
case "{{ '{{ command }}'|raw }}" in
"on")
echo "Enabling Git hooks..."
git config core.hooksPath .githooks
;;
"off")
echo "Disabling Git hooks..."
git config --unset core.hooksPath
;;
*)
echo "Error: Invalid argument. Must be either 'on' or 'off'"
;;
esac
{% if experimental.runGitHooksBeforePush %}
test-commit:
{% if "phpcs" in php|keys -%}
just _run php phpcs
{%- endif %}
{% if "phpstan" in php|keys -%}
just _run php phpstan analyze --no-progress --memory-limit=512M
{%- endif %}
just test --testdox --testsuite unit
just test --testdox --testsuite kernel
{% endif %}
_exec +args:
{% if flake is defined %}
{{ "nix develop --command {{ args }}" | raw }}
{% else %}
{{ "docker compose exec -T {{ args }}" | raw }}
{% endif %}
{% if flake is not defined %}
_run service command *args:
docker compose run \
--entrypoint {{ "{{ command }}"|raw }} \
--no-deps \
--rm \
-T \
{{ "{{ service }} {{ args }}"|raw }}
{% endif %}
# vim: ft=just

View file

@ -1,104 +0,0 @@
# {{ managedText | raw }}
FROM php:{{ php.version }} AS base
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
RUN which composer && composer -V
ARG DOCKER_UID=1000
ENV DOCKER_UID="${DOCKER_UID}"
WORKDIR {{ project_root }}
RUN adduser --disabled-password --uid "${DOCKER_UID}" app \
&& chown app:app -R {{ project_root }}
USER app
ENV PATH="${PATH}:{{ project_root }}/bin:{{ project_root }}/vendor/bin"
COPY --chown=app:app composer.* ./
################################################################################
FROM base AS build
USER root
{% if 'apache' in php.version %}
RUN a2enmod rewrite
{% endif %}
{% if dockerfile.stages.build.packages %}
RUN apt-get update -yqq \
&& apt-get install -yqq --no-install-recommends \
{{ dockerfile.stages.build.packages | join(' ') }}
{% endif %}
RUN docker-php-ext-configure gd --with-jpeg
{% if dockerfile.stages.build.extensions.install %}
RUN docker-php-ext-install {{ dockerfile.stages.build.extensions.install | join(' ') }}
{% endif %}
COPY --chown=app:app phpunit.xml* ./
{% if dockerfile.stages.build.extra_files %}
COPY --chown=app:app {{ dockerfile.stages.build.extra_files | join(" ") }} ./
{% endif %}
{% for directory in dockerfile.stages.build.extra_directories %}
COPY --chown=app:app {{ directory }} {{ directory }}
{% endfor %}
{% for command in dockerfile.stages.build.root_commands | default([]) %}
RUN {{ command | raw }}
{% endfor %}
USER app
{% for command in dockerfile.stages.build.commands %}
RUN {{ command }}
{% endfor %}
COPY --chown=app:app tools/docker/images/php/root /
ENTRYPOINT ["/usr/local/bin/docker-entrypoint-php"]
CMD ["php-fpm"]
{% if dockerfile.stages.test %}
################################################################################
FROM {{ dockerfile.stages.test.extends }} AS test
COPY --chown=app:app . .
RUN {% for command in dockerfile.stages.test.commands -%}
{% if not loop.first %} && {% endif %}
{{ command }}
{%- if not loop.last %} \{% endif %}
{% endfor %}
{% endif %}
{% if web.type == "caddy" %}
################################################################################
FROM caddy:2 as web
WORKDIR {{ project_root }}
COPY tools/docker/images/web/root /
{% endif %}
{% if web.type == "nginx" %}
################################################################################
FROM nginx:1 as web
EXPOSE 8080
WORKDIR {{ project_root }}
COPY tools/docker/images/web/root /
{% endif %}

View file

@ -1,7 +0,0 @@
#!/usr/bin/env bash
# {{ managedText | raw }}
[[ -f composer.json && ! -d vendor ]] && composer install
eval "$@"

View file

@ -1,4 +0,0 @@
# {{ managedText }}
max_vars_input = 1000
memory_limit = {{ php.ini.memory_limit | default('128M') }}

View file

@ -1,40 +0,0 @@
<?xml version="1.0"?>
<!-- {{ managedText | raw }} -->
<ruleset name="{{ name }} coding standards">
<description>PHPCS configuration file for {{ name }}.</description>
{% for path in php.phpcs.paths|default('[]') %}
<file>{{ path }}</file>
{% endfor %}
<arg value="np"/>
{% for standard in php.phpcs.standards|default(['Drupal', 'DrupalPractice']) %}
{% if not standard is same as "Drupal" %}
<rule ref="{{ standard }}"/>
{% endif %}
{% endfor %}
{% if type is same as "drupal" and "Drupal" in php.phpcs.standards or php.phpcs.standards is empty %}
<rule ref="Drupal">
<exclude name="Drupal.Commenting.ClassComment.Missing"/>
<exclude name="Drupal.Commenting.DataTypeNamespace.DataTypeNamespace"/>
<exclude name="Drupal.Commenting.Deprecated"/>
<exclude name="Drupal.Commenting.DocComment.ContentAfterOpen"/>
<exclude name="Drupal.Commenting.DocComment.MissingShort"/>
<exclude name="Drupal.Commenting.FunctionComment.IncorrectParamVarName"/>
<exclude name="Drupal.Commenting.FunctionComment.IncorrectTypeHint"/>
<exclude name="Drupal.Commenting.FunctionComment.InvalidReturn"/>
<exclude name="Drupal.Commenting.FunctionComment.Missing"/>
<exclude name="Drupal.Commenting.FunctionComment.MissingParamComment"/>
<exclude name="Drupal.Commenting.FunctionComment.MissingReturnComment"/>
<exclude name="Drupal.Commenting.FunctionComment.ParamTypeSpaces"/>
<exclude name="Drupal.Commenting.FunctionComment.TypeHintMissing"/>
<exclude name="Drupal.Commenting.InlineComment.DocBlock"/>
<exclude name="Drupal.Commenting.VariableComment.Missing"/>
<exclude name="Drupal.NamingConventions.ValidFunctionName.ScopeNotCamelCaps"/>
<exclude name="DrupalPractice.Objects.StrictSchemaDisabled.StrictConfigSchema"/>
</rule>
{% endif %}
</ruleset>

View file

@ -1,16 +0,0 @@
# {{ managedText | raw }}
parameters:
level: {{ php.phpstan.level }}
excludePaths:
- *Test.php
- *TestBase.php
paths:
{% for path in php.phpstan.paths | default(["src"]) -%}
- {{ path }}
{%- endfor %}
{% if php.phpstan.baseline %}
includes:
- phpstan-baseline.neon
{% endif %}

View file

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- {{ managedText | raw }} -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="false"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="false"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
verbose="true">
<testsuites>
<testsuite name="{{ name }}">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>

View file

@ -1,3 +0,0 @@
# {{ managedText | raw }}
--modules-folder /node_modules

View file

@ -1,20 +0,0 @@
FROM node:{{ node.version }} AS base
WORKDIR {{ project_root }}
RUN mkdir /node_modules \
&& chown node:node -R {{ project_root }} /node_modules
COPY --chown=node:node package*.json *yarn* {{ project_root }}
USER node
################################################################################
FROM base AS build
RUN yarn install --frozen-lockfile
COPY --chown=node:node . .
CMD ["bash"]