docker working

This commit is contained in:
afeiszli 2021-11-16 22:18:24 -05:00
parent e2110d1402
commit aac6837147
3 changed files with 41 additions and 19 deletions

View file

@ -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"]

View file

@ -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"]

13
scripts/netclient.sh Normal file → Executable file
View file

@ -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"