FROM debian:bullseye as frp

ENV FRP_VERSION=0.37.1
WORKDIR /usr/src/app
ADD https://github.com/fatedier/frp/releases/download/v${FRP_VERSION}/frp_${FRP_VERSION}_linux_amd64.tar.gz ./
RUN tar xf frp_${FRP_VERSION}_linux_amd64.tar.gz
RUN mv frp_${FRP_VERSION}_linux_amd64 frp

# https://github.com/masipcat/wireguard-go-docker/blob/master/Dockerfile
FROM golang:1.16-buster as wireguard

ARG wg_go_tag=0.0.20210424
ARG wg_tools_tag=v1.0.20210424

RUN git clone --depth 1 --branch $wg_go_tag https://git.zx2c4.com/wireguard-go && \
    cd wireguard-go && \
    make && \
    make install

ENV WITH_WGQUICK=yes
RUN git clone --depth 1 --branch $wg_tools_tag https://git.zx2c4.com/wireguard-tools && \
    cd wireguard-tools && \
    cd src && \
    make && \
    make install


FROM debian:bullseye

RUN apt update && apt install --no-install-recommends -y \
  supervisor openssh-server python3 iptables iproute2 \
  && rm -rf /var/lib/apt/lists/*

COPY --from=frp /usr/src/app/frp /opt/frp
RUN mkdir -p /var/run/sshd
COPY --from=wireguard /usr/bin/wireguard-go /usr/bin/wg* /usr/bin/

COPY supervisord.conf /etc/supervisord.conf

EXPOSE 22
CMD ["/usr/bin/supervisord"]