Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ POSTGRES_DB=planifetsDB
# DATABASE_URL="postgresql://postgres:postgres@db:5432/planifetsDB?schema=public" # docker
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/planifetsDB?schema=public" # local dev


# Optional
LOG_LEVELS="log,error,warn" # Log levels: "log,error,warn,debug,fatal,verbose"
APP_GIT_SHORT_SHA=localdev
APP_GIT_SHORT_SHA=$(git rev-parse --short=7 HEAD)

# Monitoring
POSTHOG_API_KEY=""
Expand Down
25 changes: 20 additions & 5 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@ on:
branches:
- main
tags:
- 'v*'
- "v*"
pull_request:
branches:
- main
workflow_dispatch:
inputs:
environment:
description: Target environment
required: true
type: choice
options:
- staging
- dev
- prod

env:
REGISTRY: ghcr.io
Expand All @@ -26,8 +36,8 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 22.x
cache: 'yarn'
cache-dependency-path: 'yarn.lock'
cache: "yarn"
cache-dependency-path: "yarn.lock"

- name: Install dependencies
run: yarn install --frozen-lockfile
Expand All @@ -38,6 +48,7 @@ jobs:
docker:
runs-on: ubuntu-latest
needs: [build]
environment: ${{ inputs.environment }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -51,8 +62,12 @@ jobs:
type=ref,event=pr,prefix=pr-
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=main-,format=short,enable={{is_default_branch}}
type=raw,value=latest,enable={{is_default_branch}}
type=sha,prefix=main-,format=short,enable=${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
type=sha,prefix=staging-,format=short,enable=${{ inputs.environment == 'staging' }}
type=sha,prefix=dev-,format=short,enable=${{ inputs.environment == 'dev' }}
type=raw,value=latest,enable=${{ inputs.environment == 'prod' }}
type=raw,value=staging,enable=${{ inputs.environment == 'staging' }}
type=raw,value=dev,enable=${{ inputs.environment == 'dev' }}

- name: Login to Registry
uses: docker/login-action@v3
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ RUN yarn build
# Development
FROM base AS dev
WORKDIR /app
RUN apk add --no-cache git
COPY prisma ./prisma
ENV NODE_ENV=development
ENV APP_ENV=development
EXPOSE 3001
CMD ["sh", "-c", "yarn prisma:generate && yarn start:dev"]
CMD ["sh", "-c", "export APP_GIT_SHORT_SHA=$(git rev-parse --short=7 HEAD 2>/dev/null || echo localdev) && yarn prisma:generate && yarn start:dev"]

# Production
FROM node:22.22.3-alpine3.22 AS production
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ services:
environment:
DATABASE_URL: ${DATABASE_URL}
APP_ENV: development
APP_GIT_SHORT_SHA: ${APP_GIT_SHORT_SHA:-}
PORT: ${PORT:-3001}
LOG_LEVELS: ${LOG_LEVELS:-log,error,warn}
TZ: America/Toronto
Expand Down
13 changes: 13 additions & 0 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,17 @@ export class AppController {
public getError() {
throw new Error("Monitoring test error from /health/monitoring endpoint");
}

@Get('info')
@ApiTags('Info')
@ApiOperation({
summary: 'Application info',
description: 'Returns the git commit SHA and environment of the running instance',
})
public getInfo(): { gitSha: string | null; environment: string } {
return {
gitSha: process.env.APP_GIT_SHORT_SHA ?? null,
environment: process.env.APP_ENV ?? 'development',
};
}
}
Loading