diff --git a/.saac/config.json b/.saac/config.json new file mode 100644 index 0000000..3960780 --- /dev/null +++ b/.saac/config.json @@ -0,0 +1,7 @@ +{ + "applicationUuid": "j4ggogg8o4cs44s0ocks48o8", + "applicationName": "application", + "subdomain": "template-001", + "domainSuffix": "startanaicompany.com", + "gitRepository": "git@git.startanaicompany.com:StartAnAiCompanyTemplates/template_001.git" +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index c1a78da..9ecca8b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,13 @@ FROM node:18-alpine +# Build arguments for versioning +ARG GIT_COMMIT=unknown +ARG APP_VERSION=1.0.0 + WORKDIR /app -# Install curl for healthcheck -RUN apk add --no-cache curl +# 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 ./ @@ -12,6 +16,16 @@ RUN npm install --production # Copy app code (changes more often — below the cached layer) COPY . . +# Try to get git commit if not provided and .git exists +RUN if [ "$GIT_COMMIT" = "unknown" ] && [ -d .git ]; then \ + GIT_COMMIT=$(git rev-parse 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 \ diff --git a/README.md b/README.md index 3645205..f182c8c 100644 --- a/README.md +++ b/README.md @@ -275,13 +275,25 @@ saac deployments ### Step 7: Verify Deployment ```bash -# Check health endpoint +# Check health endpoint (includes git commit ID) curl https://template-001.startanaicompany.com/health +# You should see a response like: +# { +# "status": "healthy", +# "postgres": "connected", +# "redis": "connected", +# "timestamp": "2026-02-14T10:30:00.000Z", +# "git_commit": "eb6b6e0...", +# "version": "1.0.0" +# } + # View the website curl https://template-001.startanaicompany.com ``` +**Note:** The `git_commit` field in the health endpoint shows which version is deployed, making it easy for AI agents to track deployments. + --- ## Architecture @@ -395,7 +407,7 @@ Returns the main template website with information about the deployment. ### GET /health -Health check endpoint that verifies connections to PostgreSQL and Redis. +Health check endpoint that verifies connections to PostgreSQL and Redis, and returns deployment version information. **Response:** ```json @@ -403,7 +415,9 @@ Health check endpoint that verifies connections to PostgreSQL and Redis. "status": "healthy", "postgres": "connected", "redis": "connected", - "timestamp": "2026-02-14T10:30:00.000Z" + "timestamp": "2026-02-14T10:30:00.000Z", + "git_commit": "eb6b6e0a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q", + "version": "1.0.0" } ``` @@ -411,10 +425,18 @@ Health check endpoint that verifies connections to PostgreSQL and Redis. ```json { "status": "unhealthy", - "error": "Connection error message" + "error": "Connection error message", + "git_commit": "eb6b6e0a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q", + "version": "1.0.0" } ``` +**Version Tracking:** +- `git_commit`: The Git commit SHA of the deployed code (auto-detected during build) +- `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. + --- ## Troubleshooting diff --git a/docker-compose.yml b/docker-compose.yml index 05ef019..91bbb4b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,11 @@ version: '3.8' services: app: - build: . + build: + context: . + args: + GIT_COMMIT: ${GIT_COMMIT:-unknown} + APP_VERSION: ${APP_VERSION:-1.0.0} restart: unless-stopped environment: - NODE_ENV=production @@ -14,6 +18,8 @@ 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: condition: service_healthy diff --git a/server.js b/server.js index da7d414..0f38b2b 100644 --- a/server.js +++ b/server.js @@ -55,12 +55,16 @@ app.get('/health', async (req, res) => { status: 'healthy', postgres: 'connected', redis: 'connected', - timestamp: pgResult.rows[0].now + timestamp: pgResult.rows[0].now, + git_commit: process.env.GIT_COMMIT || 'unknown', + version: process.env.APP_VERSION || '1.0.0' }); } catch (error) { res.status(500).json({ status: 'unhealthy', - error: error.message + error: error.message, + git_commit: process.env.GIT_COMMIT || 'unknown', + version: process.env.APP_VERSION || '1.0.0' }); } });