-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathContainerfile
39 lines (29 loc) · 1.1 KB
/
Containerfile
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
# Stage 1: Build the Go binary
FROM golang:alpine AS builder
# Required for alpine + sqlite3 driver
ENV CGO_ENABLED=1
RUN apk add --no-cache gcc musl-dev
# Set the Current Working Directory inside the container
WORKDIR /app
# Copy only the files needed for dependency resolution
COPY go.mod go.sum ./
RUN go mod download
# Copy the rest of the source code
COPY . .
# Build the Go app with necessary flags for static linking (cause I'm gonna be using scratch)
RUN go build -trimpath -ldflags='-s -w -extldflags "-static"' -o /app/expenses-app cmd/main.go
# Stage 2: Run the Go binary in a minimal environment
FROM scratch
ARG IMAGE_TAG
ENV IMAGE_TAG=$IMAGE_TAG
# Set the Current Working Directory inside the container
WORKDIR /app
# Copy the required files and directories from the build stage
COPY --from=builder /app/expenses-app /app/expenses-app
COPY --from=builder /app/views /app/views
COPY --from=builder /app/public /app/public
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Expose the port the app runs on
EXPOSE 3535
# Command to run the executable
ENTRYPOINT ["/app/expenses-app"]