-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
55 lines (40 loc) · 1.42 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Stage 1: Build stage
FROM node:20 AS build
# Define build argument
ARG NODE_ENV
# Set environment variable
ENV NODE_ENV=${NODE_ENV}
ENV PORT=8080
# Install tzdata and set timezone
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata
RUN ln -fs /usr/share/zoneinfo/Asia/Jakarta /etc/localtime && dpkg-reconfigure -f noninteractive tzdata
# Create app directory
WORKDIR /opt/app
# Copy package.json and package-lock.json
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy the rest of the application code
COPY . .
# Generate Prisma client
RUN npm install -g dotenv-cli
RUN npx prisma generate
RUN dotenv -e .env.${NODE_ENV} -- npx prisma migrate deploy
# Stage 2: Run stage
# FROM gcr.io/distroless/nodejs20-debian12
# FROM node:20-slim
# Install tzdata and set timezone
# RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata
# RUN ln -fs /usr/share/zoneinfo/Asia/Jakarta /etc/localtime && dpkg-reconfigure -f noninteractive tzdata
# Copy built files from the build stage
# COPY --from=build /opt/app /opt/app
# Set the working directory
# WORKDIR /opt/app
# Set environment variable for runtime
# ENV NODE_ENV=${NODE_ENV}
# ENV PORT=8080
ENV TZ=Asia/Jakarta
# Expose the port
EXPOSE 8080
# Run the application using shell to ensure the environment variable is picked up
CMD ["sh", "-c", "npm run start:${NODE_ENV}"]