From fd43971eab9b837252260ac410b375c5499d3649 Mon Sep 17 00:00:00 2001 From: mzz2017 <2017@duck.com> Date: Sat, 4 Mar 2023 13:16:26 +0800 Subject: [PATCH] chore: support docker. fix #30 --- Dockerfile | 18 ++++++++++++++++++ cmd/run.go | 2 +- control/control_plane.go | 2 +- docker-compose.yml | 11 +++++++++++ install/empty.dae | 1 + 5 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 install/empty.dae diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7e4399e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM golang:1.20-bullseye AS builder +RUN apt-get update && apt-get install -y llvm clang git make +WORKDIR /build/ +ADD go.mod go.sum ./ +RUN go mod download +ADD . . +RUN git submodule update --init +RUN make OUTPUT=dae GOFLAGS="-buildvcs=false" CC=clang CGO_ENABLED=0 + +FROM alpine +RUN mkdir -p /usr/local/share/dae/ +RUN mkdir -p /etc/dae/ +RUN wget -O /usr/local/share/dae/geoip.dat https://github.com/v2ray/geoip/releases/latest/download/geoip.dat +RUN wget -O /usr/local/share/dae/geosite.dat https://github.com/v2ray/domain-list-community/releases/latest/download/dlc.dat +COPY --from=builder /build/dae /usr/local/bin +COPY --from=builder /build/install/empty.dae /etc/dae/config.dae +RUN chmod 0600 /etc/dae/config.dae +CMD ["dae", "run", "-c", "/etc/dae/config.dae"] diff --git a/cmd/run.go b/cmd/run.go index 8cb64fe..3dcf3c3 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -205,7 +205,7 @@ func newControlPlane(log *logrus.Logger, bpf interface{}, conf *config.Config) ( } if len(conf.Global.LanInterface) == 0 && len(conf.Global.WanInterface) == 0 { - log.Warnln("No binding interface.") + log.Warnln("No interface to bind.") } c, err = control.NewControlPlane( diff --git a/control/control_plane.go b/control/control_plane.go index 804718b..aec5fc0 100644 --- a/control/control_plane.go +++ b/control/control_plane.go @@ -143,7 +143,7 @@ func NewControlPlane( return nil, fmt.Errorf("load eBPF objects: %w", err) } } - + log.Infof("eBPF programs and maps loaded") // outboundId2Name can be modified later. outboundId2Name := make(map[uint8]string) core := newControlPlaneCore( diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7eada3d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +version: "3" +services: + dae: + privileged: true + network_mode: host + pid: host + build: + context: . + volumes: + - /sys:/sys + - /etc/dae:/etc/dae diff --git a/install/empty.dae b/install/empty.dae new file mode 100644 index 0000000..bd9231a --- /dev/null +++ b/install/empty.dae @@ -0,0 +1 @@ +global {} routing {} \ No newline at end of file