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

@@ -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