File size: 922 Bytes
164cc3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a3e77a9
 
 
 
 
 
164cc3b
 
 
897bab5
 
 
164cc3b
 
 
 
 
 
 
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
# Gunakan image dasar Golang versi 1.24.1
FROM golang:1.24.1 AS builder

# Set working directory
WORKDIR /app

# Copy go.mod dan go.sum
COPY go.mod go.sum ./

# Download dependencies
RUN go mod download

# Copy seluruh kode
COPY . .

# Build aplikasi
# RUN go build -o /app/main .

# Build aplikasi untuk Linux
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /app/main .

# Stage 2: Gunakan image runtime yang lebih kecil
FROM alpine:latest

# Set working directory
WORKDIR /app

# Install tzdata
RUN apk update && apk add --no-cache tzdata

# Set the timezone environment variable
ENV TZ="Asia/Jakarta"

# Copy hasil build dari builder ke image runtime
COPY --from=builder /app/main .

# Copy folder utils (termasuk file seeder) dari builder ke runtime
COPY --from=builder /app/utils ./utils

# Copy file .env untuk konfigurasi environment
COPY .env .env

RUN chmod +x /app/main

# Jalankan aplikasi
CMD ["./main"]