Browse Source

docker working

afeiszli 3 years ago
parent
commit
aac6837147
3 changed files with 38 additions and 16 deletions
  1. 26 13
      docker/Dockerfile-netclient-full
  2. 1 1
      docker/Dockerfile-userspace
  3. 11 2
      scripts/netclient.sh

+ 26 - 13
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 . .
 
-COPY . /app
+ENV GO111MODULE=auto
 
-WORKDIR /app/netclient
+RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 /usr/local/go/bin/go build -ldflags="-w -s" -o netclient-app netclient/main.go
 
-ENV GO111MODULE=auto
+WORKDIR /root/
 
-RUN CGO_ENABLED=0 GOOS=linux go build -o netclient main.go
+RUN apk add --update git build-base libmnl-dev iptables
 
-#second stage
+RUN git clone https://git.zx2c4.com/wireguard-go && \
+    cd wireguard-go && \
+    make && \
+    make install
 
-FROM debian:latest
+ENV WITH_WGQUICK=yes
+RUN git clone https://git.zx2c4.com/wireguard-tools && \
+    cd wireguard-tools && \
+    cd src && \
+    make && \
+    make install
 
-RUN apt-get update && apt-get -y install systemd procps
+FROM alpine:3.13.6
 
 WORKDIR /root/
 
-COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
-
-COPY --from=builder /app/netclient/netclient .
+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
 
-CMD ["./netclient"]
+ENV WG_QUICK_USERSPACE_IMPLEMENTATION=wireguard-go
 
+ENTRYPOINT ["/bin/sh", "./netclient.sh"]

+ 1 - 1
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"]

+ 11 - 2
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"