Ashad001 commited on
Commit
ca87510
·
verified ·
1 Parent(s): 3fe9b29

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +17 -42
Dockerfile CHANGED
@@ -1,49 +1,24 @@
1
- # Use the official Go image to create a build artifact
2
- FROM golang:1.22.3 AS builder
3
 
4
- # Set the Current Working Directory inside the container
5
- WORKDIR /app
6
-
7
- # Copy go mod and sum files
8
- COPY go.mod go.sum ./
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
- # Use a debian base image to reduce the final image size
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
- # Ensure the main executable has execute permissions
35
- RUN chmod +x /root/main
36
 
37
- # Debug step: list the contents of the /root directory again to confirm permissions
38
- RUN ls -al /root
39
 
40
- # Debug step: show file information
41
- RUN file /root/main
42
 
43
- # Ensure we are running as the root user
44
- USER root
45
- # Expose port 8080 to the outside world
46
- EXPOSE 8080
47
 
48
- # Command to run the executable
49
- CMD ["/root/main"]
 
 
 
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"]