Fix: Use Coolify's SOURCE_COMMIT instead of git detection

Research findings:
- Coolify provides SOURCE_COMMIT environment variable with git commit hash
- Must enable "Include Source Commit in Build" in Coolify General settings
- Disabled by default to preserve Docker build cache
- Coolify automatically passes SOURCE_COMMIT as build arg

Changes:
1. Dockerfile: Use SOURCE_COMMIT build arg instead of GIT_COMMIT
2. Dockerfile: Remove git installation and detection logic
3. Dockerfile: Extract first 7 chars of SOURCE_COMMIT for short hash
4. docker-compose.yml: Pass SOURCE_COMMIT instead of GIT_COMMIT
5. docker-compose.yml: Remove GIT_COMMIT from env (set in Dockerfile)
6. README: Add instructions to enable "Include Source Commit in Build"
7. README: Update version tracking documentation

How it works:
- Coolify passes SOURCE_COMMIT to docker build
- Dockerfile takes first 7 characters: ${SOURCE_COMMIT:0:7}
- Sets as GIT_COMMIT env var for runtime
- Health endpoint returns the short commit ID

Note: Returns "unknown" if SOURCE_COMMIT tracking is not enabled.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
ryan.gogo
2026-02-15 14:02:43 +01:00
parent 2598323f84
commit 7b2c5f312c
3 changed files with 21 additions and 14 deletions

View File

@@ -72,6 +72,17 @@ Replace `username` with your actual Git username and `your-repo` with your repos
The application will be available at: `https://your-subdomain.startanaicompany.com`
**Important: Enable Git Commit Tracking**
To see the git commit ID in the `/health` endpoint, you must enable "Include Source Commit in Build" in your application's General settings in Coolify:
1. Go to your application in Coolify dashboard
2. Navigate to General settings
3. Enable "Include Source Commit in Build"
4. Redeploy your application
**Note:** This will invalidate Docker build cache on every commit (since the commit hash changes), but it allows you to track which version is deployed.
### 5. **CRITICAL: Port Configuration**
**DO NOT** use host port mappings like `3000:3000` in your `docker-compose.yml` file!
@@ -432,11 +443,13 @@ Health check endpoint that verifies connections to PostgreSQL and Redis, and ret
```
**Version Tracking:**
- `git_commit`: Short Git commit SHA (7 characters) of the deployed code, auto-detected during build using `git rev-parse --short HEAD`
- `git_commit`: Short Git commit SHA (7 characters) of the deployed code, provided by Coolify's `SOURCE_COMMIT` environment variable (first 7 characters). Returns "unknown" if "Include Source Commit in Build" is not enabled in Coolify settings.
- `version`: Application version (defaults to 1.0.0, can be set via APP_VERSION env var)
This allows AI agents and monitoring tools to verify which version is currently running. The short commit ID is industry standard for deployment tracking, providing a balance between uniqueness and readability.
**To enable commit tracking:** Go to your application's General settings in Coolify and enable "Include Source Commit in Build", then redeploy.
---
## Troubleshooting