|
| 1 | +# Step 1: Base image for building |
| 2 | +FROM node:22-bullseye-slim AS build |
| 3 | +# Step 2: Set working directory |
| 4 | +WORKDIR /app |
| 5 | +# Step 3: Install dependencies for pnpm |
| 6 | +RUN npm install -g [email protected] # Ensure a specific version of pnpm |
| 7 | +# Step 4: Copy application files |
| 8 | +COPY .npmrc ./ |
| 9 | +COPY .nuxtignore ./ |
| 10 | +COPY package*.json ./ |
| 11 | +COPY pnpm-*.yaml ./ |
| 12 | +COPY *.config.ts ./ |
| 13 | +COPY tsconfig.json ./ |
| 14 | +COPY package.json package.json |
| 15 | +COPY . . |
| 16 | +# Step 5: Clean up old node_modules (if any) and install dependencies |
| 17 | +RUN rm -rf node_modules && pnpm install |
| 18 | +# Step 6: Build the application |
| 19 | +RUN pnpm build |
| 20 | +# Step 7: Use a smaller image for production |
| 21 | +FROM node:22-bullseye-slim AS prod |
| 22 | +# Step 8: Set working directory |
| 23 | +WORKDIR /app |
| 24 | +# Step 9: Install required packages (curl needed for AWS CLI) |
| 25 | +RUN apt-get update && apt-get install -y curl unzip |
| 26 | +# Step 10: Install pnpm (again) to ensure it's available in the production environment |
| 27 | +RUN npm install -g [email protected] # Ensure the same version of pnpm |
| 28 | +# Step 11: Copy built application from build stage |
| 29 | +COPY --from=build /app /app |
| 30 | +# Step 12: Remove unnecessary dev dependencies |
| 31 | +RUN pnpm install |
| 32 | +# Step 13: Install AWS CLI |
| 33 | +RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \ |
| 34 | + && unzip awscliv2.zip \ |
| 35 | + && ./aws/install \ |
| 36 | + && rm -rf awscliv2.zip aws |
| 37 | +# Step 14: Expose port 3000 |
| 38 | +EXPOSE 3000 |
| 39 | +# Step 15: Push output files to S3 before starting the application |
| 40 | +CMD aws s3 sync /app/.output s3://$AWS_S3_BUCKET |
| 41 | +# Step 16: Start the application |
| 42 | +CMD ["pnpm", "start"] |
0 commit comments