FROM golang:1.22 AS builder

ENV SOURCE_PATH ${GOPATH}/src/0xacab.org/leap/obfsvpn
COPY . ${SOURCE_PATH}/
WORKDIR ${SOURCE_PATH}
RUN CGO_ENABLED=0 go build -o obfsvpn-client ./cmd/client/ && cp obfsvpn-client /obfsvpn-client

ENV NDT7_COMMIT v0.8.0
RUN git clone https://github.com/m-lab/ndt7-client-go.git && cd ndt7-client-go && git reset --hard $NDT7_COMMIT
RUN cd ndt7-client-go && CGO_ENABLED=0 go build -o ndt7-client ./cmd/ndt7-client && cp ndt7-client /ndt7-client

FROM alpine:3.14.1

ENV OBFS4_CERT1 "8nuAbPJwFrKc/29KcCfL5LBuEWxQrjBASYXdUbwcm9d9pKseGK4r2Tg47e23+t6WghxGGw"

ENV OBFS4_CERT2 "8nuAbPJwFrKc/29KcCfL5LBuEWxQrjBASYXdUbwcm9d9pKseGK4r2Tg47e23+t6WghxGGw"
# copy obfsvpn-client from builder
COPY --from=builder /obfsvpn-client /usr/bin/
COPY --from=builder /ndt7-client /usr/bin/

# Install openvpn
RUN apk --no-cache --no-progress upgrade && \
    apk --no-cache --no-progress add bash curl ip6tables iptables openvpn bind-tools iperf3 \
                shadow dumb-init tzdata && \
    addgroup -S vpn && \
    rm -rf /tmp/*

COPY images/obfsvpn-client/start.sh /usr/bin/

VOLUME ["/vpn"]

# FIXME: I should not need to create the volume here and copy the required files into /livetest
# it should be done on the docker compose layer instead
VOLUME ["/livetest"]
COPY images/obfsvpn-client/data/ /livetest/

ENTRYPOINT ["dumb-init"]

