Add MySQL and make it the default database
This commit is contained in:
parent
be5d6a9e4c
commit
62e0320413
7 changed files with 50 additions and 12 deletions
|
@ -7,4 +7,8 @@ PHP_VERSION=%s
|
||||||
PHP_PORT=%s
|
PHP_PORT=%s
|
||||||
|
|
||||||
# Nginx
|
# Nginx
|
||||||
NGINX_PORT=%s
|
SERVER_PORT=%s
|
||||||
|
|
||||||
|
# Database
|
||||||
|
DATABASE_PORT=%s
|
||||||
|
ROOT_PASSWORD=%s
|
12
config/mysql.yaml
Normal file
12
config/mysql.yaml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
services:
|
||||||
|
mysql:
|
||||||
|
image: mysql:9.3.0
|
||||||
|
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci
|
||||||
|
ports:
|
||||||
|
- ${DATABASE_PORT}:3306
|
||||||
|
expose:
|
||||||
|
- "3306"
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: ${ROOT_PASSWORD}
|
||||||
|
volumes:
|
||||||
|
- ./data/${PROJECT_NAME}/mysql:/var/lib/mysql:cached
|
|
@ -3,7 +3,7 @@ services:
|
||||||
build:
|
build:
|
||||||
context: ./nginx
|
context: ./nginx
|
||||||
ports:
|
ports:
|
||||||
- ${NGINX_PORT}:80
|
- ${SERVER_PORT}:80
|
||||||
volumes:
|
volumes:
|
||||||
- ${PROJECT_DIRECTORY}:/var/www/html:cached
|
- ${PROJECT_DIRECTORY}:/var/www/html:cached
|
||||||
- ./nginx/conf.d:/etc/nginx/conf.d
|
- ./nginx/conf.d:/etc/nginx/conf.d
|
||||||
|
|
|
@ -9,4 +9,5 @@ options:
|
||||||
enabled: true
|
enabled: true
|
||||||
database:
|
database:
|
||||||
enabled: true
|
enabled: true
|
||||||
driver: sqlite3
|
driver: sqlite3
|
||||||
|
rootPassword: docker
|
|
@ -13,7 +13,7 @@ class DockerComposeFileBuilder extends AbstractFileBuilder
|
||||||
/**
|
/**
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function __construct(Config $config)
|
public function __construct(Config $config, private array $ports)
|
||||||
{
|
{
|
||||||
return parent::__construct($config->getDataDirectory() . '/docker-compose.yaml', $config);
|
return parent::__construct($config->getDataDirectory() . '/docker-compose.yaml', $config);
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,16 @@ class DockerComposeFileBuilder extends AbstractFileBuilder
|
||||||
{
|
{
|
||||||
$this->content = $this->config->getConfigFileContents('php.yaml');
|
$this->content = $this->config->getConfigFileContents('php.yaml');
|
||||||
|
|
||||||
if ($this->config->isDatabaseEnabled($input) && in_array($this->config->getDatabaseDriver($input), ['sqlite3', 'sqlite'])) {
|
if ($this->config->isDatabaseEnabled($input)) {
|
||||||
$this->addSqliteDatabaseConfig();
|
$databaseDriver = strtolower($this->config->getDatabaseDriver($input));
|
||||||
|
|
||||||
|
if (in_array($databaseDriver, ['sqlite3', 'sqlite'])) {
|
||||||
|
$this->addSqliteDatabaseConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($databaseDriver === 'mysql') {
|
||||||
|
$this->addMysqlDatabaseConfig();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->config->isServerEnabled($input)) {
|
if ($this->config->isServerEnabled($input)) {
|
||||||
|
@ -56,4 +64,12 @@ class DockerComposeFileBuilder extends AbstractFileBuilder
|
||||||
$sqlLiteConfig = str_replace('volumes:', '', $sqlLiteConfig);
|
$sqlLiteConfig = str_replace('volumes:', '', $sqlLiteConfig);
|
||||||
$this->content .= $sqlLiteConfig;
|
$this->content .= $sqlLiteConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function addMysqlDatabaseConfig(): void
|
||||||
|
{
|
||||||
|
$mysqlConfig = str_replace('services:', '', $this->config->getConfigFileContents('mysql.yaml'));
|
||||||
|
$mysqlConfig = str_replace('${ROOT_PASSWORD}', $this->config->getEnvironmentOption('database', 'rootPassword'), $mysqlConfig);
|
||||||
|
$mysqlConfig = str_replace('${DATABASE_PORT}', (string) $this->ports['database'], $mysqlConfig);
|
||||||
|
$this->content.= $mysqlConfig;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -31,9 +31,11 @@ class PHPDockerFileBuilder extends AbstractFileBuilder
|
||||||
$this->config->getConfigFileContents('php-fpm/opcache.ini')
|
$this->config->getConfigFileContents('php-fpm/opcache.ini')
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($this->config->isDatabaseEnabled($input) && in_array($this->config->getDatabaseDriver($input), ['sqlite3', 'sqlite'])) {
|
if ($this->config->isDatabaseEnabled($input)) {
|
||||||
$this->addNewLine();
|
if (in_array($this->config->getDatabaseDriver($input), ['sqlite3', 'sqlite'])) {
|
||||||
$this->content .= $this->config->getConfigFileContents('php-fpm/Sqlite.Dockerfile');
|
$this->addNewLine();
|
||||||
|
$this->content .= $this->config->getConfigFileContents('php-fpm/Sqlite.Dockerfile');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->content = str_replace('${NODE_VERSION}', (string) $this->config->getNodeVersion($input), $this->content);
|
$this->content = str_replace('${NODE_VERSION}', (string) $this->config->getNodeVersion($input), $this->content);
|
||||||
|
|
|
@ -28,7 +28,8 @@ class SpinCommand extends AbstractSpinnerCommand
|
||||||
$this->portGenerator = new PortGenerator();
|
$this->portGenerator = new PortGenerator();
|
||||||
$this->ports = [
|
$this->ports = [
|
||||||
'php' => $this->portGenerator->generateRandomPort(),
|
'php' => $this->portGenerator->generateRandomPort(),
|
||||||
'nginx' => $this->portGenerator->generateRandomPort(),
|
'server' => $this->portGenerator->generateRandomPort(),
|
||||||
|
'database' => $this->portGenerator->generateRandomPort(),
|
||||||
];
|
];
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
@ -154,7 +155,9 @@ class SpinCommand extends AbstractSpinnerCommand
|
||||||
$input->getArgument('name'),
|
$input->getArgument('name'),
|
||||||
$this->config->getPhpVersion($input),
|
$this->config->getPhpVersion($input),
|
||||||
$this->ports['php'],
|
$this->ports['php'],
|
||||||
$this->ports['nginx'],
|
$this->ports['server'],
|
||||||
|
$this->ports['database'],
|
||||||
|
$this->config->getEnvironmentOption('database', 'rootPassword')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -166,7 +169,7 @@ class SpinCommand extends AbstractSpinnerCommand
|
||||||
{
|
{
|
||||||
$this->createProjectDataSubDirectory('php-fpm');
|
$this->createProjectDataSubDirectory('php-fpm');
|
||||||
|
|
||||||
(new DockerComposeFileBuilder($this->config))->build($input)->save();
|
(new DockerComposeFileBuilder($this->config, $this->ports))->build($input)->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue