Fix docker
This commit is contained in:
parent
5d1edd2754
commit
85f5bcbc15
2 changed files with 48 additions and 80 deletions
|
|
@ -1,14 +1,18 @@
|
||||||
# Dependencies
|
# Following pnpm Docker best practices: https://pnpm.io/docker
|
||||||
|
|
||||||
|
# Dependencies (will be installed in container)
|
||||||
node_modules
|
node_modules
|
||||||
.pnpm-store
|
.pnpm-store
|
||||||
|
|
||||||
# Build outputs
|
# Build outputs (will be built in container)
|
||||||
**/dist
|
**/dist
|
||||||
**/build
|
|
||||||
**/.next
|
|
||||||
**/.nuxt
|
|
||||||
|
|
||||||
# Testing
|
# Git
|
||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
*.md
|
||||||
|
|
||||||
|
# Testing (not needed in production)
|
||||||
**/__tests__
|
**/__tests__
|
||||||
**/*.test.ts
|
**/*.test.ts
|
||||||
**/*.test.js
|
**/*.test.js
|
||||||
|
|
@ -17,20 +21,11 @@ node_modules
|
||||||
**/coverage
|
**/coverage
|
||||||
**/.vitest
|
**/.vitest
|
||||||
|
|
||||||
# Environment files
|
|
||||||
# Note: .env files in apps/api are included for container defaults
|
|
||||||
# Override at runtime with docker run -e or --env-file
|
|
||||||
!apps/api/.env*
|
|
||||||
**/.env
|
|
||||||
**/.env.*
|
|
||||||
!**/.env.example
|
|
||||||
|
|
||||||
# Development files
|
# Development files
|
||||||
**/*.log
|
**/*.log
|
||||||
**/.DS_Store
|
**/.DS_Store
|
||||||
**/npm-debug.log*
|
**/npm-debug.log*
|
||||||
**/yarn-debug.log*
|
**/yarn-debug.log*
|
||||||
**/yarn-error.log*
|
|
||||||
**/pnpm-debug.log*
|
**/pnpm-debug.log*
|
||||||
|
|
||||||
# IDE
|
# IDE
|
||||||
|
|
@ -39,20 +34,9 @@ node_modules
|
||||||
**/.vs
|
**/.vs
|
||||||
**/*.swp
|
**/*.swp
|
||||||
**/*.swo
|
**/*.swo
|
||||||
**/*~
|
|
||||||
|
|
||||||
# Git
|
|
||||||
.git
|
|
||||||
.gitignore
|
|
||||||
.gitattributes
|
|
||||||
|
|
||||||
# Documentation (not needed in production image)
|
|
||||||
**/*.md
|
|
||||||
!**/README.md
|
|
||||||
|
|
||||||
# CI/CD
|
# CI/CD
|
||||||
.github
|
.github
|
||||||
**/.gitlab-ci.yml
|
|
||||||
**/cloudbuild.yaml
|
**/cloudbuild.yaml
|
||||||
**/.circleci
|
**/.circleci
|
||||||
|
|
||||||
|
|
@ -62,4 +46,6 @@ node_modules
|
||||||
**/.cache
|
**/.cache
|
||||||
**/tmp
|
**/tmp
|
||||||
**/temp
|
**/temp
|
||||||
|
**/.next
|
||||||
|
**/.nuxt
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,76 +3,59 @@
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# NOTE: This Dockerfile should be built from the monorepo root, not from apps/api
|
# NOTE: This Dockerfile should be built from the monorepo root, not from apps/api
|
||||||
# Build command: docker build -f apps/api/Dockerfile -t xtablo-api .
|
# Build command: docker build -f apps/api/Dockerfile -t xtablo-api .
|
||||||
FROM node:20-alpine AS base
|
FROM node:20-slim AS base
|
||||||
|
|
||||||
# Build argument for NODE_ENV
|
# Configure pnpm
|
||||||
ARG NODE_ENV=production
|
ENV PNPM_HOME="/pnpm"
|
||||||
|
ENV PATH="$PNPM_HOME:$PATH"
|
||||||
|
RUN corepack enable
|
||||||
|
|
||||||
# Install security updates and pnpm
|
# Copy all files to working directory
|
||||||
RUN apk --no-cache upgrade && \
|
COPY . /app
|
||||||
corepack enable && \
|
|
||||||
corepack prepare pnpm@latest --activate
|
|
||||||
|
|
||||||
# Create app directory and set up non-root user
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
RUN addgroup -g 1001 -S nodejs
|
|
||||||
RUN adduser -S nodejs -u 1001
|
|
||||||
|
|
||||||
# Copy workspace configuration and root package files
|
|
||||||
COPY pnpm-workspace.yaml package.json pnpm-lock.yaml ./
|
|
||||||
|
|
||||||
# Copy packages directory (shared packages)
|
|
||||||
COPY packages ./packages
|
|
||||||
|
|
||||||
# Copy api app package.json
|
|
||||||
COPY apps/api/package.json ./apps/api/package.json
|
|
||||||
|
|
||||||
# ==============================================================================
|
|
||||||
# Dependencies stage - Install all dependencies
|
|
||||||
# ==============================================================================
|
|
||||||
FROM base AS deps
|
|
||||||
|
|
||||||
# Install all dependencies (including devDependencies for build)
|
|
||||||
# This installs dependencies for the entire workspace
|
|
||||||
RUN pnpm install --frozen-lockfile
|
|
||||||
|
|
||||||
# ==============================================================================
|
|
||||||
# Build stage - Compile TypeScript
|
|
||||||
# ==============================================================================
|
|
||||||
FROM deps AS build
|
|
||||||
|
|
||||||
# Copy api source code
|
|
||||||
COPY apps/api ./apps/api
|
|
||||||
|
|
||||||
# Build the api application
|
|
||||||
WORKDIR /app/apps/api
|
|
||||||
RUN pnpm run build
|
|
||||||
|
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# Production dependencies stage - Install only production dependencies
|
# Production dependencies stage - Install only production dependencies
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
FROM base AS prod-deps
|
FROM base AS prod-deps
|
||||||
|
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
|
||||||
|
|
||||||
# Install only production dependencies
|
# ==============================================================================
|
||||||
RUN pnpm install --frozen-lockfile --prod && pnpm store prune
|
# Build stage - Install all dependencies and build
|
||||||
|
# ==============================================================================
|
||||||
|
FROM base AS build
|
||||||
|
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
|
||||||
|
# Build only the API and its dependencies
|
||||||
|
WORKDIR /app/apps/api
|
||||||
|
RUN pnpm run build
|
||||||
|
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# Final stage - Production image
|
# Final stage - Production image
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
FROM base AS final
|
FROM node:20-slim
|
||||||
|
|
||||||
# Copy built api application
|
# Configure pnpm
|
||||||
COPY --from=build /app/apps/api/dist ./apps/api/dist
|
ENV PNPM_HOME="/pnpm"
|
||||||
COPY --from=build /app/apps/api/package.json ./apps/api/package.json
|
ENV PATH="$PNPM_HOME:$PATH"
|
||||||
|
RUN corepack enable
|
||||||
|
|
||||||
# Copy shared packages (needed for workspace resolution)
|
# Create non-root user
|
||||||
COPY --from=prod-deps /app/packages ./packages
|
RUN groupadd --gid 1001 nodejs && \
|
||||||
|
useradd -l --uid 1001 --gid nodejs --shell /bin/bash --create-home nodejs
|
||||||
|
|
||||||
# Install production dependencies
|
# Copy production dependencies from prod-deps stage
|
||||||
# This ensures proper symlink structure for pnpm
|
COPY --from=prod-deps /app/node_modules /app/node_modules
|
||||||
RUN pnpm install --frozen-lockfile --prod --filter @xtablo/api...
|
COPY --from=prod-deps /app/packages /app/packages
|
||||||
|
|
||||||
# Set working directory to api app
|
# Copy built application from build stage
|
||||||
|
COPY --from=build /app/apps/api/dist /app/apps/api/dist
|
||||||
|
COPY --from=build /app/apps/api/package.json /app/apps/api/package.json
|
||||||
|
|
||||||
|
# Copy workspace files for proper resolution
|
||||||
|
COPY --from=build /app/pnpm-workspace.yaml /app/pnpm-workspace.yaml
|
||||||
|
COPY --from=build /app/package.json /app/package.json
|
||||||
|
|
||||||
|
# Set working directory
|
||||||
WORKDIR /app/apps/api
|
WORKDIR /app/apps/api
|
||||||
|
|
||||||
# Change ownership to nodejs user
|
# Change ownership to nodejs user
|
||||||
|
|
@ -85,5 +68,4 @@ USER nodejs
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
# NODE_ENV will be set via Cloud Run environment variables
|
# NODE_ENV will be set via Cloud Run environment variables
|
||||||
# Start the application
|
|
||||||
CMD ["pnpm", "start"]
|
CMD ["pnpm", "start"]
|
||||||
Loading…
Reference in a new issue