ilhamdev commited on
Commit
62c4c40
·
verified ·
1 Parent(s): 96b64e3

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +30 -12
Dockerfile CHANGED
@@ -1,10 +1,28 @@
1
- # Gunakan image Node.js versi 18 berbasis Alpine yang ringan
2
- FROM node:18-alpine
 
 
 
3
 
4
- # Setel direktori kerja di dalam kontainer
5
  WORKDIR /app
6
 
7
- # Install alat-alat yang diperlukan sekaligus dependencies sistem
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  RUN apk add --no-cache \
9
  git \
10
  python3 \
@@ -15,17 +33,17 @@ RUN apk add --no-cache \
15
  ttf-freefont \
16
  ffmpeg
17
 
18
- # Salin file package.json dan package-lock.json
19
- COPY package*.json ./
20
 
21
- # Instal dependensi dengan NPM menggunakan argumen --production untuk hanya instalasi dependensi produksi
22
- RUN npm install
23
 
24
- # Salin file dan direktori lain ke dalam kontainer
25
- COPY . .
26
 
27
- # Menyediakan port yang akan digunakan aplikasi
28
  EXPOSE 7860
29
 
30
- # Perintah untuk menjalankan aplikasi
31
  CMD ["node", "index.js"]
 
1
+ # Stage 1: Build Stage
2
+ FROM node:18-alpine AS build
3
+
4
+ # Set environment variables for Node.js
5
+ ENV NODE_ENV=production
6
 
7
+ # Set working directory
8
  WORKDIR /app
9
 
10
+ # Copy package.json and package-lock.json
11
+ COPY package*.json ./
12
+
13
+ # Install production dependencies
14
+ RUN npm install --only=production
15
+
16
+ # Copy the entire application
17
+ COPY . .
18
+
19
+ # Remove any development dependencies to keep the build clean
20
+ RUN npm prune --production
21
+
22
+ # Stage 2: Final Stage
23
+ FROM node:18-alpine
24
+
25
+ # Install required system packages
26
  RUN apk add --no-cache \
27
  git \
28
  python3 \
 
33
  ttf-freefont \
34
  ffmpeg
35
 
36
+ # Clean up package cache to keep image size small
37
+ RUN rm -rf /var/cache/apk/*
38
 
39
+ # Set the working directory
40
+ WORKDIR /app
41
 
42
+ # Copy only the necessary files from the build stage
43
+ COPY --from=build /app .
44
 
45
+ # Expose the port the app runs on
46
  EXPOSE 7860
47
 
48
+ # Command to run the application
49
  CMD ["node", "index.js"]