Add remaining templates

This commit is contained in:
Oliver Davies 2023-01-19 19:47:15 +00:00
parent 014b6dabeb
commit 579c476a54
8 changed files with 198 additions and 5 deletions

View file

@ -28,16 +28,27 @@ final class BuildConfigurationCommand extends Command
parent::__construct();
}
public function execute(InputInterface $input, OutputInterface $output)
public function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$buildYaml = Yaml::parseFile(getcwd().'/build.yaml');
$configurationData = Yaml::parseFile(getcwd().'/build.yaml');
$configurationData['dockerCompose'] = $configurationData['docker-compose'];
$configurationData['docker-compose'] = null;
$io->info("Building configuration for {$buildYaml['name']}.");
$io->info("Building configuration for {$configurationData['name']}.");
if ($buildYaml['language'] === self::LANGUAGE_PHP) {
$this->filesystem->dumpFile('Dockerfile', $this->twig->render('php/Dockerfile.twig', $buildYaml));
$this->filesystem->dumpFile('.env.example', $this->twig->render('env.example.twig', $configurationData));
$this->filesystem->dumpFile('Dockerfile', $this->twig->render('Dockerfile.twig', $configurationData));
if ($configurationData['dockerCompose'] === true) {
$this->filesystem->dumpFile('docker-compose.yaml', $this->twig->render('docker-compose.yaml.twig', $configurationData));
}
if ($configurationData['language'] === self::LANGUAGE_PHP) {
$this->filesystem->dumpFile('phpcs.xml.dist', $this->twig->render('phpcs.xml.twig', $configurationData));
$this->filesystem->dumpFile('phpstan.neon.dist', $this->twig->render('phpstan.neon.twig', $configurationData));
$this->filesystem->dumpFile('phpunit.xml.dist', $this->twig->render('phpunit.xml.twig', $configurationData));
}
return Command::SUCCESS;

58
templates/Dockerfile.twig Normal file
View file

@ -0,0 +1,58 @@
FROM php:{{ php.version }} AS base
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
RUN which composer && composer -V
WORKDIR /app
ENV PATH="${PATH}:/app/vendor/bin"
COPY composer.* ./
{% if dockerfile.stages.build %}
################################################################################
FROM {{ dockerfile.stages.build.extends }} AS build
{% if dockerfile.stages.build.packages %}
RUN apt-get update -yqq \
&& apt-get install -yqq --no-install-recommends \
{{ dockerfile.stages.build.packages | join(' ') }}
{% endif %}
{% if dockerfile.stages.build.extensions.install %}
RUN docker-php-ext-install {{ dockerfile.stages.build.extensions.install | join(' ') }}
{% endif %}
RUN {% for command in dockerfile.stages.build.commands %}
{% if not loop.first %} && {% endif %}
{{- command }}
{%- if not loop.last %} \{% endif %}
{% endfor %}
{% endif %}
{% if dockerfile.stages.test %}
################################################################################
FROM {{ dockerfile.stages.test.extends }} AS test
COPY . .
RUN {% for command in dockerfile.stages.test.commands -%}
{% if not loop.first %} && {% endif %}
{{- command }}
{%- if not loop.last %} \{% endif %}
{% endfor %}
{% endif %}
{% if web.type == "nginx" %}
################################################################################
FROM nginx:1 as web
EXPOSE 8080
WORKDIR /app
COPY tools/docker/images/nginx/root /
{% endif %}

20
templates/default.conf Normal file
View file

@ -0,0 +1,20 @@
server {
server_name _;
root /app/web;
location / {
try_files $uri /index.php?$query_string;
}
location ~ \.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
try_files $fastcgi_script_name =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param QUERY_STRING $query_string;
fastcgi_intercept_errors on;
fastcgi_pass php:9000;
}
}

View file

@ -0,0 +1,65 @@
x-app: &default-app
volumes:
- "${DOCKER_WEB_VOLUME:-./web:/app/web}"
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:
web:
<<: *default-app
build:
context: .
target: web
depends_on:
- php
networks:
- default
- web
labels:
- "traefik.docker.network=traefik_proxy"
- "traefik.http.routers.${COMPOSE_PROJECT_NAME}.rule=Host(`${COMPOSE_PROJECT_NAME}.localhost`)"
profiles: [web]
php:
<<: *default-app
build:
context: .
target: {{ dockerCompose.services.php.build.target }}
depends_on:
- database
profiles: [php]
database:
image: mariadb:10
deploy:
resources:
limits:
cpus: "${DOCKER_MYSQL_CPUS:-0}"
memory: "${DOCKER_MYSQL_MEMORY:-0}"
volumes:
- db-data:/var/lib/mysql
env_file:
- .env
labels:
- "traefik.enabled=false"
environment:
MYSQL_RANDOM_ROOT_PASSWORD: true
profiles: [database]
volumes:
db-data: {}
networks:
web:
name: traefik_proxy

View file

@ -0,0 +1,6 @@
{% if dockerCompose %}
export COMPOSE_PROJECT_NAME={{ name }}
export COMPOSE_PROFILES=web,php,database
export DOCKER_WEB_VOLUME=.:/app
{% endif %}

7
templates/phpcs.xml.twig Normal file
View file

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<ruleset name="{{ name }} coding standards">
<description>PHPCS configuration file for {{ name }}.</description>
<file>src</file>
<arg value="np"/>
<rule ref="{{ php.phpcs.standard }}"/>
</ruleset>

View file

@ -0,0 +1,6 @@
parameters:
level: {{ php.phpstan.level }}
paths:
{% for path in php.phpstan.paths | default(["src"]) -%}
- {{ path }}
{% endfor %}

View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>