Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimised the Docker File #623

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# Use small Alpine Linux image
FROM node:12-alpine
# Stage 1: Build the application
FROM node:12-alpine AS builder

# Set environment variables
ENV PORT=5000
ARG CLIENT_ID

COPY . app/

WORKDIR app/
WORKDIR /app

# Make sure dependencies exist for Webpack loaders
# Install dependencies needed for building the application
RUN apk add --no-cache \
autoconf \
automake \
Expand All @@ -20,13 +18,31 @@ RUN apk add --no-cache \
libpng-dev \
make \
nasm
RUN npm ci --only-production --silent

# Copy package files first to leverage Docker cache
COPY package*.json ./
RUN npm install --production --silent

# Copy the rest of the application code
COPY . .

# Build production client side React application
RUN npm run build

# Stage 2: Create the final image
FROM node:12-alpine

# Set environment variables
ENV PORT=5000

WORKDIR /app

# Copy only the built files and necessary dependencies from the builder stage
COPY --from=builder /app/build ./build
COPY --from=builder /app/node_modules ./node_modules

# Expose port for Node
EXPOSE $PORT

# Start Node server
ENTRYPOINT npm run prod
CMD ["npm", "run", "prod"]