diff --git a/Dockerfile b/Dockerfile index 85dc1ed..a2213e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,13 @@ FROM node:18-alpine -# Build arguments for versioning -ARG GIT_COMMIT=unknown +# Build arguments - Coolify provides SOURCE_COMMIT automatically +ARG SOURCE_COMMIT=unknown ARG APP_VERSION=1.0.0 WORKDIR /app -# Install curl for healthcheck and git for commit info -RUN apk add --no-cache curl git +# Install curl for healthcheck +RUN apk add --no-cache curl # Copy package files first for layer caching COPY package*.json ./ @@ -16,14 +16,9 @@ RUN npm install --production # Copy app code (changes more often — below the cached layer) COPY . . -# Try to get short git commit (7 chars) if not provided and .git exists -RUN if [ "$GIT_COMMIT" = "unknown" ] && [ -d .git ]; then \ - GIT_COMMIT=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown"); \ - fi && \ - echo "export GIT_COMMIT=${GIT_COMMIT}" >> /etc/profile.d/git-version.sh - # Set environment variables for runtime -ENV GIT_COMMIT=${GIT_COMMIT} \ +# Extract first 7 characters of SOURCE_COMMIT for short hash +ENV GIT_COMMIT=${SOURCE_COMMIT:0:7} \ APP_VERSION=${APP_VERSION} EXPOSE 3000 diff --git a/README.md b/README.md index d7b7cdb..226eb95 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index 91bbb4b..41df4f0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ services: build: context: . args: - GIT_COMMIT: ${GIT_COMMIT:-unknown} + SOURCE_COMMIT: ${SOURCE_COMMIT:-unknown} APP_VERSION: ${APP_VERSION:-1.0.0} restart: unless-stopped environment: @@ -18,7 +18,6 @@ services: - POSTGRES_DB=template_db - REDIS_HOST=redis - REDIS_PORT=6379 - - GIT_COMMIT=${GIT_COMMIT:-unknown} - APP_VERSION=${APP_VERSION:-1.0.0} depends_on: postgres: