Dockerfile 780 B

12345678910111213141516171819202122232425262728
  1. # Dockerfile References: https://docs.docker.com/engine/reference/builder/
  2. # Start from the latest golang base image
  3. FROM golang:1.18.3-alpine as builder
  4. # Set the Current Working Directory inside the container
  5. WORKDIR /app
  6. # Copy go mod and sum files
  7. COPY go.mod go.sum ./
  8. # Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
  9. RUN go mod download
  10. # Copy the source from the current directory to the Working Directory inside the container
  11. COPY . .
  12. # Build the Go app
  13. RUN CGO_ENABLED=0 GOOS=linux go build -v -a -installsuffix cgo -o swag cmd/swag/main.go
  14. ######## Start a new stage from scratch #######
  15. FROM scratch
  16. WORKDIR /root/
  17. # Copy the Pre-built binary file from the previous stage
  18. COPY --from=builder /app/swag .