Some more changes for Docker
This commit is contained in:
+29
-4
@@ -15,6 +15,14 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
- wkvs
|
- wkvs
|
||||||
|
|
||||||
|
env-init:
|
||||||
|
build: ./config/apache
|
||||||
|
container_name: wkvs-env-init
|
||||||
|
volumes:
|
||||||
|
- .:/var/wkvs
|
||||||
|
working_dir: /var/wkvs
|
||||||
|
command: php setup/init-env.php
|
||||||
|
|
||||||
composer-init:
|
composer-init:
|
||||||
image: composer:latest
|
image: composer:latest
|
||||||
container_name: wkvs-composer-init
|
container_name: wkvs-composer-init
|
||||||
@@ -22,6 +30,9 @@ services:
|
|||||||
- .:/app
|
- .:/app
|
||||||
working_dir: /app/composer
|
working_dir: /app/composer
|
||||||
command: composer install --no-interaction --prefer-dist
|
command: composer install --no-interaction --prefer-dist
|
||||||
|
depends_on:
|
||||||
|
env-init:
|
||||||
|
condition: service_completed_successfully
|
||||||
|
|
||||||
apache:
|
apache:
|
||||||
build: ./config/apache
|
build: ./config/apache
|
||||||
@@ -42,7 +53,8 @@ services:
|
|||||||
container_name: wkvs-mariadb
|
container_name: wkvs-mariadb
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
env_file:
|
env_file:
|
||||||
- ./config/.env.db
|
- path: ./config/.env.db
|
||||||
|
required: false
|
||||||
volumes:
|
volumes:
|
||||||
- db_data:/var/lib/mysql
|
- db_data:/var/lib/mysql
|
||||||
healthcheck:
|
healthcheck:
|
||||||
@@ -50,6 +62,9 @@ services:
|
|||||||
interval: 5s
|
interval: 5s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
retries: 5
|
||||||
|
depends_on:
|
||||||
|
env-init:
|
||||||
|
condition: service_completed_successfully
|
||||||
networks:
|
networks:
|
||||||
- wkvs
|
- wkvs
|
||||||
|
|
||||||
@@ -62,6 +77,8 @@ services:
|
|||||||
depends_on:
|
depends_on:
|
||||||
mariadb:
|
mariadb:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
|
env-init:
|
||||||
|
condition: service_completed_successfully
|
||||||
networks:
|
networks:
|
||||||
- wkvs
|
- wkvs
|
||||||
command: php setup/database/init-db.php
|
command: php setup/database/init-db.php
|
||||||
@@ -71,8 +88,12 @@ services:
|
|||||||
container_name: wkvs-redis
|
container_name: wkvs-redis
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
env_file:
|
env_file:
|
||||||
- ./config/.env.redis
|
- path: ./config/.env.redis
|
||||||
|
required: false
|
||||||
command: ["sh", "-c", "exec redis-server --requirepass \"$REDDIS_PASSWORD\""]
|
command: ["sh", "-c", "exec redis-server --requirepass \"$REDDIS_PASSWORD\""]
|
||||||
|
depends_on:
|
||||||
|
env-init:
|
||||||
|
condition: service_completed_successfully
|
||||||
networks:
|
networks:
|
||||||
- wkvs
|
- wkvs
|
||||||
|
|
||||||
@@ -84,12 +105,16 @@ services:
|
|||||||
- .:/var/wkvs
|
- .:/var/wkvs
|
||||||
working_dir: /var/wkvs/websocket
|
working_dir: /var/wkvs/websocket
|
||||||
env_file:
|
env_file:
|
||||||
- ./config/.env.redis
|
- path: ./config/.env.redis
|
||||||
|
required: false
|
||||||
environment:
|
environment:
|
||||||
- REDDIS_HOST=redis
|
- REDDIS_HOST=redis
|
||||||
command: sh -c "npm install && npm install -g pm2 && pm2-runtime start index.js --max-memory-restart 1G --node-args=\"--max-old-space-size=1024\" --name=\"WebSocket WKVS\""
|
command: sh -c "npm install && npm install -g pm2 && pm2-runtime start index.js --max-memory-restart 1G --node-args=\"--max-old-space-size=1024\" --name=\"WebSocket WKVS\""
|
||||||
depends_on:
|
depends_on:
|
||||||
- redis
|
redis:
|
||||||
|
condition: service_started
|
||||||
|
env-init:
|
||||||
|
condition: service_completed_successfully
|
||||||
networks:
|
networks:
|
||||||
- wkvs
|
- wkvs
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WKVS Automated Environment Initialization Script
|
||||||
|
* Auto-creates missing config/.env files from .example templates
|
||||||
|
* and configures them with valid Docker container hostnames and default dev credentials.
|
||||||
|
*/
|
||||||
|
|
||||||
|
$configDir = dirname(__DIR__) . '/config';
|
||||||
|
|
||||||
|
$envMappings = [
|
||||||
|
'env.redis' => [
|
||||||
|
'example' => 'env.redis.example',
|
||||||
|
'replacements' => [
|
||||||
|
'/REDDIS_HOST=127\.0\.0\.1/' => 'REDDIS_HOST=redis',
|
||||||
|
'/REDDIS_HOST=localhost/' => 'REDDIS_HOST=redis',
|
||||||
|
'/REDDIS_HOST=YOUR_REDDIS_IP.*/' => 'REDDIS_HOST=redis',
|
||||||
|
'/REDDIS_PORT=YOUR_REDDIS_PORT.*/' => 'REDDIS_PORT=6379',
|
||||||
|
'/YOUR_REDDIS_PASSWORD/' => base64_encode(random_bytes(64)),
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'env.db' => [
|
||||||
|
'example' => 'env.db.example',
|
||||||
|
'replacements' => [
|
||||||
|
'/MYSQL_HOST=localhost/' => 'MYSQL_HOST=mariadb',
|
||||||
|
'/MYSQL_HOST=127\.0\.0\.1/' => 'MYSQL_HOST=mariadb',
|
||||||
|
'/YOUR_PASSWORD_FOR_ROOT/' => base64_encode(random_bytes(64)),
|
||||||
|
'/YOUR_DATABASE_NAME/' => 'devdb_',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'env.db-tables' => [
|
||||||
|
'example' => 'env.db-tables.example',
|
||||||
|
'replacements' => [
|
||||||
|
'/DB_PREFIX=PREFIX/' => 'DB_PREFIX=wkvs_',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'env.pw-encryption-key' => [
|
||||||
|
'example' => 'env.pw-encryption-key.example',
|
||||||
|
'replacements' => [
|
||||||
|
'/YOUR_CUSTOM_PASSWORD_ENCRYPTION_KEY/' => base64_encode(random_bytes(64)),
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'env.wk-id' => [
|
||||||
|
'example' => 'env.wk-id.example',
|
||||||
|
'replacements' => []
|
||||||
|
],
|
||||||
|
'env.db-wkvs-user' => [
|
||||||
|
'example' => 'env.db-wkvs-user.example',
|
||||||
|
'replacements' => [
|
||||||
|
'/DB_HOST=localhost/' => 'DB_HOST=mariadb',
|
||||||
|
'/DB_HOST=127\.0\.0\.1/' => 'DB_HOST=mariadb',
|
||||||
|
'/DATABASE_NAME/' => 'devdb_',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'env.db-guest' => [
|
||||||
|
'example' => 'env.db-guest.example',
|
||||||
|
'replacements' => [
|
||||||
|
'/DB_HOST=localhost/' => 'DB_HOST=mariadb',
|
||||||
|
'/DB_HOST=127\.0\.0\.1/' => 'DB_HOST=mariadb',
|
||||||
|
'/DATABASE_NAME/' => 'devdb_',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
echo "========================================\n";
|
||||||
|
echo " WKVS Environment Initializer \n";
|
||||||
|
echo "========================================\n\n";
|
||||||
|
|
||||||
|
foreach ($envMappings as $targetName => $config) {
|
||||||
|
$targetPath = $configDir . '/.' . $targetName;
|
||||||
|
$examplePath = $configDir . '/.' . $config['example'];
|
||||||
|
|
||||||
|
if (!file_exists($targetPath)) {
|
||||||
|
if (file_exists($examplePath)) {
|
||||||
|
echo "Creating missing ." . $targetName . " from ." . $config['example'] . "...\n";
|
||||||
|
$content = file_get_contents($examplePath);
|
||||||
|
foreach ($config['replacements'] as $pattern => $replacement) {
|
||||||
|
$content = preg_replace($pattern, $replacement, $content);
|
||||||
|
}
|
||||||
|
file_put_contents($targetPath, $content);
|
||||||
|
} else {
|
||||||
|
echo "⚠️ Warning: Example file ." . $config['example'] . " not found.\n";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo "Skipping ." . $targetName . " (file already exists).\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "✓ Environment initialization complete.\n\n";
|
||||||
Reference in New Issue
Block a user