FROM golang:1.13 AS builder

WORKDIR /workspace
COPY go.mod go.mod
COPY go.sum go.sum
ARG GOPROXY
ARG GOSUMDB
RUN go mod download

COPY cmd cmd/
COPY internal internal/
COPY pkg pkg/
COPY public public/

RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on taskset -c 1 /usr/local/go/bin/go build -a -o q3 ./cmd/q3


FROM alpine:3 AS urt-download

WORKDIR /ut/
RUN apk add --no-cache libxml2-utils=2.13.4-r5 curl=8.12.1-r1 bash=5.2.37-r0
COPY updater-cfg ./
RUN curl -sSLO 'https://raw.githubusercontent.com/FrozenSand/UrTUpdater/master/ded/UrTUpdater_Ded.sh' && bash ./UrTUpdater_Ded.sh -q


FROM alpine:3

RUN apk add --no-cache gcompat=1.1.0-r4
COPY --from=builder /workspace/q3 /usr/local/bin/
COPY --from=urt-download /ut/Quake3-UrT-Ded.x86_64 /usr/local/bin/
COPY --from=urt-download /ut/q3ut4/ /root/.q3a/q3ut4/

# ENTRYPOINT ["/bin/sh"]
ENTRYPOINT ["/usr/local/bin/q3"]
