FROM golang:1.20 AS builder
WORKDIR /app
COPY . .
ARG GOODS=linux
ARG GOARCH=amd64

RUN go env -w GOPROXY=https://goproxy.cn,direct

RUN --mount=type=cache,target=/go --mount=type=cache,target=/root/.cache/go-build \
    GOODS=${GOODS} GOARCH=${GOARCH}  go build -o /app/app  app.go

FROM registry.cn-hangzhou.aliyuncs.com/tuon-pub/nginx:1.25.1

WORKDIR /app
COPY --from=builder /app/app /app
COPY conf /app/conf
COPY data  /app/data
#COPY ../server/static  /app/static
COPY frontend/dist  /app/static/web
COPY docker/entrypoint.sh /entrypoint.sh

RUN chmod +x /entrypoint.sh /app/app

RUN rm -rf /app/static/web/config.js
RUN rm -rf /etc/nginx/conf.d
RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/*
RUN sed -i 's/security.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/*
RUN apt -qq update && apt -qq install -y --no-install-recommends ca-certificates curl

ENTRYPOINT ["/entrypoint.sh"]