-
Notifications
You must be signed in to change notification settings - Fork 3
feat(TEA-84): add PR gate for lint, type-check, build, and Docker health #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Mohamed-Elshesheny
wants to merge
3
commits into
main
Choose a base branch
from
chore/ci-gate-pipeline
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
1035a69
feat(ci): add CI workflow for linting, type-checking, and building; a…
Mohamed-Elshesheny 6cd48c3
refactor(Dockerfile): streamline Dockerfile stages and improve health…
Mohamed-Elshesheny 6615f9b
fix(eslint-config): set explicit React version to prevent compatibili…
ibastawisi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| concurrency: | ||
| group: ci-${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| build: | ||
| name: Lint, type-check, build | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup pnpm | ||
| uses: pnpm/action-setup@v4 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| cache: 'pnpm' | ||
|
|
||
| - name: Restore turbo cache | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: | | ||
| .turbo | ||
| node_modules/.cache/turbo | ||
| key: ${{ runner.os }}-turbo-${{ hashFiles('pnpm-lock.yaml') }}-${{ github.sha }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-turbo-${{ hashFiles('pnpm-lock.yaml') }}- | ||
| ${{ runner.os }}-turbo- | ||
|
|
||
| - name: Install dependencies | ||
| run: pnpm install --frozen-lockfile | ||
|
|
||
| - name: Lint | ||
| run: pnpm lint | ||
|
|
||
| - name: Type-check | ||
| run: pnpm check-types | ||
|
|
||
| - name: Build | ||
| run: pnpm build | ||
|
|
||
| docker: | ||
| name: Docker stack health | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Build images | ||
| run: docker compose build | ||
|
|
||
| - name: Start stack and wait for healthchecks | ||
| run: docker compose up -d --wait --wait-timeout 180 | ||
|
|
||
| - name: Dump compose state on failure | ||
| if: failure() | ||
| run: | | ||
| docker compose ps | ||
| docker compose logs --no-color | ||
|
|
||
| - name: Tear down stack | ||
| if: always() | ||
| run: docker compose down -v | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,119 +1,125 @@ | ||
| # ========================================== | ||
| # STAGE 1: Pruner | ||
| # ========================================== | ||
| FROM node:20-alpine AS pruner | ||
| RUN apk add --no-cache libc6-compat | ||
| WORKDIR /app | ||
| RUN npm install -g turbo | ||
| COPY . . | ||
| RUN turbo prune --scope=web --scope=@repo/backend --docker | ||
|
|
||
| # ========================================== | ||
| # STAGE 2: Base & Builder | ||
| # ========================================== | ||
| FROM node:20-alpine AS builder | ||
| RUN apk add --no-cache libc6-compat sqlite | ||
| WORKDIR /app | ||
|
|
||
| RUN corepack enable && corepack prepare pnpm@10.27.0 --activate | ||
|
|
||
| # Copy pruned files | ||
| COPY --from=pruner /app/out/json/ . | ||
| COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml | ||
|
|
||
| RUN pnpm install --frozen-lockfile | ||
|
|
||
| COPY --from=pruner /app/out/full/ . | ||
|
|
||
| ENV DB_FILE_NAME=file:/app/apps/backend/local.db | ||
|
|
||
| # Web app environment variables (build-time) | ||
| ARG VITE_BACKEND_URL | ||
|
|
||
| ENV VITE_BACKEND_URL=${VITE_BACKEND_URL:-} | ||
|
|
||
|
|
||
| RUN pnpm build --filter=web... --filter=@repo/backend... | ||
|
|
||
| RUN pnpm --filter @repo/backend --prod deploy --legacy pruned-backend | ||
|
|
||
| # ========================================== | ||
| # STAGE 3: Backend Runner | ||
| # ========================================== | ||
| FROM node:20-alpine AS backend | ||
| WORKDIR /app | ||
|
|
||
| RUN apk add --no-cache sqlite libc6-compat | ||
|
|
||
| RUN addgroup --system --gid 1001 nodejs && \ | ||
| adduser --system --uid 1001 nodejs | ||
|
|
||
| COPY --from=builder /app/pruned-backend . | ||
| COPY --from=builder /app/apps/backend/dist ./dist | ||
| COPY --from=builder /app/apps/backend/drizzle ./drizzle | ||
| COPY --from=builder /app/apps/backend/src/scripts/run-migrations.mjs ./run-migrations.mjs | ||
|
|
||
| RUN mkdir -p storage && chown -R nodejs:nodejs storage | ||
|
|
||
| USER nodejs | ||
|
|
||
| ENV NODE_ENV=production | ||
| ENV PORT=3000 | ||
| ENV DB_FILE_NAME=file:storage/local.db | ||
| ENV CLIENT_URL=http://localhost:5173 | ||
|
|
||
| EXPOSE 3000 | ||
|
|
||
| CMD ["sh", "-c", "node run-migrations.mjs && node dist/index.js"] | ||
|
|
||
| # ========================================== | ||
| # STAGE 4: Web Runner (Nginx) | ||
| # ========================================== | ||
| FROM nginx:alpine AS web | ||
| WORKDIR /usr/share/nginx/html | ||
| RUN rm -rf ./* | ||
| COPY --from=builder /app/apps/web/dist . | ||
|
|
||
| RUN echo 'server { \ | ||
| listen 80; \ | ||
| \ | ||
| # Enable Gzip compression for faster loading \ | ||
| gzip on; \ | ||
| gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; \ | ||
| \ | ||
| location / { \ | ||
| root /usr/share/nginx/html; \ | ||
| index index.html index.htm; \ | ||
| try_files $uri $uri/ /index.html; \ | ||
| } \ | ||
| \ | ||
| # Proxy API requests to the backend container \ | ||
| location /api/ { \ | ||
| proxy_pass http://backend:3000; \ | ||
| proxy_set_header Host $host; \ | ||
| proxy_set_header X-Real-IP $remote_addr; \ | ||
| } \ | ||
| \ | ||
| # Proxy storage requests to the backend container \ | ||
| location /storage/ { \ | ||
| proxy_pass http://backend:3000; \ | ||
| proxy_set_header Host $host; \ | ||
| proxy_set_header X-Real-IP $remote_addr; \ | ||
| client_max_body_size 10M; \ | ||
| } \ | ||
| \ | ||
| # Proxy WebSocket connections for Socket.io \ | ||
| location /socket.io/ { \ | ||
| proxy_pass http://backend:3000; \ | ||
| proxy_http_version 1.1; \ | ||
| proxy_set_header Upgrade $http_upgrade; \ | ||
| proxy_set_header Connection "upgrade"; \ | ||
| proxy_set_header Host $host; \ | ||
| proxy_set_header X-Real-IP $remote_addr; \ | ||
| proxy_read_timeout 86400; \ | ||
| proxy_send_timeout 86400; \ | ||
| } \ | ||
| }' > /etc/nginx/conf.d/default.conf | ||
|
|
||
| EXPOSE 80 | ||
| # ========================================== | ||
| # STAGE 1: Pruner | ||
| # ========================================== | ||
| FROM node:20-alpine AS pruner | ||
| RUN apk add --no-cache libc6-compat | ||
| WORKDIR /app | ||
| RUN npm install -g turbo | ||
| COPY . . | ||
| RUN turbo prune --scope=web --scope=@repo/backend --docker | ||
|
|
||
| # ========================================== | ||
| # STAGE 2: Base & Builder | ||
| # ========================================== | ||
| FROM node:20-alpine AS builder | ||
| RUN apk add --no-cache libc6-compat sqlite | ||
| WORKDIR /app | ||
|
|
||
| RUN corepack enable && corepack prepare pnpm@10.27.0 --activate | ||
|
|
||
| # Copy pruned files | ||
| COPY --from=pruner /app/out/json/ . | ||
| COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml | ||
|
|
||
| RUN pnpm install --frozen-lockfile | ||
|
|
||
| COPY --from=pruner /app/out/full/ . | ||
|
|
||
| ENV DB_FILE_NAME=file:/app/apps/backend/local.db | ||
|
|
||
| # Web app environment variables (build-time) | ||
| ARG VITE_BACKEND_URL | ||
|
|
||
| ENV VITE_BACKEND_URL=${VITE_BACKEND_URL:-} | ||
|
|
||
|
|
||
| RUN pnpm build --filter=web... --filter=@repo/backend... | ||
|
|
||
| RUN pnpm --filter @repo/backend --prod deploy --legacy pruned-backend | ||
|
|
||
| # ========================================== | ||
| # STAGE 3: Backend Runner | ||
| # ========================================== | ||
| FROM node:20-alpine AS backend | ||
| WORKDIR /app | ||
|
|
||
| RUN apk add --no-cache sqlite libc6-compat | ||
|
|
||
| RUN addgroup --system --gid 1001 nodejs && \ | ||
| adduser --system --uid 1001 nodejs | ||
|
|
||
| COPY --from=builder /app/pruned-backend . | ||
| COPY --from=builder /app/apps/backend/dist ./dist | ||
| COPY --from=builder /app/apps/backend/drizzle ./drizzle | ||
| COPY --from=builder /app/apps/backend/src/scripts/run-migrations.mjs ./run-migrations.mjs | ||
|
|
||
| RUN mkdir -p storage && chown -R nodejs:nodejs storage | ||
|
|
||
| USER nodejs | ||
|
|
||
| ENV NODE_ENV=production | ||
| ENV PORT=3000 | ||
| ENV DB_FILE_NAME=file:storage/local.db | ||
| ENV CLIENT_URL=http://localhost:5173 | ||
|
|
||
| EXPOSE 3000 | ||
|
|
||
| CMD ["sh", "-c", "node run-migrations.mjs && node dist/index.js"] | ||
|
|
||
| # ========================================== | ||
| # STAGE 4: Web Runner (Nginx) | ||
| # ========================================== | ||
| FROM nginx:alpine AS web | ||
| WORKDIR /usr/share/nginx/html | ||
| RUN rm -rf ./* | ||
| COPY --from=builder /app/apps/web/dist . | ||
|
|
||
| RUN cat <<'EOF' > /etc/nginx/conf.d/default.conf | ||
| server { | ||
| listen 80; | ||
|
|
||
| # Enable Gzip compression for faster loading | ||
| gzip on; | ||
| gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; | ||
|
|
||
| location / { | ||
| root /usr/share/nginx/html; | ||
| index index.html index.htm; | ||
| try_files $uri $uri/ /index.html; | ||
| } | ||
|
|
||
| # Proxy API requests to the backend container | ||
| location /api/ { | ||
| proxy_pass http://backend:3000; | ||
| proxy_set_header Host $host; | ||
| proxy_set_header X-Real-IP $remote_addr; | ||
| } | ||
|
|
||
| # Proxy storage requests to the backend container | ||
| location /storage/ { | ||
| proxy_pass http://backend:3000; | ||
| proxy_set_header Host $host; | ||
| proxy_set_header X-Real-IP $remote_addr; | ||
| client_max_body_size 10M; | ||
| } | ||
|
|
||
| # Proxy WebSocket connections for Socket.io | ||
| location /socket.io/ { | ||
| proxy_pass http://backend:3000; | ||
| proxy_http_version 1.1; | ||
| proxy_set_header Upgrade $http_upgrade; | ||
| proxy_set_header Connection "upgrade"; | ||
| proxy_set_header Host $host; | ||
| proxy_set_header X-Real-IP $remote_addr; | ||
| proxy_read_timeout 86400; | ||
| proxy_send_timeout 86400; | ||
| } | ||
| } | ||
| EOF | ||
|
|
||
| EXPOSE 80 | ||
|
|
||
| HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ | ||
| CMD wget -qO- http://127.0.0.1/ >/dev/null 2>&1 || exit 1 | ||
|
|
||
| CMD ["nginx", "-g", "daemon off;"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set explicit least-privilege
GITHUB_TOKENpermissions.This workflow performs read/build/test actions only. Add explicit read-only permissions to avoid inheriting broader defaults.
Proposed hardening
name: CI @@ concurrency: group: ci-${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true + +permissions: + contents: read🤖 Prompt for AI Agents