github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/Dockerfile (about)

     1  # Use a lightweight Linux distribution as the base image
     2  FROM golang:1.21-alpine AS builder
     3  
     4  # Set the working directory inside the container
     5  WORKDIR /build
     6  
     7  # Copy the Go module files
     8  COPY go.mod go.sum ./
     9  COPY apiconfig.json ./
    10  COPY configuration.json ./
    11  # Download the Go module dependencies
    12  RUN go mod download
    13  
    14  # Copy the entire application source
    15  COPY . .
    16  
    17  # Build the Go application
    18  RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o iac-linux
    19  
    20  # Final stage
    21  FROM alpine:latest
    22  
    23  WORKDIR /app
    24  
    25  COPY --from=builder /build/iac-linux /app/iac-linux
    26  COPY --from=builder /build/apiconfig.json /app/apiconfig.json
    27  COPY --from=builder /build/dockerconfiguration.json /app/configuration.json
    28  
    29  # Copy the compiled Go application into the container
    30  #COPY iac-linux /app/    
    31  #COPY apiconfig.json /app/  
    32  #COPY configuration.json /app/  
    33  
    34  
    35  # Set the working directory inside the container
    36  #WORKDIR /app
    37  
    38  # Set permissions on the application (if needed)
    39  #RUN chmod +x iac-linux
    40  RUN chmod +x /app/iac-linux
    41  
    42  # Expose additional ports
    43  EXPOSE 8080
    44  # Define an entry point to run the application
    45  
    46  CMD ["/app/iac-linux"]