diff --git a/src/Console/Command/BuildConfigurationCommand.php b/src/Console/Command/BuildConfigurationCommand.php
index 253039c..f431bbc 100644
--- a/src/Console/Command/BuildConfigurationCommand.php
+++ b/src/Console/Command/BuildConfigurationCommand.php
@@ -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;
diff --git a/templates/Dockerfile.twig b/templates/Dockerfile.twig
new file mode 100644
index 0000000..4a54e84
--- /dev/null
+++ b/templates/Dockerfile.twig
@@ -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 %}
diff --git a/templates/default.conf b/templates/default.conf
new file mode 100644
index 0000000..b032e23
--- /dev/null
+++ b/templates/default.conf
@@ -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;
+ }
+}
diff --git a/templates/docker-compose.yaml.twig b/templates/docker-compose.yaml.twig
new file mode 100644
index 0000000..8ba3ae8
--- /dev/null
+++ b/templates/docker-compose.yaml.twig
@@ -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
diff --git a/templates/env.example.twig b/templates/env.example.twig
new file mode 100644
index 0000000..60eb883
--- /dev/null
+++ b/templates/env.example.twig
@@ -0,0 +1,6 @@
+{% if dockerCompose %}
+export COMPOSE_PROJECT_NAME={{ name }}
+export COMPOSE_PROFILES=web,php,database
+
+export DOCKER_WEB_VOLUME=.:/app
+{% endif %}
diff --git a/templates/phpcs.xml.twig b/templates/phpcs.xml.twig
new file mode 100644
index 0000000..ec86f35
--- /dev/null
+++ b/templates/phpcs.xml.twig
@@ -0,0 +1,7 @@
+
+
+ PHPCS configuration file for {{ name }}.
+ src
+
+
+
diff --git a/templates/phpstan.neon.twig b/templates/phpstan.neon.twig
new file mode 100644
index 0000000..303bd69
--- /dev/null
+++ b/templates/phpstan.neon.twig
@@ -0,0 +1,6 @@
+parameters:
+ level: {{ php.phpstan.level }}
+ paths:
+ {% for path in php.phpstan.paths | default(["src"]) -%}
+ - {{ path }}
+ {% endfor %}
diff --git a/templates/phpunit.xml.twig b/templates/phpunit.xml.twig
new file mode 100644
index 0000000..de47e44
--- /dev/null
+++ b/templates/phpunit.xml.twig
@@ -0,0 +1,20 @@
+
+
+
+
+ tests
+
+
+