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.
This commit is contained in:
2
.github/workflows/deploy.yml
vendored
2
.github/workflows/deploy.yml
vendored
@@ -25,7 +25,7 @@ jobs:
|
|||||||
- name: Build and push Docker image
|
- name: Build and push Docker image
|
||||||
uses: docker/build-push-action@v4
|
uses: docker/build-push-action@v4
|
||||||
with:
|
with:
|
||||||
context: ./apps/web
|
context: .
|
||||||
file: ./Dockerfile
|
file: ./Dockerfile
|
||||||
push: true
|
push: true
|
||||||
# Make sure to replace with your own namespace and repository
|
# Make sure to replace with your own namespace and repository
|
||||||
|
|||||||
26
Dockerfile
26
Dockerfile
@@ -8,19 +8,30 @@ WORKDIR /usr/src/app
|
|||||||
RUN addgroup --system --gid 1001 sveltekit
|
RUN addgroup --system --gid 1001 sveltekit
|
||||||
RUN adduser --system --uid 1001 sveltekit
|
RUN adduser --system --uid 1001 sveltekit
|
||||||
|
|
||||||
# Copy package.json and bun.lockb (if available)
|
# Copy package.json and bun.lock (if available)
|
||||||
COPY package.json bun.lockb* ./
|
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)
|
# 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
|
RUN bun install --frozen-lockfile
|
||||||
|
|
||||||
# Copy the source code
|
# Copy the rest of the source code
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Prepare SvelteKit and build the application
|
# 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 prepare
|
||||||
RUN bun run build
|
RUN bun run build
|
||||||
RUN bun run db:migrate
|
|
||||||
|
|
||||||
# Production stage
|
# Production stage
|
||||||
FROM oven/bun:1-slim AS production
|
FROM oven/bun:1-slim AS production
|
||||||
@@ -33,12 +44,13 @@ RUN addgroup --system --gid 1001 sveltekit
|
|||||||
RUN adduser --system --uid 1001 sveltekit
|
RUN adduser --system --uid 1001 sveltekit
|
||||||
|
|
||||||
# Copy built application from base stage
|
# Copy built application from base stage
|
||||||
COPY --from=base --chown=sveltekit:sveltekit /usr/src/app/build ./build
|
COPY --from=base --chown=sveltekit:sveltekit /usr/src/app/apps/web/build ./build
|
||||||
COPY --from=base --chown=sveltekit:sveltekit /usr/src/app/package.json ./package.json
|
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 --from=base --chown=sveltekit:sveltekit /usr/src/app/node_modules ./node_modules
|
||||||
|
|
||||||
# Copy any additional files needed for runtime
|
# Copy any additional files needed for runtime
|
||||||
COPY --from=base --chown=sveltekit:sveltekit /usr/src/app/static ./static
|
COPY --from=base --chown=sveltekit:sveltekit /usr/src/app/apps/web/static ./static
|
||||||
|
|
||||||
# Switch to non-root user
|
# Switch to non-root user
|
||||||
USER sveltekit
|
USER sveltekit
|
||||||
|
|||||||
Reference in New Issue
Block a user