refactor: Update RabbitMQ configuration to use environment variable for port

This commit is contained in:
Andras Bacsai
2024-08-12 12:37:39 +02:00
parent e068581862
commit f87e6bcfc6
4 changed files with 71 additions and 24 deletions

View File

@@ -205,6 +205,41 @@ class Service extends BaseModel
foreach ($applications as $application) {
$image = str($application->image)->before(':')->value();
switch ($image) {
case str($image)?->contains('rabbitmq'):
$data = collect([]);
$host_port = $this->environment_variables()->where('key', 'PORT')->first();
$username = $this->environment_variables()->where('key', 'SERVICE_USER_RABBITMQ')->first();
$password = $this->environment_variables()->where('key', 'SERVICE_PASSWORD_RABBITMQ')->first();
if ($host_port) {
$data = $data->merge([
'Host Port Binding' => [
'key' => data_get($host_port, 'key'),
'value' => data_get($host_port, 'value'),
'rules' => 'required',
],
]);
}
if ($username) {
$data = $data->merge([
'Username' => [
'key' => data_get($username, 'key'),
'value' => data_get($username, 'value'),
'rules' => 'required',
],
]);
}
if ($password) {
$data = $data->merge([
'Password' => [
'key' => data_get($password, 'key'),
'value' => data_get($password, 'value'),
'rules' => 'required',
'isPassword' => true,
],
]);
}
$fields->put('RabbitMQ', $data->toArray());
break;
case str($image)?->contains('tolgee'):
$data = collect([]);
$admin_password = $this->environment_variables()->where('key', 'SERVICE_PASSWORD_TOLGEE')->first();
@@ -504,6 +539,9 @@ class Service extends BaseModel
default:
$data = collect([]);
$admin_user = $this->environment_variables()->where('key', 'SERVICE_USER_ADMIN')->first();
// Chaskiq
$admin_email = $this->environment_variables()->where('key', 'ADMIN_EMAIL')->first();
$admin_password = $this->environment_variables()->where('key', 'SERVICE_PASSWORD_ADMIN')->first();
if ($admin_user) {
$data = $data->merge([
@@ -525,6 +563,15 @@ class Service extends BaseModel
],
]);
}
if ($admin_email) {
$data = $data->merge([
'Email' => [
'key' => 'ADMIN_EMAIL',
'value' => data_get($admin_email, 'value'),
'rules' => 'required|email',
],
]);
}
$fields->put('Admin', $data->toArray());
break;
case str($image)?->contains('vaultwarden'):

View File

@@ -13,8 +13,8 @@ services:
- DATABASE_URL=postgres://$SERVICE_USER_POSTGRES:$SERVICE_PASSWORD_POSTGRES@postgresql:5432/${POSTGRES_DB:-chaskiq}
- POSTGRES_USER=$SERVICE_USER_POSTGRES
- SERVICE_URL=${SERVICE_URL_CHASKIQ}
- HOST=https://${SERVICE_URL_CHASKIQ}
- ASSET_HOST=https://${SERVICE_URL_CHASKIQ}
- HOST=${SERVICE_FQDN_CHASKIQ_3000}
- ASSET_HOST=${SERVICE_FQDN_CHASKIQ_3000}
- WS=wss://${SERVICE_URL_CHASKIQ}/cable
- SNS_CONFIGURATION_SET=metrics
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID:-}
@@ -22,9 +22,9 @@ services:
- AWS_S3_BUCKET=${AWS_S3_BUCKET:-}
- AWS_S3_REGION=${AWS_S3_REGION:-}
- ADMIN_EMAIL=${ADMIN_EMAIL:-admin@example}
- ADMIN_PASSWORD=${ADMIN_PASSWORD:-password}
- ADMIN_PASSWORD=${SERVICE_PASSWORD_ADMIN}
- DEFAULT_SENDER_EMAIL=${DEFAULT_SENDER_EMAIL:-admin@example}
- LOCAL_STORAGE_PATH=./data/storage
- LOCAL_STORAGE_PATH=/data/storage
- ACTIVE_STORAGE_SERVICE=${ACTIVE_STORAGE_SERVICE:-local}
- SMTP_DELIVERY_METHOD=${SMTP_DELIVERY_METHOD:-}
- SMTP_ADDRESS=${SMTP_ADDRESS:-}
@@ -55,13 +55,8 @@ services:
set -e
rm -f /usr/src/app/tmp/pids/server.pid
exec "$@"
while ! pg_isready -q -h postgresql -p 5432 -U $POSTGRES_USER
do
echo "$(date) - waiting for database to start."
sleep 2
done
echo "Running database migrations..."
bundle exec rails db:setup
bundle exec rails db:setup || true
bundle exec rails db:migrate
echo "Finished running database migrations."
echo "Running packages update..."
@@ -76,7 +71,7 @@ services:
bundle exec rails s -b 0.0.0.0 -p 3000
healthcheck:
test: ["CMD", "curl", "-f", "http://127.0.0.1:3000"]
interval: 15s
interval: 5s
timeout: 20s
retries: 15
sidekiq:
@@ -85,8 +80,8 @@ services:
- REDIS_URL=redis://redis:6379/
- DATABASE_URL=postgres://$SERVICE_USER_POSTGRES:$SERVICE_PASSWORD_POSTGRES@postgresql:5432/${POSTGRES_DB:-chaskiq}
- POSTGRES_USER=$SERVICE_USER_POSTGRES
- HOST=https://${SERVICE_URL_CHASKIQ}
- ASSET_HOST=https://${SERVICE_URL_CHASKIQ}
- HOST=${SERVICE_FQDN_CHASKIQ_3000}
- ASSET_HOST=${SERVICE_FQDN_CHASKIQ_3000}
- WS=wss://${SERVICE_URL_CHASKIQ}/cable
- SNS_CONFIGURATION_SET=metrics
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID:-}
@@ -94,9 +89,9 @@ services:
- AWS_S3_BUCKET=${AWS_S3_BUCKET:-}
- AWS_S3_REGION=${AWS_S3_REGION:-}
- ADMIN_EMAIL=${ADMIN_EMAIL:-admin@example}
- ADMIN_PASSWORD=${ADMIN_PASSWORD:-password}
- ADMIN_PASSWORD=${SERVICE_PASSWORD_ADMIN}
- DEFAULT_SENDER_EMAIL=${DEFAULT_SENDER_EMAIL:-admin@example}
- LOCAL_STORAGE_PATH=./data/storage
- LOCAL_STORAGE_PATH=/data/storage
- ACTIVE_STORAGE_SERVICE=${ACTIVE_STORAGE_SERVICE:-local}
- SMTP_DELIVERY_METHOD=${SMTP_DELIVERY_METHOD:-}
- SMTP_ADDRESS=${SMTP_ADDRESS:-}
@@ -120,12 +115,16 @@ services:
condition: service_healthy
chaskiq:
condition: service_healthy
command: ['bundle', 'exec', 'sidekiq', '-C', 'config/sidekiq.yml']
command: ["bundle", "exec", "sidekiq", "-C", "config/sidekiq.yml"]
healthcheck:
test: ["CMD-SHELL", "bundle exec rails runner 'puts Sidekiq.redis(&:info)' > /dev/null 2>&1"]
interval: 30s
test:
[
"CMD-SHELL",
"bundle exec rails runner 'puts Sidekiq.redis(&:info)' > /dev/null 2>&1",
]
interval: 5s
timeout: 10s
retries: 3
retries: 15
postgresql:
image: postgres:14-alpine
volumes:
@@ -138,7 +137,7 @@ services:
- PSQL_HISTFILE=/root/log/.psql_history
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
interval: 10s
interval: 5s
timeout: 5s
retries: 10
redis:
@@ -148,6 +147,6 @@ services:
- redis-data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
interval: 5s
timeout: 5s
retries: 10
retries: 10

View File

@@ -11,8 +11,9 @@ services:
- SERVICE_FQDN_RABBITMQ_15672
- RABBITMQ_DEFAULT_USER=$SERVICE_USER_RABBITMQ
- RABBITMQ_DEFAULT_PASS=$SERVICE_PASSWORD_RABBITMQ
- PORT=${PORT:-5672}
ports:
- 5672:5672
- ${PORT}:5672
healthcheck:
test: rabbitmq-diagnostics -q ping
interval: 30s

File diff suppressed because one or more lines are too long