# syntax=docker/dockerfile:1.3

ARG BASE_IMAGE=registry.openanolis.cn/openanolis/anolisos:23.2

FROM ${BASE_IMAGE} AS builder

WORKDIR /usr/src/trustee

COPY . .

RUN yum install -y wget ca-certificates gcc

RUN wget https://go.dev/dl/go1.21.6.linux-amd64.tar.gz && \
    sha256sum go1.21.6.linux-amd64.tar.gz > go1.21.6.linux-amd64.tar.gz.sha256 && \
    sha256sum -c go1.21.6.linux-amd64.tar.gz.sha256 && \
    rm -rf /usr/local/go && \
    tar -C /usr/local -xzf go1.21.6.linux-amd64.tar.gz

ENV PATH=$PATH:/usr/local/go/bin

RUN go env -w GOPROXY=https://mirrors.aliyun.com/goproxy

RUN cd trustee-gateway && CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -ldflags="-s -w" -o gateway cmd/server/main.go

FROM ${BASE_IMAGE}

RUN yum install -y ca-certificates tzdata sqlite-libs

WORKDIR /app

COPY --from=builder /usr/src/trustee/trustee-gateway/gateway /app/
COPY --from=builder /usr/src/trustee/trustee-gateway/config.yaml /app/

VOLUME /app/data

EXPOSE 8081

ENV GIN_MODE=release

CMD ["./gateway", "--config", "/app/config.yaml"] 
