From e8379e0c6618214f039203f29dc105cddae1147c Mon Sep 17 00:00:00 2001 From: Michael Vaughan Date: Fri, 11 Feb 2022 12:38:29 -0500 Subject: [PATCH] add linux static target --- Makefile | 6 +++++- build_static.sh | 17 +++++++++++++++++ go.mod | 2 +- main.go | 2 +- 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100755 build_static.sh diff --git a/Makefile b/Makefile index 0d9ac5f..46c55be 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ WIN=windows-agent.exe FLAGS=-ldflags "-s -w" WIN-FLAGS=-ldflags -H=windowsgui -all: clean create-directory agent-windows agent-linux +all: clean create-directory agent-windows agent-linux agent-linux-static create-directory: mkdir ${DIRECTORY} @@ -17,5 +17,9 @@ agent-linux: echo "Compiling Linux binary" env GOOS=linux GOARCH=amd64 go build ${FLAGS} -o ${DIRECTORY}/${LINUX} main.go +agent-linux-static: + echo "Compiling static Linux binary" + docker run --rm=true -itv $(PWD):/mnt alpine:3.7 /mnt/build_static.sh + clean: rm -rf ${DIRECTORY} diff --git a/build_static.sh b/build_static.sh new file mode 100755 index 0000000..6652088 --- /dev/null +++ b/build_static.sh @@ -0,0 +1,17 @@ +#!/bin/sh +# many thanks to @negbie +# https://github.com/google/gopacket/issues/424#issuecomment-369551841 +set -ex +apk update +apk add linux-headers musl-dev gcc go libpcap-dev ca-certificates git + +mkdir /go +export GOPATH=/go +mkdir -p /go/src/github.com/emmaunel +mkdir -p /mnt/out +cp -a /mnt /go/src/github.com/emmaunel/vishnu +cd /go/src/github.com/emmaunel/vishnu +rm -f vishnu* +go get -v ./ ./ +go build --ldflags '-linkmode external -extldflags "-static -s -w"' -v ./ +cp ./vishnu /mnt/out/ diff --git a/go.mod b/go.mod index 7f9b84a..2af143e 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module vishnu +module github.com/emmaunel/vishnu go 1.17 diff --git a/main.go b/main.go index dfb7ff6..69ac33a 100644 --- a/main.go +++ b/main.go @@ -10,7 +10,7 @@ import ( "runtime" "strconv" - "vishnu/spec" + "github.com/emmaunel/vishnu/spec" "github.com/google/gopacket" "github.com/google/gopacket/layers"