Commit graph

590 commits

Author SHA1 Message Date
Andras Bacsai
194d023f70
Enhance port detection and improve user notifications (#7184) 2025-11-10 13:56:09 +01:00
Andras Bacsai
99e97900a5 feat: add automated PORT environment variable detection and UI warnings
Add detection system for PORT environment variable to help users configure applications correctly:

- Add detectPortFromEnvironment() method to Application model to detect PORT env var
- Add getDetectedPortInfoProperty() computed property in General Livewire component
- Display contextual info banners in UI when PORT is detected:
  - Warning when PORT exists but ports_exposes is empty
  - Warning when PORT doesn't match ports_exposes configuration
  - Info message when PORT matches ports_exposes
- Add deployment logging to warn about PORT/ports_exposes mismatches
- Include comprehensive unit tests for port detection logic

The ports_exposes field remains authoritative for proxy configuration, while
PORT detection provides helpful suggestions to users.
2025-11-10 13:43:27 +01:00
Andras Bacsai
0ea27ce37a
Cancel active deployments when a pull request is closed (#7164) 2025-11-10 11:16:54 +01:00
Andras Bacsai
67605d50fc fix(deployment): prevent base deployments from being killed when PRs close (#7113)
- Fix container filtering to properly distinguish base deployments (pullRequestId=0) from PR deployments
- Add deployment cancellation when PR closes via webhook to prevent race conditions
- Prevent CleanupHelperContainersJob from killing active deployment containers
- Enhance error messages with exit codes and actual errors instead of vague "Oops" messages
- Protect status transitions in finally blocks to ensure proper job failure handling
2025-11-09 14:41:35 +01:00
Andras Bacsai
712d60c75b feat: ensure .env file exists for docker compose and auto-inject in payloads 2025-11-07 15:20:10 +01:00
Andras Bacsai
d0ee7d0412
Merge branch 'next' into feat-add-dockerfile-from-instruction-par 2025-11-06 09:24:54 +01:00
Andras Bacsai
88aa24057b fix: update environment variable mapping in deployment job 2025-11-06 09:21:41 +01:00
Andras Bacsai
dbf7957795 fix: inserting ARG statements in Dockerfile after FROM instructions 2025-11-06 08:54:35 +01:00
Andras Bacsai
f315e4bd9c feat: add dev_helper_version to instance settings and update related functionality 2025-11-03 08:38:43 +01:00
Andras Bacsai
1f158b9b35 fix: Improve custom_network_aliases handling and testing
The `is_array` check for `custom_network_aliases_array` was too strict and could lead to issues when the value was an empty string or null. This commit changes the check to `!empty()` for more robust handling.

Additionally, the unit tests for `custom_network_aliases` have been refactored to directly use the `Application::isConfigurationChanged()` method. This provides a more accurate and integrated test of the configuration change detection logic, rather than relying on a manual hash calculatio
2025-11-01 13:24:05 +01:00
Andras Bacsai
9a664865ee refactor: Improve handling of custom network aliases
The custom_network_aliases attribute in the Application model was being cast to an array directly. This commit refactors the attribute to provide both a string representation (for compatibility with older configurations and hashing) and an array representation for internal use. This ensures that network aliases are correctly parsed and utilized, preventing potential issues during deployment and configuration updates.
2025-11-01 13:13:14 +01:00
Andras Bacsai
aeba914bda refactor: remove deprecated next() method
The backward-compatible next() method is no longer needed since all
call sites have been updated to use the clearer method names:
- completeDeployment()
- failDeployment()
- transitionToStatus()

This completes the refactoring to make status transitions more explicit
and maintainable.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-26 09:20:30 +01:00
Andras Bacsai
42f916dce2 fix: ensure deployment failure notifications are sent reliably
**Problem:**
Deployment failure notifications were not being sent due to two bugs:

1. **Timing Issue in next() function:**
   - When failed() called next(FAILED), the database still had status "in_progress"
   - The notification check looked for ALREADY failed status (not found yet)
   - Status was updated AFTER the check, losing the notification

2. **Direct Status Update:**
   - Healthcheck failures directly updated status to FAILED
   - Bypassed next() entirely, no notification sent

**Solution:**
Refactored status transition logic with clear separation of concerns:

- Moved notification logic AFTER status update (not before)
- Created transitionToStatus() as single source of truth
- Added completeDeployment() and failDeployment() for clarity
- Extracted status-specific side effects into dedicated methods
- Updated healthcheck failure to use failDeployment()

**Benefits:**
-  Notifications sent for ALL failure scenarios
-  Clear, self-documenting method names
-  Single responsibility per method
-  Type-safe using enum instead of strings
-  Harder to bypass notification logic accidentally
-  Backward compatible (old next() preserved)

**Changed:**
- app/Jobs/ApplicationDeploymentJob.php (+101/-21 lines)

Fixes #6911

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-26 09:06:59 +01:00
Andras Bacsai
587517394b Changes auto-committed by Conductor 2025-10-22 13:03:17 +02:00
Andras Bacsai
d8c89a1abf Changes auto-committed by Conductor 2025-10-21 20:39:39 +02:00
Andras Bacsai
41afa9568d fix: handle null environment variable values in bash escaping
Previously, the bash escaping functions (`escapeBashEnvValue()` and `escapeBashDoubleQuoted()`) had strict string type hints that rejected null values, causing deployment failures when environment variables had null values.

Changes:
- Updated both functions to accept nullable strings (`?string $value`)
- Handle null/empty values by returning empty quoted strings (`''` for single quotes, `""` for double quotes)
- Added 3 new tests to cover null and empty value handling
- All 29 tests pass

This fix ensures deployments work correctly even when environment variables have null values, while maintaining the existing behavior for all other cases.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-15 13:35:58 +02:00
Andras Bacsai
a9d899334f
Merge branch 'next' into allow-at-sign-in-git-urls 2025-10-14 20:46:08 +02:00
Andras Bacsai
7bdd53b3fb
Merge pull request #6871 from coollabsio/fix-static-publish-dir-slash
Fix static site publish directory double slash in build logs
2025-10-14 20:45:49 +02:00
Andras Bacsai
933a67645f
Update app/Jobs/ApplicationDeploymentJob.php
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-10-14 20:45:40 +02:00
Andras Bacsai
b81baff4b1 fix: improve logging and add shell escaping for git ls-remote
Two improvements to Git deployment handling:

1. **ApplicationDeploymentJob.php**:
   - Fixed log message to show actual resolved commit SHA (`$this->commit`)
   - Previously showed `$this->application->git_commit_sha` which could be "HEAD"
   - Now displays the actual 40-character commit SHA that will be deployed

2. **Application.php (generateGitLsRemoteCommands)**:
   - Added `escapeshellarg()` for repository URL in 'other' deployment type
   - Prevents shell injection in git ls-remote commands
   - Complements existing shell escaping in `generateGitImportCommands`
   - Ensures consistent security across all Git operations

**Security Impact:**
- All Git commands now use properly escaped repository URLs
- Prevents command injection through malicious repository URLs
- Consistent escaping in both ls-remote and clone operations

**User Experience:**
- Deployment logs now show exact commit SHA being deployed
- More accurate debugging information for deployment issues

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 20:44:35 +02:00
Andras Bacsai
91e070b2c3 fix: add missing save_runtime_environment_variables() in deploy_simple_dockerfile
Fixes pure Dockerfile deployment failing with 'env file not found' error.

The deploy_simple_dockerfile() method was missing the call to
save_runtime_environment_variables() which creates the .env file
needed during the rolling update phase. This call is present in
all other deployment methods (dockerfile, dockercompose, nixpacks,
static) but was missing here.

This ensures the .env file exists when docker compose tries to
use --env-file during the rolling update.
2025-10-14 20:43:11 +02:00
Andras Bacsai
1aea813b71 Fix static site publish directory double slash in build logs
- Strip leading slashes from publish_directory to prevent /app// paths
- Only add slash prefix if directory is not empty
- Ensures clean Docker COPY paths in build output
2025-10-14 17:15:41 +02:00
Andras Bacsai
893093fad3
Update app/Jobs/ApplicationDeploymentJob.php
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-10-14 15:21:38 +02:00
Andras Bacsai
bf00405971 fix(git): handle Git redirects and improve URL parsing for tangled.sh and other Git hosts
Fixes deployment failures when Git repositories redirect (e.g., tangled.sh → tangled.org)
and improves security by adding proper shell escaping for repository URLs.

**Root Cause:**
Git redirect warnings can appear on the same line as ls-remote output with no newline:
`warning: redirecting to https://tangled.org/...196d3df...	refs/heads/master`

The previous parsing logic split by newlines and extracted text before tabs, which
included the entire warning message instead of just the 40-character commit SHA.

**Changes:**

1. **Fixed commit SHA extraction** (ApplicationDeploymentJob.php):
   - Changed from line-based parsing to regex pattern matching
   - Uses `/([0-9a-f]{40})\s*\t/` to find valid 40-char hex commit SHA before tab
   - Handles warnings on same line, separate lines, multiple warnings, and whitespace
   - Added comprehensive Ray debug logs for troubleshooting

2. **Added security fix** (Application.php):
   - Added `escapeshellarg()` for repository URLs in 'other' deployment type
   - Prevents shell injection and fixes parsing issues with special characters like `@`
   - Added Ray debug logs for deployment type tracking

3. **Comprehensive test coverage** (GitLsRemoteParsingTest.php):
   - Tests normal output without warnings
   - Tests redirect warning on separate line
   - Tests redirect warning on same line (actual tangled.sh format)
   - Tests multiple warning lines
   - Tests extra whitespace handling

**Resolves:**
- Linear issue COOLGH-53: Valid git URLs are rejected as being invalid
- GitHub issue #6568: tangled.sh deployments failing
- Handles Git redirects universally for all Git hosting services

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 11:55:17 +02:00
Andras Bacsai
8d5ac0da00 feat(deployment): save build-time .env file before build and enhance logging for Dockerfile 2025-10-09 16:38:17 +02:00
Andras Bacsai
bc8cf8ed84 fix(deployment): save runtime environment variables when skipping build
- Updated the should_skip_build method to save runtime environment variables even when the build step is skipped, ensuring that the latest environment settings are preserved.
- Enhanced logging in prepare_builder_image to differentiate between the first attempt and subsequent attempts, improving clarity in deployment logs.
2025-10-07 14:26:23 +02:00
Andras Bacsai
1a42187d5d fix 2025-10-07 14:20:33 +02:00
Andras Bacsai
981f46c406 fix(deployment): add warning for NIXPACKS_NODE_VERSION in node configurations
- Implemented a check for the NIXPACKS_NODE_VERSION variable in the ApplicationDeploymentJob.
- Added log entries to notify users when NIXPACKS_NODE_VERSION is not set, indicating that Node.js 18 will be used by default, which is EOL.
- Provided guidance on how to override the default version by setting NIXPACKS_NODE_VERSION in environment variables.
2025-10-07 14:19:34 +02:00
Andras Bacsai
acf2d5f89b refactor(deployment): update environment variable handling for Docker builds
- Changed the .env file reference to use a build-time .env file located in /artifacts, preventing it from being included in Docker images.
- Introduced a new method to wrap Docker build commands with environment variable exports, enhancing the handling of build-time variables.
- Updated logging messages for clarity regarding the creation and usage of the build-time .env file.
2025-10-06 10:31:58 +02:00
Andras Bacsai
239ecd4056 fix dev only thingy 2025-10-05 11:39:22 +02:00
Andras Bacsai
06dfcff559 refactor(deployment): standardize environment variable handling in ApplicationDeploymentJob
- Replaced the use of a dynamic env_filename with a consistent .env file reference across deployment methods.
- Simplified the generation and saving of build-time and runtime environment variables, ensuring they are always written to the .env file.
- Enhanced clarity in the deployment process by removing redundant logic and ensuring environment variables are handled uniformly.
2025-10-04 19:19:15 +02:00
Andras Bacsai
158747c8b1 refactor(deployment): streamline environment variable generation in ApplicationDeploymentJob
- Removed redundant logic for merging COOLIFY_* variables into env_args.
- Simplified the process of adding environment variables by directly incorporating generated COOLIFY environment variables.
- Enhanced clarity and maintainability of the generate_env_variables method.
2025-10-04 15:06:49 +02:00
Andras Bacsai
0e02eff4a1
Merge branch 'v4.x' into allow-dep 2025-10-03 10:57:10 +02:00
Andras Bacsai
2216832f67 fix(deployments): enhance builder container management and environment variable handling
- Added a new method to restart the builder container with the actual commit value, ensuring accurate deployment.
- Improved the generation of environment variables by consolidating user-defined and Coolify-specific variables.
- Updated Dockerfile modification logic to handle environment variables more effectively, including support for multiline variables.
- Enhanced logging for better visibility during deployment processes.
2025-10-03 09:20:05 +02:00
Andras Bacsai
aadde3a83e feat(deployments): enhance Docker build argument handling for multiline variables
- Introduced new helper functions to generate Docker build arguments and environment flags, accommodating multiline variables with proper escaping.
- Updated the ApplicationDeploymentJob to utilize these new functions, improving the handling of environment variables during deployment.
- Added comprehensive tests to ensure correct behavior for multiline variables and special characters.
2025-10-02 13:54:36 +02:00
Andras Bacsai
2f099613a0 feat(deployments): add support for Coolify variables in Dockerfile
- Introduced functionality to add Coolify variables as ARGs in the Dockerfile during the build process.
- Enhanced the existing method to handle both standard environment variables and Coolify-specific variables, improving deployment flexibility.
2025-10-01 20:29:38 +02:00
Andras Bacsai
f0a532407b revert changes to v429 2025-10-01 19:57:54 +02:00
Andras Bacsai
9b4abe753d fix(git): enhance error handling for missing branch information during deployment 2025-09-30 12:23:04 +02:00
Andras Bacsai
249ab06295 refactor(deployment): remove commented-out code and streamline environment variable handling in ApplicationDeploymentJob 2025-09-29 12:05:51 +02:00
Andras Bacsai
ed7ecbb49d feat/fix(deployment): implement detection for Laravel/Symfony frameworks and configure NIXPACKS PHP environment variables accordingly 2025-09-29 12:05:14 +02:00
Andras Bacsai
d81ed86920 refactor(deployment): improve environment variable handling in ApplicationDeploymentJob 2025-09-26 15:17:42 +02:00
Andras Bacsai
2a3a46c337 feat(application): add conditional .env file creation for Symfony apps during PHP deployment 2025-09-26 09:17:25 +02:00
Andras Bacsai
667c8e6432 fix(deployment-job): enhance build time variable analysis
- Introduced logic to filter user-defined build time variables from the database based on the pull request context.
- Improved handling of build time variables to ensure only relevant variables are analyzed, enhancing the deployment process.
2025-09-24 18:19:42 +02:00
Andras Bacsai
e9324fd410 fix(deployment-job): escape single quotes in build arguments for Docker Compose command
- Added logic to escape single quotes in build arguments to ensure proper execution in bash -c context used by executeInDocker, preventing potential command errors.
2025-09-24 17:27:48 +02:00
Andras Bacsai
b1abdcee83 feat(environment-variables): implement environment variable analysis for build-time issues
- Added EnvironmentVariableAnalyzer trait to analyze and warn about problematic environment variables during the build process.
- Integrated analysis into ApplicationDeploymentJob and Livewire components to provide feedback on potential build issues.
- Introduced a new Blade component for displaying warnings related to environment variables in the UI.
2025-09-23 08:53:14 +02:00
Andras Bacsai
4f71d14d39 feat(event): introduce ApplicationConfigurationChanged event to handle team-specific configuration updates and broadcast changes
feat(envs): Generate hash from secrets to invalidate docker layers
2025-09-22 09:44:30 +02:00
Andras Bacsai
593c1b4767 fix(deployment): enhance Dockerfile modification for build-time variables and secrets during deployment in case of docker compose buildpack 2025-09-19 13:46:00 +02:00
Andras Bacsai
9ad5b8c37f feat(deployment): handle buildtime and runtime variables during deployment 2025-09-18 18:15:20 +02:00
Andras Bacsai
b34dc11d8e fix(deployment): prevent removal of running containers for pull request deployments in case of failure 2025-09-18 11:30:49 +02:00
Andras Bacsai
1f4255ef41 refactor(deployment): rename method for modifying Dockerfile to improve clarity and streamline build secrets integration 2025-09-17 18:46:10 +02:00