mirror of
https://github.com/opdavies/build-configs.git
synced 2025-01-22 18:27:31 +00:00
parent
a179f1b0ee
commit
b4b289748a
|
@ -101,6 +101,11 @@ final class BuildConfigurationCommand extends Command
|
|||
$this->filesToGenerate->push(['php/docker-entrypoint-php', 'tools/docker/images/php/root/usr/local/bin/docker-entrypoint-php']);
|
||||
}
|
||||
|
||||
if (self::isNode(Arr::get($configurationData, 'language'))) {
|
||||
$this->filesToGenerate->push(['node/.yarnrc', '.yarnrc']);
|
||||
$this->filesToGenerate->push(['node/Dockerfile', 'Dockerfile']);
|
||||
}
|
||||
|
||||
if (self::isCaddy(Arr::get($configurationData, 'web.type'))) {
|
||||
$this->filesystem->mkdir("{$this->outputDir}/tools/docker/images/web/root/etc/caddy");
|
||||
$this->filesToGenerate->push(['web/caddy/Caddyfile', 'tools/docker/images/web/root/etc/caddy/Caddyfile']);
|
||||
|
@ -166,6 +171,15 @@ final class BuildConfigurationCommand extends Command
|
|||
return strtoupper($webServer) === WebServer::NGINX->name;
|
||||
}
|
||||
|
||||
private static function isNode(?string $language): bool
|
||||
{
|
||||
if (is_null($language)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return strtoupper($language) === Language::NODE->name;
|
||||
}
|
||||
|
||||
private static function isPhp(?string $language): bool
|
||||
{
|
||||
if (is_null($language)) {
|
||||
|
|
|
@ -6,5 +6,6 @@ namespace OliverDaviesLtd\BuildConfigs\Enum;
|
|||
|
||||
enum Language
|
||||
{
|
||||
case NODE;
|
||||
case PHP;
|
||||
}
|
||||
|
|
|
@ -28,13 +28,20 @@ final class ConfigurationValidator implements ValidatorInterface
|
|||
'language' => [
|
||||
new Assert\NotNull(),
|
||||
new Assert\Type('string'),
|
||||
new Assert\Choice(['node', 'php']),
|
||||
new Assert\Choice([
|
||||
'node',
|
||||
'php',
|
||||
]),
|
||||
],
|
||||
|
||||
'type' => [
|
||||
new Assert\NotNull(),
|
||||
new Assert\Type('string'),
|
||||
new Assert\Choice(['drupal-project', 'fractal', 'php-library']),
|
||||
new Assert\Choice([
|
||||
'drupal-project',
|
||||
'fractal',
|
||||
'php-library',
|
||||
]),
|
||||
],
|
||||
|
||||
'project_root' => [
|
||||
|
@ -53,6 +60,8 @@ final class ConfigurationValidator implements ValidatorInterface
|
|||
// TODO: this should be a boolean if present.
|
||||
'justfile' => new Assert\Optional(),
|
||||
|
||||
'node' => new Assert\Optional(),
|
||||
|
||||
'php' => new Assert\Optional(),
|
||||
|
||||
'web' => new Assert\Optional(),
|
||||
|
|
|
@ -40,6 +40,7 @@ services:
|
|||
profiles: [web]
|
||||
{% endif %}
|
||||
|
||||
{% if "php" == language %}
|
||||
php:
|
||||
<<: *default-app
|
||||
build:
|
||||
|
@ -52,6 +53,20 @@ services:
|
|||
- database
|
||||
{% endif -%}
|
||||
profiles: [php]
|
||||
{% elseif "node" == language %}
|
||||
node:
|
||||
<<: *default-app
|
||||
build:
|
||||
context: .
|
||||
target: build
|
||||
volumes:
|
||||
- .:{{ project_root }}
|
||||
{% if "database" in dockerCompose.services|keys -%}
|
||||
depends_on:
|
||||
- database
|
||||
{% endif -%}
|
||||
profiles: [node]
|
||||
{% endif %}
|
||||
|
||||
{% if "database" in dockerCompose.services|keys %}
|
||||
database:
|
||||
|
|
|
@ -4,7 +4,11 @@ export DOCKER_UID=1000
|
|||
|
||||
{% if dockerCompose %}
|
||||
export COMPOSE_PROJECT_NAME={{ name }}
|
||||
{% if "php" == language %}
|
||||
export COMPOSE_PROFILES=web,php,database
|
||||
{% elseif "node" == language %}
|
||||
export COMPOSE_PROFILES=node
|
||||
{% endif %}
|
||||
|
||||
export DOCKER_WEB_VOLUME=.:{{ project_root }}
|
||||
{% endif %}
|
||||
|
|
3
templates/node/.yarnrc.twig
Normal file
3
templates/node/.yarnrc.twig
Normal file
|
@ -0,0 +1,3 @@
|
|||
# {{ managedText | raw }}
|
||||
|
||||
--modules-folder /node_modules
|
20
templates/node/Dockerfile.twig
Normal file
20
templates/node/Dockerfile.twig
Normal file
|
@ -0,0 +1,20 @@
|
|||
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"]
|
Loading…
Reference in a new issue