Files
template_001/Dockerfile
ryan.gogo 25b9d20094 Fix: Use short git commit ID (7 chars) instead of full hash
Research findings:
- Industry standard uses 'git rev-parse --short HEAD' (7 characters)
- Short hashes are more readable for logs and health endpoints
- Git automatically extends hash if 7 chars aren't unique
- Better for production deployment tracking and version verification

Changes:
- Dockerfile: Use --short flag to get 7-character commit ID
- README: Update examples to show short commit format (0e993d9)
- README: Add explanation of why short commits are used

Example health response:
{
  "git_commit": "0e993d9",  // 7 chars, not full 40-char SHA
  "version": "1.0.0"
}

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

Co-Authored-By: Claude <noreply@anthropic.com>
2026-02-15 11:00:45 +01:00

35 lines
942 B
Docker

FROM node:18-alpine
# Build arguments for versioning
ARG GIT_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
# Copy package files first for layer caching
COPY package*.json ./
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} \
APP_VERSION=${APP_VERSION}
EXPOSE 3000
HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=2 \
CMD curl -f http://localhost:3000/health || exit 1
CMD ["node", "server.js"]