34 lines
850 B
Docker
34 lines
850 B
Docker
FROM golang:1.17-alpine3.16 as builder
|
|
|
|
# Set the Current Working Directory inside the container
|
|
WORKDIR /app
|
|
|
|
# Copy go mod and sum files
|
|
COPY go.mod go.sum ./
|
|
|
|
# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
|
|
RUN go mod download
|
|
|
|
# Copy the source from the current directory to the Working Directory inside the container
|
|
COPY . .
|
|
RUN apk --no-cache add musl-dev gcc build-base
|
|
RUN go install github.com/99designs/gqlgen@v0.14.0
|
|
RUN go generate ./...
|
|
ENV CGO_ENABLED=0
|
|
RUN go build -o zdamegzawodowy ./cmd/server
|
|
|
|
######## Start a new stage from scratch #######
|
|
FROM alpine:3.16
|
|
|
|
RUN apk --no-cache add ca-certificates
|
|
|
|
WORKDIR /root/
|
|
|
|
# Copy the Pre-built binary file from the previous stage
|
|
COPY --from=builder /app/zdamegzawodowy .
|
|
|
|
ENV APP_MODE=production
|
|
EXPOSE 8080
|
|
|
|
CMD ./zdamegzawodowy
|