Add basic database support with default integrated sqlite3 install
This commit is contained in:
parent
df4fdbde3c
commit
7f2fb2bbf3
9 changed files with 61 additions and 5 deletions
|
@ -15,7 +15,7 @@ RUN apt-get -qq update && apt-get -qq install -y \
|
||||||
> /dev/null 2>&1
|
> /dev/null 2>&1
|
||||||
|
|
||||||
RUN docker-php-ext-configure intl > /dev/null 2>&1
|
RUN docker-php-ext-configure intl > /dev/null 2>&1
|
||||||
RUN docker-php-ext-install mysqli pdo pdo_mysql sockets intl exif bcmath > /dev/null
|
RUN docker-php-ext-install sockets intl exif bcmath > /dev/null 2>&1
|
||||||
RUN docker-php-ext-install opcache > /dev/null 2>&1
|
RUN docker-php-ext-install opcache > /dev/null 2>&1
|
||||||
COPY ./opcache.ini "${PHP_INI_DIR}/conf.d"
|
COPY ./opcache.ini "${PHP_INI_DIR}/conf.d"
|
||||||
|
|
||||||
|
|
4
config/php-fpm/Sqlite.Dockerfile
Normal file
4
config/php-fpm/Sqlite.Dockerfile
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
RUN mkdir -p /var/www/html/sqlite \
|
||||||
|
&& chown www-data:www-data /var/www/html/sqlite
|
||||||
|
|
||||||
|
RUN apt-get install sqlite3
|
|
@ -7,8 +7,8 @@ services:
|
||||||
working_dir: /var/www/html
|
working_dir: /var/www/html
|
||||||
extra_hosts:
|
extra_hosts:
|
||||||
- host.docker.internal:host-gateway
|
- host.docker.internal:host-gateway
|
||||||
volumes:
|
|
||||||
- ${PROJECT_DIRECTORY}:/var/www/html:cached
|
|
||||||
ports:
|
ports:
|
||||||
- ${PHP_PORT}:9003
|
- ${PHP_PORT}:9003
|
||||||
container_name: ${PROJECT_NAME}-php
|
container_name: ${PROJECT_NAME}-php
|
||||||
|
volumes:
|
||||||
|
- ${PROJECT_DIRECTORY}:/var/www/html:cached
|
|
@ -8,3 +8,6 @@ options:
|
||||||
version: 23
|
version: 23
|
||||||
server:
|
server:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
database:
|
||||||
|
enabled: true
|
||||||
|
driver: sqlite3
|
2
config/sqlite.yaml
Normal file
2
config/sqlite.yaml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
volumes:
|
||||||
|
- ${PROJECT_DIRECTORY}/sqlite:/var/www/html/sqlite:cached
|
|
@ -83,6 +83,30 @@ class Config
|
||||||
return $this->getEnvironmentOption('php', 'xdebug');
|
return $this->getEnvironmentOption('php', 'xdebug');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function isDatabaseEnabled(InputInterface $input): bool
|
||||||
|
{
|
||||||
|
if ($input->getOption('disable-database')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->getEnvironmentOption('database', 'enabled');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function getDatabaseDriver(InputInterface $input): ?string
|
||||||
|
{
|
||||||
|
if ($input->getOption('database')) {
|
||||||
|
return (string) $input->getOption('database');
|
||||||
|
}
|
||||||
|
|
||||||
|
return (string) $this->getEnvironmentOption('database', 'driver');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -32,6 +32,10 @@ class DockerComposeFileBuilder extends AbstractFileBuilder
|
||||||
$this->config->getFilePaths()->get('phpYamlTemplate')->getAbsolutePath()
|
$this->config->getFilePaths()->get('phpYamlTemplate')->getAbsolutePath()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($this->config->isDatabaseEnabled($input) && in_array($this->config->getDatabaseDriver($input), ['sqlite3', 'sqlite'])) {
|
||||||
|
$this->addSqliteDatabaseConfig();
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->config->isServerEnabled($input)) {
|
if ($this->config->isServerEnabled($input)) {
|
||||||
$this->addNginxConfig();
|
$this->addNginxConfig();
|
||||||
}
|
}
|
||||||
|
@ -54,4 +58,11 @@ class DockerComposeFileBuilder extends AbstractFileBuilder
|
||||||
$this->content
|
$this->content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function addSqliteDatabaseConfig(): void
|
||||||
|
{
|
||||||
|
$sqlLiteConfig = file_get_contents((new SpinnerFilePath('config/sqlite.yaml'))->getAbsolutePath());
|
||||||
|
$sqlLiteConfig = str_replace('volumes:', '', $sqlLiteConfig);
|
||||||
|
$this->content .= $sqlLiteConfig;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -38,6 +38,11 @@ class PHPDockerFileBuilder extends AbstractFileBuilder
|
||||||
file_get_contents($this->config->getFilePaths()->get('opcacheIniTemplate')->getAbsolutePath())
|
file_get_contents($this->config->getFilePaths()->get('opcacheIniTemplate')->getAbsolutePath())
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($this->config->isDatabaseEnabled($input) && in_array($this->config->getDatabaseDriver($input), ['sqlite3', 'sqlite'])) {
|
||||||
|
$this->addNewLine();
|
||||||
|
$this->content .= file_get_contents((new SpinnerFilePath('config/php-fpm/Sqlite.Dockerfile'))->getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->config->isNodeEnabled($input)) {
|
if ($this->config->isNodeEnabled($input)) {
|
||||||
$this->addNewLine();
|
$this->addNewLine();
|
||||||
$this->content .= file_get_contents($this->config->getFilePaths()->get('nodeDockerfileTemplate')->getAbsolutePath());
|
$this->content .= file_get_contents($this->config->getFilePaths()->get('nodeDockerfileTemplate')->getAbsolutePath());
|
||||||
|
|
|
@ -65,6 +65,13 @@ class SpinCommand extends AbstractSpinnerCommand
|
||||||
InputOption::VALUE_NONE,
|
InputOption::VALUE_NONE,
|
||||||
'Set this flag to disable XDebug for your environment.'
|
'Set this flag to disable XDebug for your environment.'
|
||||||
)
|
)
|
||||||
|
->addOption(
|
||||||
|
'disable-database',
|
||||||
|
null,
|
||||||
|
InputOption::VALUE_NONE,
|
||||||
|
'Set this flag to not include a database for your environment.'
|
||||||
|
)
|
||||||
|
->addOption('database', null, InputOption::VALUE_REQUIRED, 'The type of database to use (e.g., mysql, postgresql, sqlite).', null, ['sqlite'])
|
||||||
->addOption('node', null, InputOption::VALUE_OPTIONAL, 'The Node.js version to use (e.g. 20).');
|
->addOption('node', null, InputOption::VALUE_OPTIONAL, 'The Node.js version to use (e.g. 20).');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue