Skip to content

Conversation

@Elandlord
Copy link

@Elandlord Elandlord commented Nov 13, 2025

Changes

  • In the ApplicationDeploymentJob.php@generate_runtime_environment_variables() the recently added SERVICE_NAME .env value can contain dashes, causing dotEnv parsers to break on deployment. In the linked issue, people are mentioning both Symfony and Bun apps breaking. Upon inspection, I saw that the service name does not take into account characters like - or . which causes the parser to break upon deployment.

In order to fix it, I have added the replace functions in the exact way they are added in App\Models\Service.php for example.

Issues

Example:
image

Summary by CodeRabbit

  • Bug Fixes
    • Fixed deployment environment variable generation to properly sanitize service names. Service names containing dashes or dots are now correctly converted to valid shell identifiers for docker-compose builds, ensuring that deployments work correctly regardless of whether service names contain these special characters.

@Elandlord Elandlord changed the title 🐛 Add replace hyphen and dot with underscore - prevent parse errors Fix: prevent SERVICE_NAME with dashes from breaking dotenv parsing in Symfony and Bun deployments. Nov 13, 2025
@Elandlord Elandlord changed the title Fix: prevent SERVICE_NAME with dashes from breaking dotenv parsing in Symfony and Bun deployments. Fix: prevent SERVICE_NAME with dashes from breaking DotEnv parsing Nov 13, 2025
@ShadowArcanist
Copy link
Member

@CodeRabbit review!

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 13, 2025

@ShadowArcanist: I'll review the changes in this PR right away!

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 13, 2025

Walkthrough

The pull request modifies ApplicationDeploymentJob.php to sanitize SERVICE_NAME environment variable keys by replacing dashes and dots with underscores before uppercasing, ensuring valid shell identifiers while preserving original service names as values.

Changes

Cohort / File(s) Summary
Environment variable sanitization
app/Jobs/ApplicationDeploymentJob.php
Sanitizes SERVICE_NAME keys by replacing dashes and dots with underscores before uppercasing for Docker Compose runtime environment variable generation

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Verify the sanitization logic handles all expected edge cases (consecutive dashes/dots, boundary characters)
  • Check that existing service configurations and tests accommodate the new variable naming scheme
  • Confirm no downstream dependencies rely on the previous variable name format

Possibly related PRs

Poem

🐰 Dashes and dots now transform with care,
Underscores in their place so fair,
Shell variables now pristine and true,
Valid identifiers, shiny and new! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: fixing SERVICE_NAME parsing issues by preventing dashes from breaking DotEnv parsing.
Description check ✅ Passed The description includes the Changes and Issues sections as required by the template, with clear explanation of the fix and relevant issue link.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
app/Jobs/ApplicationDeploymentJob.php (2)

1178-1183: Apply the same sanitization to preview deployments.

This code generates SERVICE_NAME variables for preview/PR deployments but lacks the sanitization applied at line 1128. Service names with dashes or dots will still break DotEnv parsers for preview deployments.

Apply this diff to maintain consistency:

                 $rawDockerCompose = Yaml::parse($this->application->docker_compose_raw);
                 $rawServices = data_get($rawDockerCompose, 'services', []);
                 foreach ($rawServices as $rawServiceName => $_) {
-                    $envs->push('SERVICE_NAME_'.str($rawServiceName)->upper().'='.addPreviewDeploymentSuffix($rawServiceName, $this->pull_request_id));
+                    $envs->push('SERVICE_NAME_'.str($rawServiceName)->replace('-', '_')->replace('.', '_')->upper().'='.addPreviewDeploymentSuffix($rawServiceName, $this->pull_request_id));
                 }

1340-1390: Apply the same sanitization to build-time SERVICE_NAME variables.

The generate_buildtime_environment_variables() method generates SERVICE_NAME variables at lines 1351 and 1373, but both lack the dash/dot sanitization. This will cause DotEnv parser failures during the build phase when services have dashes or dots in their names.

Apply this diff:

                 $services = data_get($dockerCompose, 'services', []);
                 foreach ($services as $serviceName => $_) {
-                    $envs->push('SERVICE_NAME_'.str($serviceName)->upper().'='.escapeBashEnvValue($serviceName));
+                    $envs->push('SERVICE_NAME_'.str($serviceName)->replace('-', '_')->replace('.', '_')->upper().'='.escapeBashEnvValue($serviceName));
                 }

                 // ... later in the preview section ...

                 $rawServices = data_get($rawDockerCompose, 'services', []);
                 foreach ($rawServices as $rawServiceName => $_) {
-                    $envs->push('SERVICE_NAME_'.str($rawServiceName)->upper().'='.escapeBashEnvValue(addPreviewDeploymentSuffix($rawServiceName, $this->pull_request_id)));
+                    $envs->push('SERVICE_NAME_'.str($rawServiceName)->replace('-', '_')->replace('.', '_')->upper().'='.escapeBashEnvValue(addPreviewDeploymentSuffix($rawServiceName, $this->pull_request_id)));
                 }
🧹 Nitpick comments (2)
app/Jobs/ApplicationDeploymentJob.php (2)

1128-1128: Good fix, but consider collision handling.

The sanitization correctly prevents DotEnv parser breakage by ensuring SERVICE_NAME keys are valid shell identifiers. The original service name is properly preserved in the value.

However, there's a potential collision risk: services with names differing only by dashes/dots (e.g., my-service and my.service) would both map to SERVICE_NAME_MY_SERVICE, causing the latter to silently overwrite the former.

Consider adding collision detection:

$sanitizedKey = str($serviceName)->replace('-', '_')->replace('.', '_')->upper();
$envKey = 'SERVICE_NAME_'.$sanitizedKey;
if ($envs->contains(fn($env) => str($env)->startsWith($envKey.'='))) {
    $this->application_deployment_queue->addLogEntry("Warning: SERVICE_NAME collision detected for service '{$serviceName}' (sanitized to {$sanitizedKey})", 'warning');
}
$envs->push($envKey.'='.$serviceName);

1107-1117: Consider sanitizing SERVICE_FQDN and SERVICE_URL keys for consistency.

For consistency with the SERVICE_NAME fix, consider applying the same sanitization to SERVICE_FQDN and SERVICE_URL variable keys. While these derive from the docker_compose_domains configuration rather than direct service names, they may still contain dashes or dots if the domain keys match service names.

Example for line 1115-1116:

-                        $envs->push('SERVICE_URL_'.str($forServiceName)->upper().'='.$coolifyUrl->__toString());
-                        $envs->push('SERVICE_FQDN_'.str($forServiceName)->upper().'='.$coolifyFqdn);
+                        $envs->push('SERVICE_URL_'.str($forServiceName)->replace('-', '_')->replace('.', '_')->upper().'='.$coolifyUrl->__toString());
+                        $envs->push('SERVICE_FQDN_'.str($forServiceName)->replace('-', '_')->replace('.', '_')->upper().'='.$coolifyFqdn);

Apply similar changes to lines 1173-1174 for preview deployments.

Also applies to: 1165-1175

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between afdc4f9 and 39526cb.

📒 Files selected for processing (1)
  • app/Jobs/ApplicationDeploymentJob.php (1 hunks)

@Elandlord
Copy link
Author

@ShadowArcanist I have added the changes requested by CodeRabbit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants