-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
37 lines (27 loc) Β· 986 Bytes
/
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
# Use an official Go runtime as a parent image
FROM golang:1.23 AS BUILDER
# Set the Current Working Directory inside the container
WORKDIR /app
# Copy the Go Modules manifest (go.mod) and download dependencies
COPY go.mod go.sum ./
RUN go mod download
# Copy the source code to the container
COPY . .
# Ensure the Go binaries are built for Linux (even if building on macOS)
ENV GOOS=linux
ENV GOARCH=amd64
# Build the Go app and place the binaries in the build directory
RUN mkdir -p build
RUN go build -o build/godis-server ./cmd/server
RUN go build -o build/godis-cli ./cmd/client
# Use a lightweight image for the final container
FROM alpine:3.18
# Set the Current Working Directory inside the container
WORKDIR /app
# Copy the binaries and Makefile from the builder stage
COPY --from=BUILDER /app/build /app/build/
COPY --from=BUILDER /app/Makefile /app/
# Expose the port the server will run on
EXPOSE 5001
# Command to run the server binary
CMD ["./build/godis-server"]