2021-11-12 16:26:16 +00:00
|
|
|
FROM golang:1.17.3-alpine as builder
|
2020-06-02 15:45:21 +00:00
|
|
|
|
2020-09-03 11:14:08 +00:00
|
|
|
# Set the Current Working Directory inside the container
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
# Copy go mod and sum files
|
|
|
|
COPY go.mod go.sum ./
|
2020-06-02 15:45:21 +00:00
|
|
|
|
2020-09-03 11:14:08 +00:00
|
|
|
# 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
|
2020-06-02 15:45:21 +00:00
|
|
|
COPY . .
|
2021-11-12 16:26:16 +00:00
|
|
|
ARG VERSION="0.0.0"
|
2021-06-05 09:01:02 +00:00
|
|
|
RUN apk --no-cache add musl-dev gcc build-base
|
2021-11-12 16:26:16 +00:00
|
|
|
RUN go install github.com/99designs/gqlgen@v0.14.0
|
2021-06-04 17:09:33 +00:00
|
|
|
RUN go generate ./...
|
2021-11-12 16:37:43 +00:00
|
|
|
RUN go build -ldflags="-X 'main.Version=$VERSION'" -o twhelpapi ./cmd/api
|
2020-06-02 15:45:21 +00:00
|
|
|
|
2020-09-03 11:14:08 +00:00
|
|
|
######## Start a new stage from scratch #######
|
2021-05-05 18:19:56 +00:00
|
|
|
FROM alpine:latest
|
2020-09-03 11:14:08 +00:00
|
|
|
|
|
|
|
RUN apk --no-cache add ca-certificates
|
|
|
|
|
|
|
|
WORKDIR /root/
|
|
|
|
|
|
|
|
# Copy the Pre-built binary file from the previous stage
|
2021-05-05 18:19:56 +00:00
|
|
|
COPY --from=builder /app/twhelpapi .
|
2020-09-03 11:14:08 +00:00
|
|
|
|
2021-05-05 18:19:56 +00:00
|
|
|
ENV APP_MODE=production
|
2020-09-03 11:14:08 +00:00
|
|
|
ENV GIN_MODE=release
|
2020-06-05 15:17:46 +00:00
|
|
|
EXPOSE 8080
|
|
|
|
|
2020-06-02 15:45:21 +00:00
|
|
|
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.2.1/wait ./wait
|
|
|
|
RUN chmod +x ./wait
|
|
|
|
|
2021-05-05 18:19:56 +00:00
|
|
|
CMD ./wait && ./twhelpapi
|