From efcaccc0c2edb0d2bc638b47ee075f3d47967385 Mon Sep 17 00:00:00 2001 From: Denshooter Date: Sun, 23 Feb 2025 17:38:14 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20chore:=20streamline=20Dockerfile=20?= =?UTF-8?q?and=20remove=20redundant=20steps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 5 ----- Dockerfile | 27 +++++++++++++++++++++------ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a7d7163..db3cdfd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -32,11 +32,6 @@ jobs: EOF echo "Created .env file:" && cat .env - - name: Install dependencies - run: npm install - - - - name: Build & Push Docker Image run: | # Nutzt den Branch-Namen aus dem auslösenden Workflow diff --git a/Dockerfile b/Dockerfile index 8ffb440..45aa815 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ -# Use Node.js LTS image as the base -FROM node:current-alpine +# Stage 1: Build +FROM node:current-alpine AS builder # Set working directory WORKDIR /app @@ -7,20 +7,35 @@ WORKDIR /app # Copy package.json and package-lock.json COPY package*.json ./ -# Install dependencies +# Install dependencies including development dependencies RUN npm install # Copy the application code COPY . . -# Copy the .env file -COPY .env .env +# Install type definitions for react-responsive-masonry +RUN npm install --save-dev @types/react-responsive-masonry # Build the Next.js application RUN npm run build +# Stage 2: Production +FROM node:current-alpine + +# Set working directory +WORKDIR /app + +# Copy only the necessary files from the build stage +COPY --from=builder /app/package*.json ./ +COPY --from=builder /app/.next ./.next +COPY --from=builder /app/public ./public +COPY --from=builder /app/.env .env + +# Install only production dependencies +RUN npm install --only=production + # Expose the port the app runs on EXPOSE 3000 # Run the app with the start script -CMD ["npm", "start"] +ENTRYPOINT [ "npm", "run", "start" ] \ No newline at end of file