brackt/Dockerfile

33 lines
1.1 KiB
Text
Raw Permalink Normal View History

FROM node:20-alpine AS development-dependencies-env
Optimize CI build pipeline (~15 min → ~3-5 min) (#59) ## Summary - **Dockerfile layer caching**: `development-dependencies-env` now copies only `package.json`/`package-lock.json` before `npm ci` (was `COPY . /app`), so the npm install layer is cached on every code-only commit instead of rebuilt from scratch - **Skip QEMU**: `platforms: linux/amd64` added to `build-push-action`, cutting `setup-buildx-action` from ~5 min to ~30 sec - **npm cache in CI jobs**: Manual `actions/cache@v3` blocks (copy-pasted 3×) replaced with `actions/setup-node@v4` + `cache: 'npm'`, which handles path/key/restore automatically and pins Node 20 explicitly - **Harden `.npmrc`**: Switched from `COPY .npmrc` to `--mount=type=secret,id=npmrc` in both `npm ci` stages — the file is available during install but never written into a Docker layer, so it cannot leak through the registry build cache regardless of future contents ## Expected timing | Step | Before | After (code change) | |---|---|---| | Setup buildx | ~5 min | ~30 sec | | Build + push | ~5 min | ~1-2 min | | Deploy (docker pull) | ~5 min | ~1-2 min | | **Total** | **~15 min** | **~3-5 min** | ## Test plan - [ ] Push a code-only commit to main — confirm `setup-buildx-action` logs ~30s (no QEMU), Docker build shows `CACHED` for npm install layers, build+push completes in ~1-2 min - [ ] Check deploy job — `docker compose pull` should show most layers as `Already exists` - [ ] Push a commit that changes `package.json` — confirm npm layer correctly re-runs (not cached) - [ ] Confirm deployed app is functional 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Chris Parsons <chrisparsons1127@gmail.com> Reviewed-on: https://forge.brackt.com/chrisp/brackt/pulls/59
2026-05-31 04:35:05 +00:00
COPY package.json package-lock.json /app/
WORKDIR /app
Optimize CI build pipeline (~15 min → ~3-5 min) (#59) ## Summary - **Dockerfile layer caching**: `development-dependencies-env` now copies only `package.json`/`package-lock.json` before `npm ci` (was `COPY . /app`), so the npm install layer is cached on every code-only commit instead of rebuilt from scratch - **Skip QEMU**: `platforms: linux/amd64` added to `build-push-action`, cutting `setup-buildx-action` from ~5 min to ~30 sec - **npm cache in CI jobs**: Manual `actions/cache@v3` blocks (copy-pasted 3×) replaced with `actions/setup-node@v4` + `cache: 'npm'`, which handles path/key/restore automatically and pins Node 20 explicitly - **Harden `.npmrc`**: Switched from `COPY .npmrc` to `--mount=type=secret,id=npmrc` in both `npm ci` stages — the file is available during install but never written into a Docker layer, so it cannot leak through the registry build cache regardless of future contents ## Expected timing | Step | Before | After (code change) | |---|---|---| | Setup buildx | ~5 min | ~30 sec | | Build + push | ~5 min | ~1-2 min | | Deploy (docker pull) | ~5 min | ~1-2 min | | **Total** | **~15 min** | **~3-5 min** | ## Test plan - [ ] Push a code-only commit to main — confirm `setup-buildx-action` logs ~30s (no QEMU), Docker build shows `CACHED` for npm install layers, build+push completes in ~1-2 min - [ ] Check deploy job — `docker compose pull` should show most layers as `Already exists` - [ ] Push a commit that changes `package.json` — confirm npm layer correctly re-runs (not cached) - [ ] Confirm deployed app is functional 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Chris Parsons <chrisparsons1127@gmail.com> Reviewed-on: https://forge.brackt.com/chrisp/brackt/pulls/59
2026-05-31 04:35:05 +00:00
RUN --mount=type=secret,id=npmrc,target=/app/.npmrc npm ci
FROM node:20-alpine AS production-dependencies-env
Optimize CI build pipeline (~15 min → ~3-5 min) (#59) ## Summary - **Dockerfile layer caching**: `development-dependencies-env` now copies only `package.json`/`package-lock.json` before `npm ci` (was `COPY . /app`), so the npm install layer is cached on every code-only commit instead of rebuilt from scratch - **Skip QEMU**: `platforms: linux/amd64` added to `build-push-action`, cutting `setup-buildx-action` from ~5 min to ~30 sec - **npm cache in CI jobs**: Manual `actions/cache@v3` blocks (copy-pasted 3×) replaced with `actions/setup-node@v4` + `cache: 'npm'`, which handles path/key/restore automatically and pins Node 20 explicitly - **Harden `.npmrc`**: Switched from `COPY .npmrc` to `--mount=type=secret,id=npmrc` in both `npm ci` stages — the file is available during install but never written into a Docker layer, so it cannot leak through the registry build cache regardless of future contents ## Expected timing | Step | Before | After (code change) | |---|---|---| | Setup buildx | ~5 min | ~30 sec | | Build + push | ~5 min | ~1-2 min | | Deploy (docker pull) | ~5 min | ~1-2 min | | **Total** | **~15 min** | **~3-5 min** | ## Test plan - [ ] Push a code-only commit to main — confirm `setup-buildx-action` logs ~30s (no QEMU), Docker build shows `CACHED` for npm install layers, build+push completes in ~1-2 min - [ ] Check deploy job — `docker compose pull` should show most layers as `Already exists` - [ ] Push a commit that changes `package.json` — confirm npm layer correctly re-runs (not cached) - [ ] Confirm deployed app is functional 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Chris Parsons <chrisparsons1127@gmail.com> Reviewed-on: https://forge.brackt.com/chrisp/brackt/pulls/59
2026-05-31 04:35:05 +00:00
COPY ./package.json package-lock.json /app/
WORKDIR /app
Optimize CI build pipeline (~15 min → ~3-5 min) (#59) ## Summary - **Dockerfile layer caching**: `development-dependencies-env` now copies only `package.json`/`package-lock.json` before `npm ci` (was `COPY . /app`), so the npm install layer is cached on every code-only commit instead of rebuilt from scratch - **Skip QEMU**: `platforms: linux/amd64` added to `build-push-action`, cutting `setup-buildx-action` from ~5 min to ~30 sec - **npm cache in CI jobs**: Manual `actions/cache@v3` blocks (copy-pasted 3×) replaced with `actions/setup-node@v4` + `cache: 'npm'`, which handles path/key/restore automatically and pins Node 20 explicitly - **Harden `.npmrc`**: Switched from `COPY .npmrc` to `--mount=type=secret,id=npmrc` in both `npm ci` stages — the file is available during install but never written into a Docker layer, so it cannot leak through the registry build cache regardless of future contents ## Expected timing | Step | Before | After (code change) | |---|---|---| | Setup buildx | ~5 min | ~30 sec | | Build + push | ~5 min | ~1-2 min | | Deploy (docker pull) | ~5 min | ~1-2 min | | **Total** | **~15 min** | **~3-5 min** | ## Test plan - [ ] Push a code-only commit to main — confirm `setup-buildx-action` logs ~30s (no QEMU), Docker build shows `CACHED` for npm install layers, build+push completes in ~1-2 min - [ ] Check deploy job — `docker compose pull` should show most layers as `Already exists` - [ ] Push a commit that changes `package.json` — confirm npm layer correctly re-runs (not cached) - [ ] Confirm deployed app is functional 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Chris Parsons <chrisparsons1127@gmail.com> Reviewed-on: https://forge.brackt.com/chrisp/brackt/pulls/59
2026-05-31 04:35:05 +00:00
RUN --mount=type=secret,id=npmrc,target=/app/.npmrc npm ci --omit=dev
FROM node:20-alpine AS build-env
WORKDIR /app
COPY --from=development-dependencies-env /app/node_modules /app/node_modules
COPY package.json package-lock.json tsconfig*.json vite.config.ts react-router.config.ts drizzle.config.ts ./
COPY scripts/ /app/scripts/
COPY app/ /app/app/
COPY server/ /app/server/
COPY database/ /app/database/
COPY public/ /app/public/
COPY instrument.server.mjs ./
COPY server.ts ./
RUN npm run build
FROM node:20-alpine
COPY ./package.json package-lock.json /app/
COPY --from=production-dependencies-env /app/node_modules /app/node_modules
COPY --from=build-env /app/build /app/build
COPY --from=build-env /app/dist /app/dist
COPY ./drizzle /app/drizzle
Decouple database migrations from server startup (#265) * Use Docker Compose init service pattern for database migrations Replaces the fragile double-migration approach (server.ts startup + drizzle-kit CLI in CI) with a one-shot migrate service in Docker Compose that the app depends on via condition: service_completed_successfully. - Add scripts/migrate.mjs: programmatic drizzle-orm migration (uses production deps, not drizzle-kit which is devOnly and absent from image) - Dockerfile: copy scripts/ into image, remove drizzle.config.ts (only needed by drizzle-kit CLI) - server.ts: remove runMigrations() entirely; migrations are now handled by the migrate container before the app starts - deploy.yml: remove explicit docker run migration step; replace sleep 10 health check with a poll loop and explicit migrate exit-code check Production server's docker-compose.yaml needs a one-time manual update to add the migrate service — see plan for exact config. https://claude.ai/code/session_01ReaqH3o9NVH4QU4qE9WMMQ * Move drizzle-kit to devDependencies; use docker compose wait in deploy drizzle-kit is a dev-only tool (schema generation and local migrations). Now that production migrations run via the programmatic drizzle-orm API in the migrate init container, drizzle-kit has no runtime role. Also replaces the polling health check loop with docker compose wait, which blocks until the migrate service exits and returns its exit code cleanly — no sleep or manual status inspection needed. https://claude.ai/code/session_01ReaqH3o9NVH4QU4qE9WMMQ --------- Co-authored-by: Claude <noreply@anthropic.com>
2026-04-06 00:07:36 -04:00
COPY ./scripts /app/scripts
COPY ./instrument.server.mjs /app/instrument.server.mjs
WORKDIR /app
CMD ["npm", "run", "start"]