Skip to content

A self-hosted media server and file management system

generate reverb keys in external env

aminnausin437a9fe2d605
diff --git a/.github/workflows/build-beta.yml b/.github/workflows/build-beta.yml
index 7ed38de5..e7300c76 100644
--- a/.github/workflows/build-beta.yml
+++ b/.github/workflows/build-beta.yml
@@ -37,11 +37,11 @@ jobs:
- name: Zip Files Linux
run: |
- zip -r mediaServerDockerLinux.zip ./docker ./docker-compose.yaml ./startDocker.sh ./README.md
+ zip -r mediaServerDockerLinux.zip ./docker/etc ./docker/.env.docker ./docker-compose.yaml ./startDocker.sh ./README.md
- name: Zip Files Windows
run: |
- zip -r mediaServerDockerWindows.zip ./docker ./docker-compose.yaml ./startDocker.bat ./README.md
+ zip -r mediaServerDockerWindows.zip ./docker/etc ./docker/.env.docker ./docker-compose.yaml ./startDocker.bat ./README.md
- name: Create Release
uses: ncipollo/release-action@v1
with:
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 7dcc37b2..d1f83a29 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -34,11 +34,11 @@ jobs:
- name: Zip Files Linux
run: |
- zip -r mediaServerDockerLinux.zip ./docker ./docker-compose.yaml ./startDocker.sh ./README.md
+ zip -r mediaServerDockerLinux.zip ./docker/etc ./docker/.env.docker ./docker-compose.yaml ./startDocker.sh ./README.md
- name: Zip Files Windows
run: |
- zip -r mediaServerDockerWindows.zip ./docker ./docker-compose.yaml ./startDocker.bat ./README.md
+ zip -r mediaServerDockerWindows.zip ./docker/etc ./docker/.env.docker ./docker-compose.yaml ./startDocker.bat ./README.md
- name: Create Release
uses: ncipollo/release-action@v1
with:
diff --git a/app/Console/Commands/GenerateReverbKeys.php b/app/Console/Commands/GenerateReverbKeys.php
index daab302a..89ed47ff 100644
--- a/app/Console/Commands/GenerateReverbKeys.php
+++ b/app/Console/Commands/GenerateReverbKeys.php
@@ -10,26 +10,28 @@ class GenerateReverbKeys extends Command {
*
* @var string
*/
- protected $signature = 'reverb:generate';
+ protected $signature = 'reverb:generate {--env-file=.env}';
/**
* The console command description.
*
* @var string
*/
- protected $description = 'Generate REVERB_APP_ID, REVERB_APP_KEY, and REVERB_APP_SECRET and insert them into the .env file';
+ protected $description = 'Generate REVERB_APP_ID, REVERB_APP_KEY, and REVERB_APP_SECRET and insert them into the specified .env file';
/**
* Execute the console command.
*/
public function handle() {
- $envPath = base_path('.env');
+ $envPath = base_path($this->option('env-file'));
if (! file_exists($envPath)) {
+ $this->error("The specified env file ($envPath) does not exist.");
return false;
}
- if ($this->keysExist()) {
+ if ($this->keysExist($envPath)) {
+ $this->info('Reverb keys already exist.');
return false;
}
@@ -41,28 +43,38 @@ class GenerateReverbKeys extends Command {
$this->setEnvironmentValue('REVERB_APP_KEY', $reverbAppKey, $envPath);
$this->setEnvironmentValue('REVERB_APP_SECRET', $reverbAppSecret, $envPath);
- $this->info('Reverb keys generated and updated in .env file.');
+ $this->info("Reverb keys generated and updated in $envPath.");
+ return true;
}
// Helper method to set the values in the .env file
protected function setEnvironmentValue($key, $value, $envPath) {
- $envPath = base_path('.env');
-
$content = file_get_contents($envPath);
$pattern = "/^$key=[^\n]*/m";
$replacement = "$key=$value";
- $newContent = preg_replace($pattern, $replacement, $content);
+ // $newContent = preg_replace($pattern, $replacement, $content);
+
+ if (preg_match($pattern, $content)) {
+ $newContent = preg_replace($pattern, $replacement, $content);
+ } else {
+ $newContent = $content . PHP_EOL . "$key=$value";
+ }
if ($newContent !== null) {
file_put_contents($envPath, $newContent);
}
}
- protected function keysExist() {
- $reverbAppId = (int) env('REVERB_APP_ID');
- $reverbAppKey = env('REVERB_APP_KEY', '');
- $reverbAppSecret = env('REVERB_APP_SECRET', '');
+ protected function keysExist($envPath) {
+ $envContent = file_get_contents($envPath);
+ // $reverbAppId = (int) env('REVERB_APP_ID');
+ // $reverbAppKey = env('REVERB_APP_KEY', '');
+ // $reverbAppSecret = env('REVERB_APP_SECRET', '');
+
+ $reverbAppId = (int) preg_match("/^REVERB_APP_ID=\d{6}$/m", $envContent);
+ $reverbAppKey = preg_match("/^REVERB_APP_KEY=[a-f0-9]{32}$/m", $envContent);
+ $reverbAppSecret = preg_match("/^REVERB_APP_SECRET=[a-f0-9]{32}$/m", $envContent);
if ($reverbAppId < 100000 || $reverbAppId > 999999) {
return false;
diff --git a/docker-compose.yaml b/docker-compose.yaml
index d1d4a0b4..cc43c1d4 100644
--- a/docker-compose.yaml
+++ b/docker-compose.yaml
@@ -6,6 +6,7 @@ services:
- ./data:/var/www/html/storage/app/public
- ./logs:/var/www/html/storage/logs
- ./docker/etc/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf
+ - ./env:/var/www/html/.env.docker
ports:
- '8086:8086'
expose:
diff --git a/docker/entrypoint.d/keys.sh b/docker/entrypoint.d/keys.sh
index 3079387f..dab5bc55 100644
--- a/docker/entrypoint.d/keys.sh
+++ b/docker/entrypoint.d/keys.sh
@@ -11,7 +11,12 @@ else
echo "APP_KEY already set, skipping key generation."
fi
-php artisan reverb:generate
+if [ -f "/var/www/html/.env.docker" ]; then
+ php artisan reverb:generate --env-file=".env.docker"
+
+else
+ php artisan reverb:generate
+fi
# echo "Waiting for PostgreSQL to be ready..."