Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +17 -42
Dockerfile
CHANGED
|
@@ -1,49 +1,24 @@
|
|
| 1 |
-
|
| 2 |
-
FROM golang:1.22.3 AS builder
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
|
| 11 |
-
RUN go mod download
|
| 12 |
-
|
| 13 |
-
# Copy the source from the current directory to the Working Directory inside the container
|
| 14 |
-
COPY . .
|
| 15 |
-
|
| 16 |
-
# Build the Go app
|
| 17 |
-
RUN go build -o main main.go
|
| 18 |
-
|
| 19 |
-
# Debug step: list the contents of the /app directory
|
| 20 |
-
RUN ls -al /app
|
| 21 |
|
| 22 |
-
|
| 23 |
-
FROM debian:latest
|
| 24 |
-
|
| 25 |
-
# Install ca-certificates to make HTTPS requests
|
| 26 |
-
RUN apt-get update && apt-get install -y ca-certificates
|
| 27 |
-
|
| 28 |
-
# Set the Current Working Directory inside the container
|
| 29 |
-
WORKDIR /root/
|
| 30 |
-
|
| 31 |
-
# Copy the Pre-built binary file from the previous stage
|
| 32 |
-
COPY --from=builder /app/main .
|
| 33 |
|
| 34 |
-
|
| 35 |
-
RUN chmod +x /root/main
|
| 36 |
|
| 37 |
-
|
| 38 |
-
RUN
|
| 39 |
|
| 40 |
-
|
| 41 |
-
RUN file /root/main
|
| 42 |
|
| 43 |
-
|
| 44 |
-
USER root
|
| 45 |
-
# Expose port 8080 to the outside world
|
| 46 |
-
EXPOSE 8080
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
| 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 |
+
COPY . /app
|
|
|
|
| 13 |
|
| 14 |
+
RUN go build -o main .
|
| 15 |
+
RUN chmod +x /app/main
|
| 16 |
|
| 17 |
+
FROM alpine:latest
|
|
|
|
| 18 |
|
| 19 |
+
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
COPY --from=builder /app/main /app/
|
| 22 |
+
RUN ls -l /app
|
| 23 |
+
RUN pwd
|
| 24 |
+
CMD ["./main"]
|