mirror of
https://github.com/fosrl/gerbil.git
synced 2026-03-03 01:06:47 +00:00
Add entrypoint script
This commit is contained in:
14
Dockerfile
14
Dockerfile
@@ -18,12 +18,16 @@ RUN CGO_ENABLED=0 GOOS=linux go build -o /gerbil
|
|||||||
# Start a new stage from scratch
|
# Start a new stage from scratch
|
||||||
FROM ubuntu:22.04 AS runner
|
FROM ubuntu:22.04 AS runner
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y nftables iproute2 wireguard && apt-get clean
|
RUN apt-get update && apt-get install -y nftables && apt-get clean
|
||||||
|
|
||||||
WORKDIR /root/
|
# Copy the pre-built binary file from the previous stage and the entrypoint script
|
||||||
|
COPY --from=builder /gerbil /usr/local/bin/
|
||||||
|
COPY entrypoint.sh /
|
||||||
|
|
||||||
# Copy the pre-built binary file from the previous stage
|
RUN chmod +x /entrypoint.sh
|
||||||
COPY --from=builder /gerbil .
|
|
||||||
|
# Copy the entrypoint script
|
||||||
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
|
|
||||||
# Command to run the executable
|
# Command to run the executable
|
||||||
CMD ["./gerbil"]
|
CMD ["gerbil"]
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -3,7 +3,7 @@ all:
|
|||||||
docker build -t gerbil .
|
docker build -t gerbil .
|
||||||
|
|
||||||
test:
|
test:
|
||||||
docker run -it -p 3002:3002 -v ./config_example.json:/config/config.json --cap-add=NET_ADMIN --cap-add=SYS_MODULE gerbil ./gerbil --config /config/config.json
|
docker run -it -p 3002:3002 -v ./config_example.json:/config/config.json --cap-add=NET_ADMIN --cap-add=SYS_MODULE gerbil --config /config/config.json
|
||||||
|
|
||||||
local:
|
local:
|
||||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o gerbil
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o gerbil
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
version: '3'
|
|
||||||
|
|
||||||
services:
|
|
||||||
gerbil:
|
|
||||||
image: gerbil
|
|
||||||
container_name: gerbil
|
|
||||||
command: ["./gerbil", "--config", "/config/gerbil.conf"]
|
|
||||||
cap_add:
|
|
||||||
- NET_ADMIN
|
|
||||||
- SYS_MODULE
|
|
||||||
ports:
|
|
||||||
- 51820:51820/udp
|
|
||||||
volumes:
|
|
||||||
- ./config_example.json:/config/config.json
|
|
||||||
restart: unless-stopped
|
|
||||||
21
entrypoint.sh
Normal file
21
entrypoint.sh
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Sample from https://github.com/traefik/traefik-library-image/blob/5070edb25b03cca6802d75d5037576c840f73fdd/v3.1/alpine/entrypoint.sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# first arg is `-f` or `--some-option`
|
||||||
|
if [ "${1#-}" != "$1" ]; then
|
||||||
|
set -- gerbil "$@"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# if our command is a valid Gerbil subcommand, let's invoke it through Gerbil instead
|
||||||
|
# (this allows for "docker run gerbil version", etc)
|
||||||
|
if gerbil "$1" --help >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
set -- gerbil "$@"
|
||||||
|
else
|
||||||
|
echo "= '$1' is not a Gerbil command: assuming shell execution." 1>&2
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec "$@"
|
||||||
2
main.go
2
main.go
@@ -399,7 +399,7 @@ func periodicBandwidthCheck(endpoint string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func calculatePeerBandwidth() ([]PeerBandwidth, error) {
|
func calculatePeerBandwidth() ([]PeerBandwidth, error) { //TODO: fix this to actually only report the change in bandwidth from the last query
|
||||||
device, err := wgClient.Device(interfaceName)
|
device, err := wgClient.Device(interfaceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get device: %v", err)
|
return nil, fmt.Errorf("failed to get device: %v", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user