From aac6837147b727d5a3a6c6dac112c2bc280c2e0e Mon Sep 17 00:00:00 2001 From: afeiszli Date: Tue, 16 Nov 2021 22:18:24 -0500 Subject: [PATCH] docker working --- docker/Dockerfile-netclient-full | 45 ++++++++++++++++++++------------ docker/Dockerfile-userspace | 2 +- scripts/netclient.sh | 13 +++++++-- 3 files changed, 41 insertions(+), 19 deletions(-) mode change 100644 => 100755 scripts/netclient.sh diff --git a/docker/Dockerfile-netclient-full b/docker/Dockerfile-netclient-full index c8fa9233..642c2864 100644 --- a/docker/Dockerfile-netclient-full +++ b/docker/Dockerfile-netclient-full @@ -1,26 +1,39 @@ -#first stage - builder +FROM gravitl/builder:latest as builder +# add glib support daemon manager +WORKDIR /app -FROM golang:latest as builder - -COPY . /app - -WORKDIR /app/netclient +COPY . . ENV GO111MODULE=auto -RUN CGO_ENABLED=0 GOOS=linux go build -o netclient main.go - -#second stage - -FROM debian:latest - -RUN apt-get update && apt-get -y install systemd procps +RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 /usr/local/go/bin/go build -ldflags="-w -s" -o netclient-app netclient/main.go WORKDIR /root/ -COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +RUN apk add --update git build-base libmnl-dev iptables -COPY --from=builder /app/netclient/netclient . +RUN git clone https://git.zx2c4.com/wireguard-go && \ + cd wireguard-go && \ + make && \ + make install -CMD ["./netclient"] +ENV WITH_WGQUICK=yes +RUN git clone https://git.zx2c4.com/wireguard-tools && \ + cd wireguard-tools && \ + cd src && \ + make && \ + make install +FROM alpine:3.13.6 + +WORKDIR /root/ + +RUN apk add --no-cache --update bash libmnl iptables openresolv iproute2 +COPY --from=builder /usr/bin/wireguard-go /usr/bin/wg* /usr/bin/ +COPY --from=builder /app/netclient-app ./netclient +COPY --from=builder /app/scripts/netclient.sh . +RUN chmod 0755 netclient && chmod 0755 netclient.sh + +ENV WG_QUICK_USERSPACE_IMPLEMENTATION=wireguard-go + +ENTRYPOINT ["/bin/sh", "./netclient.sh"] diff --git a/docker/Dockerfile-userspace b/docker/Dockerfile-userspace index 9307caba..1da2198a 100644 --- a/docker/Dockerfile-userspace +++ b/docker/Dockerfile-userspace @@ -21,6 +21,6 @@ FROM gravitl/netmaker:${NM_VERSION} RUN apk add --no-cache --update bash libmnl iptables openresolv iproute2 COPY --from=builder /usr/bin/wireguard-go /usr/bin/wg* /usr/bin/ -COPY scripts/userspace-entrypoint.sh ./entrypoint.sh +COPY scripts/netclient.sh ./entrypoint.sh ENTRYPOINT ["/bin/sh", "./entrypoint.sh"] diff --git a/scripts/netclient.sh b/scripts/netclient.sh old mode 100644 new mode 100755 index 1b64dae5..05dd728d --- a/scripts/netclient.sh +++ b/scripts/netclient.sh @@ -1,13 +1,22 @@ #!/bin/sh echo "[netclient] joining network" -/etc/netclient/netclient join -t $NETCLIENT_ACCESSTOKEN -daemon off -dnson no +if [ -z "${SLEEP}" ]; then + SLEEP=10 +fi + +TOKEN_CMD="" +if [ "$TOKEN" != "" ]; then + TOKEN_CMD="-t $TOKEN" +fi + +/root/netclient join $TOKEN_CMD -daemon off -dnson no echo "[netclient] Starting netclient checkin" # loop and call checkin -n all while [ 1 ]; do # add logs to netclient.logs - /etc/netclient/netclient checkin -n all + /root/netclient checkin -n all sleep $SLEEP done echo "[netclient] exiting"