FROM golang:1.20-alpine AS build

# Install dependencies
RUN apk update && \
    apk upgrade && \
    apk add --no-cache bash git openssh make build-base

RUN go env -w CGO_ENABLED="1"

WORKDIR /build

RUN git clone https://code.wuban.net.cn/odysseus/power-node  && \
    git clone https://code.wuban.net.cn/odysseus/odysseus-protocol

RUN  cd /build/power-node

WORKDIR /build/power-node

RUN  sh build.sh && cp /build/power-node/powerNode /powerNode

RUN  cp config.json /config.json && mkdir /conf && cp conf/app.conf /conf/app.conf

RUN  cp start.sh /start.sh

FROM alpine

WORKDIR /root

COPY --from=build /start.sh /root/start.sh

COPY --from=build /powerNode /usr/bin/powerNode

COPY --from=build /config.json /root/config.json

COPY --from=build /conf /root/conf

RUN apk add --update curl

# Expose the port that the application listens on
EXPOSE 9090

RUN chmod +x /root/start.sh

CMD [ "/bin/sh","/root/start.sh"]