]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6693 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 30 Jan 2024 07:38:40 +0000 (08:38 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 30 Jan 2024 07:38:40 +0000 (08:38 +0100)
app/Http/Controllers/Admin/Operations/Tools/DockerWebContainer.php
resources/tools/dockerwebcontainer/template/www/.env

index ce49c0bd14a58147e7573aa3e8bc7bbb8e768d94..14e5922d15bfab4f619bd3b967abf459189dec08 100644 (file)
@@ -10,10 +10,14 @@ use Cubist\Backpack\Magic\Fields\SelectFromArrayMultiple;
 use Cubist\Backpack\Magic\Fields\Tags;
 use Cubist\Backpack\Magic\Fields\Text;
 use Cubist\Backpack\Magic\Form;
+use Cubist\Util\Env;
 use Cubist\Util\Files\Files;
 use Cubist\Util\Str;
 use Cubist\Util\Zip;
+use Dotenv\Dotenv;
+use Illuminate\Support\Facades\Artisan;
 use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions\F;
+use Symfony\Component\Console\Output\BufferedOutput;
 
 // __('!! Outils')
 trait DockerWebContainer
@@ -29,8 +33,9 @@ trait DockerWebContainer
         $form->addField('containername', Text::class, __('Nom du container'), ['prefix' => '/docker/']);
         $form->addField('domain', Text::class, __('Nom du domaine ou sous-domaine'), ['placeholder' => 'containername.dev.cubedesigners.com']);
         $form->addField('env', SelectFromArrayMultiple::class, __('Environnements'), ['default' => json_encode(['production', 'dev']), 'options' => ['production' => 'production', 'dev' => 'dev', 'staging' => 'staging', 'preprod' => 'preprod']]);
-        $form->addField('public', Checkbox::class, __('Racine dans le dossier "public"'), ['default' => true]);
+
         $form->addField('laravel', Checkbox::class, __('Installer Laravel'), ['default' => true]);
+        $form->addField('public', Checkbox::class, __('Racine dans le dossier "public"'), ['default' => true]);
         $form->addField('phpversion', SelectFromArray::class, __('Version de PHP'), ["options" =>
             ['none' => '-',
                 '5.6' => '5.6',
@@ -68,6 +73,8 @@ trait DockerWebContainer
                 $subDomain = '';
             }
 
+            $laravel = $request->get('laravel', true);
+
             $variables = ['$name' => $name . $dockerSuffix,
                 '$matomodbpassword' => Str::random(16),
                 '$sshport' => rand(10000, 60000),
@@ -77,7 +84,8 @@ trait DockerWebContainer
                 '$locale' => 'fr_FR',
                 '$localeshort' => 'fr',
                 '$sshpassword' => Str::random(16),
-                '$public' => $request->get('public') ? '/public' : '/'
+                '$public' => ($laravel || $request->get('public')) ? '/public' : '/',
+                '$environment' => $env,
             ];
 
             if (!$variables['$domain']) {
@@ -90,6 +98,8 @@ trait DockerWebContainer
             $source = resource_path('tools/dockerwebcontainer/template');
             `cp -r $source/* $dir/`;
 
+            $additionalEnv = [];
+
             $compose = ['base'];
             $variables['$phpversion'] = $request->get('phpversion', '8.3');
             if ($variables['$phpversion'] !== 'none') {
@@ -99,13 +109,23 @@ trait DockerWebContainer
                 }
                 $fixRights[] = 'chown 0:0 ./config/cron/crontab';
             }
-            if ($request->get('mysql', true)) {
+            if ($laravel || $request->get('mysql', true)) {
                 $compose[] = 'mysql';
                 $fixRights[] = 'chown -R 999:999 ./database/data';
+
+                $additionalEnv['DB_CONNECTION']='mysql';
+                $additionalEnv['DB_HOST']='$name-mariadb';
+                $additionalEnv['DB_PORT']='3306';
+                $additionalEnv['DB_DATABASE']='$name';
+                $additionalEnv['DB_USERNAME']='root';
+                $additionalEnv['DB_PASSWORD']='$dbpassword';
             }
-            if ($request->get('redis', true)) {
+            if ($laravel || $request->get('redis', true)) {
                 $compose[] = 'redis';
                 $fixRights[] = 'chown -R 999:999 ./redis';
+                $additionalEnv['CACHE_DRIVER'] = 'redis';
+                $additionalEnv['SESSION_DRIVER'] = 'redis';
+                $additionalEnv['REDIS_HOST'] = '$name-redis';
             }
             if ($request->get('matomo', true)) {
                 $compose[] = 'matomo';
@@ -116,6 +136,8 @@ trait DockerWebContainer
             }
 
             if ($request->get('laravel', true)) {
+                $envPath = $dir . '/www/.env';
+                $env = Dotenv::parse(file_get_contents($envPath));
                 `rm -rf $dir/www;composer create-project laravel/laravel $dir/www`;
                 $composerFile = $dir . '/www/composer.json';
                 $composer = json_decode(file_get_contents($composerFile));
@@ -132,6 +154,12 @@ trait DockerWebContainer
                 file_put_contents($composerFile, json_encode($composer));
                 copy(base_path() . '/auth.json', $dir . '/www/auth.json');
                 `rm -rf $dir/www/vendor`;
+                $laravelEnv = Dotenv::parse(file_get_contents($envPath));
+                $laravelEnv = array_merge($laravelEnv, $env, $additionalEnv);
+                $output = new BufferedOutput();
+                Artisan::call('key:generate --show', [], $output);
+                $laravelEnv['APP_KEY'] = trim($output->fetch());
+                Env::arrayToEnvFile($envPath, $laravelEnv);
             }
 
             $variables['$fixrights'] = implode("\n", $fixRights);
index 8cdfff1e398f815036999f21962fb92892d30779..66ae0e6528c3a69f92fd84f89b521845b322bc2b 100644 (file)
@@ -1,6 +1,26 @@
-DB_CONNECTION=mysql
-DB_HOST=$name-mariadb
-DB_PORT=3306
-DB_DATABASE=$name
-DB_USERNAME=root
-DB_PASSWORD=$dbpassword
+APP_NAME=$name
+APP_ENV=$environment
+APP_KEY=
+APP_DEBUG=true
+APP_URL=https://$domain
+
+DEBUGBAR_ENABLED=true
+DEBUGBAR_OPEN_STORAGE=true
+
+MAIL_HOST=mail2.cubedesigners.com
+MAIL_PORT=587
+MAIL_USERNAME=external@cubedesigners.com
+MAIL_PASSWORD=z6hfYZJEfFZp48pza3
+MAIL_ENCRYPTION=tls
+MAIL_FROM_ADDRESS=external@cubedesigners.com
+MAIL_FROM_NAME="$name"
+MAIL_BCC_ALL=test+$name@cubedesigners.com
+
+QUEUE_CONNECTION=database
+
+SESSION_LIFETIME=1200
+
+BACKPACK_LOCALES=en,fr
+TIMEZONE=Europe/Paris
+
+POWERED_BY_LINK=https://www.cubedesigners.com/