Skip to content
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
31 changes: 27 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,44 @@
FROM node:16.10.0 AS build
# -------- Stage 1: Build Angular app --------
FROM node:16.10.0-slim AS build

WORKDIR /app

# Install Angular CLI
RUN npm install -g @angular/cli@13.3.0

# Copy package files first (for caching)
COPY package*.json ./

# Install dependencies
RUN npm install

# Copy rest of code
COPY . .

# Build Angular app
RUN ng build --configuration=production

# Stage 2: Create a lightweight container with Node.js to serve the Angular application
FROM node:16.10.0 AS final

# -------- Stage 2: Serve app securely --------
FROM node:16.10.0-slim AS final

# Create non-root user
RUN useradd -m appuser

WORKDIR /usr/src/app
COPY --from=build /app/dist/template-validation-portal/* ./dist/

# Copy build output
COPY --from=build /app/dist/template-validation-portal ./dist

# Install serve
RUN npm install -g serve

# Fix permissions
RUN chown -R appuser:appuser /usr/src/app

# Switch to non-root
USER appuser

EXPOSE 3111

CMD ["serve", "-s", "dist", "-p", "3111"]