Skip to content

Commit

Permalink
Merge pull request #24 from ramprasathmk/test_branch
Browse files Browse the repository at this point in the history
  • Loading branch information
ramprasathmk authored Feb 2, 2025
2 parents 7d7abfe + 49804d2 commit 1c597c0
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 35 deletions.
81 changes: 49 additions & 32 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,42 +1,59 @@
# syntax=docker/dockerfile:1.4
# syntax=docker/dockerfile:1

# Use nodejs version
ARG NODE_VERSION=20.10.0
ARG NODE_VERSION=18

# use the official node.js image
FROM node:${NODE_VERSION}-alpine as development
################################################################################
# Base image for all stages
FROM node:${NODE_VERSION}-alpine AS base

# Environment variable for the container
ENV NODE_ENV production

# set the working directory in the container
# Set the working directory
WORKDIR /usr/src/app

# install dependencies
COPY package.json /usr/src/app/package.json
COPY package-lock.json /usr/src/app/package-lock.json
# Install essential build tools
# * The Container size should be reduced while commenting the below command
# TODO: Uncomment after checking the size of the container
# RUN apk add --no-cache python3 make g++

################################################################################
# Dependencies stage
FROM base AS deps

# Copy package.json and package-lock.json for dependency installation
COPY package.json package-lock.json* ./

# Install only production dependencies for optimized builds
RUN npm ci --only=production

################################################################################
# Build stage (if needed for assets or complex builds)
FROM base AS build

# Copy all source files for building
COPY . .

# Install full dependencies for building (including devDependencies)
RUN npm ci

COPY . /usr/src/app
# ? Example build step (if your project has one)
# RUN npm run build

EXPOSE 3000
################################################################################
# Production stage (final)
FROM base AS final

# Set environment to production
ENV NODE_ENV=production

# * Switch to non-root user for security
USER node

# * Copy only essential files from previous stages
COPY package.json .
COPY --from=deps /usr/src/app/node_modules ./node_modules
COPY --from=build /usr/src/app .

# Expose the app port
EXPOSE 3000

# Run command
CMD [ "npm", "run", "dev" ]

# dev Env
FROM development as dev-envs
RUN <<EOF
apt-get update
apt-get install -y --no-install-recommends git
EOF

RUN <<EOF
useradd -s /bin/bash -m vscode
groupadd docker
usermod -aG docker vscode
EOF
# install Docker tools (cli, buildx, compose)
COPY --from=gloursdocker/docker / /
CMD [ "npm", "run", "dev" ]
# Start the application
CMD ["npm", "start"]
17 changes: 14 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3'
version: '3.8'

services:
# web
Expand All @@ -10,16 +10,27 @@ services:
- "3000:3000"
networks:
- poet-app-network
environment:
- NODE_ENV=production
volumes:
- .:/usr/src/app
command: ["npm", "run", "dev"] # Dev mode for live code changes

# db
mongo:
image: mongo:latest
image: mongo:6.0
ports:
- "27017:27017"
networks:
- poet-app-network
volumes:
- mongo-data:/data/db

# network
networks:
poet-app-network:
driver: bridge
driver: bridge

# volumes
volumes:
mongo-data:

0 comments on commit 1c597c0

Please sign in to comment.