Refactor Dockerfile to streamline build process by removing unnecessary stages and commands; update npm installation method for improved efficiency.
This commit is contained in:
parent
e095df4b54
commit
46dcc1a0b3
45
Dockerfile
45
Dockerfile
|
|
@ -1,42 +1,7 @@
|
||||||
FROM node:18-alpine AS builder
|
|
||||||
|
|
||||||
# Create app directory
|
|
||||||
RUN mkdir -p /app
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Copy package files first for better caching
|
|
||||||
COPY package*.json ./
|
|
||||||
|
|
||||||
# Install dependencies
|
|
||||||
RUN npm ci --only=production
|
|
||||||
|
|
||||||
# Copy source code
|
|
||||||
COPY . .
|
|
||||||
|
|
||||||
# Production stage
|
|
||||||
FROM node:18-alpine
|
FROM node:18-alpine
|
||||||
|
|
||||||
# Create app directory
|
|
||||||
RUN mkdir -p /app
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Copy built application from builder stage
|
|
||||||
COPY --from=builder /app .
|
|
||||||
|
|
||||||
# Create non-root user for security
|
|
||||||
RUN addgroup -g 1001 -S nodejs && \
|
|
||||||
adduser -S nodejs -u 1001
|
|
||||||
|
|
||||||
# Change ownership of the app directory to nodejs user
|
|
||||||
RUN chown -R nodejs:nodejs /app
|
|
||||||
USER nodejs
|
|
||||||
|
|
||||||
# Expose the port the app runs on
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
WORKDIR /app
|
||||||
# Health check
|
COPY ./package.json .
|
||||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
COPY ./package-lock.json .
|
||||||
CMD node -e "require('http').get('http://localhost:8080/', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) })"
|
RUN npm install
|
||||||
|
CMD ["npm", "start"]
|
||||||
# Start the application
|
|
||||||
CMD ["npm", "start"]
|
|
||||||
|
|
@ -9,7 +9,7 @@ const bigquery = new BigQuery({
|
||||||
});
|
});
|
||||||
const storage = new Storage({
|
const storage = new Storage({
|
||||||
projectId: process.env.PROJECT_ID || "fynd-jio-commerceml-prod",
|
projectId: process.env.PROJECT_ID || "fynd-jio-commerceml-prod",
|
||||||
credentials: {}
|
credentials: process.env.GCS_CREDENTIALS || {}
|
||||||
});
|
});
|
||||||
|
|
||||||
export const exportMergedJson = async (req, res) => {
|
export const exportMergedJson = async (req, res) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user