Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +16 -13
Dockerfile
CHANGED
|
@@ -1,24 +1,27 @@
|
|
|
|
|
| 1 |
FROM golang:1.22.3 as builder
|
| 2 |
|
| 3 |
-
# Install Go if it's not already installed
|
| 4 |
-
RUN if ! [ -x "$(command -v go)" ]; then echo "Installing Go..." && \
|
| 5 |
-
apk add --no-cache curl && \
|
| 6 |
-
curl -L "https://golang.org/dl/go1.21.linux-amd64.tar.gz" | tar -xz && \
|
| 7 |
-
mv go /usr/local && \
|
| 8 |
-
rm -rf /var/cache/apk/*; fi
|
| 9 |
-
|
| 10 |
WORKDIR /app
|
| 11 |
|
| 12 |
-
|
|
|
|
| 13 |
|
|
|
|
| 14 |
RUN go build -o main .
|
| 15 |
-
RUN chmod +x /app/main
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
FROM alpine:latest
|
| 18 |
|
| 19 |
WORKDIR /app
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Build stage
|
| 2 |
FROM golang:1.22.3 as builder
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
WORKDIR /app
|
| 5 |
|
| 6 |
+
# Copy the source code into the container
|
| 7 |
+
COPY . .
|
| 8 |
|
| 9 |
+
# Build the Go app
|
| 10 |
RUN go build -o main .
|
|
|
|
| 11 |
|
| 12 |
+
# Ensure the binary has execute permissions
|
| 13 |
+
RUN chmod +x main
|
| 14 |
+
|
| 15 |
+
# Final stage
|
| 16 |
FROM alpine:latest
|
| 17 |
|
| 18 |
WORKDIR /app
|
| 19 |
|
| 20 |
+
# Copy the binary from the builder stage
|
| 21 |
+
COPY --from=builder /app/main .
|
| 22 |
+
|
| 23 |
+
# Ensure the binary has execute permissions (redundant but safe)
|
| 24 |
+
RUN chmod +x main
|
| 25 |
+
|
| 26 |
+
# Run the binary
|
| 27 |
+
CMD ["./main"]
|