Files
sgse-app/Dockerfile
killer-cf 75989b0546 refactor: update Dockerfile for improved workspace structure and build process
- Adjusted the Dockerfile to copy package.json files from workspace packages, ensuring proper dependency resolution.
- Modified the build context in the deploy workflow to streamline the Docker image build process.
- Enhanced the build steps to navigate to the web app directory before building, ensuring correct application setup.
2025-11-26 10:48:01 -03:00

71 lines
2.2 KiB
Docker

# Use the official Bun image
FROM oven/bun:1 AS base
# Set the working directory inside the container
WORKDIR /usr/src/app
# Create a non-root user for security
RUN addgroup --system --gid 1001 sveltekit
RUN adduser --system --uid 1001 sveltekit
# Copy package.json and bun.lock (if available)
COPY package.json bun.lock* ./
# Copy workspace packages first (needed for bun install to resolve local dependencies)
# Copy package.json files to establish workspace structure
COPY packages/backend/package.json ./packages/backend/
COPY packages/eslint-config/package.json ./packages/eslint-config/
# Copy eslint-config files (needed for the package to be valid)
COPY packages/eslint-config/*.js ./packages/eslint-config/
# Copy apps/web package.json (also part of the workspace)
COPY apps/web/package.json ./apps/web/
# Install dependencies (including dev dependencies for build)
# This will resolve workspace dependencies using the package.json files we just copied
RUN bun install --frozen-lockfile
# Copy the rest of the source code
COPY . .
# Prepare SvelteKit and build the application
# Navigate to web app directory and build
WORKDIR /usr/src/app/apps/web
RUN bun run prepare
RUN bun run build
# Production stage
FROM oven/bun:1-slim AS production
# Set working directory
WORKDIR /usr/src/app
# Create non-root user
RUN addgroup --system --gid 1001 sveltekit
RUN adduser --system --uid 1001 sveltekit
# Copy built application from base stage
COPY --from=base --chown=sveltekit:sveltekit /usr/src/app/apps/web/build ./build
COPY --from=base --chown=sveltekit:sveltekit /usr/src/app/apps/web/package.json ./package.json
# Copy node_modules from root (Bun manages workspaces centrally)
COPY --from=base --chown=sveltekit:sveltekit /usr/src/app/node_modules ./node_modules
# Copy any additional files needed for runtime
COPY --from=base --chown=sveltekit:sveltekit /usr/src/app/apps/web/static ./static
# Switch to non-root user
USER sveltekit
# Expose the port that the app runs on
EXPOSE 5173
# Set environment variables
ENV NODE_ENV=production
ENV PORT=5173
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD bun --version || exit 1
# Start the application
CMD ["bun", "./build/index.js"]