forked from E-cercise/E-cercise-Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
55 lines (42 loc) · 1.1 KB
/
Dockerfile
File metadata and controls
55 lines (42 loc) · 1.1 KB
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
# Set the Go version as a build argument
ARG GO_VERSION=1.23
# Stage 1: Build the Go application
FROM golang:${GO_VERSION}-alpine AS builder
ARG SERVICE_PORT="8888"
ARG TARGETARCH=amd64
RUN apk add --no-cache tzdata
ENV CGO_ENABLED=0 GO111MODULE=on GOOS=linux GOARCH=$TARGETARCH
WORKDIR /app
# Copy the Go application source code
COPY go.mod go.sum ./
RUN go mod tidy
COPY . .
RUN go build -installsuffix cgo -ldflags '-s -w' -o main ./main.go
FROM alpine:3.17
ARG SERVICE_PORT="80"
ENV PORT=${SERVICE_PORT}
# Install necessary packages
RUN apk add --no-cache \
bash \
gettext \
curl \
tzdata \
openssl \
postgresql-client
# Set the working directory
WORKDIR /app
# Create an empty .env file
RUN touch .env
# Add User
RUN addgroup -S application
RUN adduser -S user -G application
RUN chown -R user:application /app
USER user
# Copy the compiled Go binary and other resources
COPY --from=builder /app/main ./main
COPY --from=builder /app/script/. ./script/.
COPY --from=builder /app/src/. ./src/.
# Expose the specified service port
EXPOSE $PORT
# Run the compiled Go binary
CMD ["./main"]