Skip to content

Commit 85cb7b6

Browse files
authored
Merge pull request #26 from deepfence/fix-musl
Fix build with musl
2 parents cd32ec5 + 54f917e commit 85cb7b6

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

.github/workflows/build.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: actions/setup-go@v2
15+
with:
16+
go-version: "1.17"
17+
- name: Build
18+
run: make docker-bin
19+
env:
20+
DOCKER_BUILDKIT: 1
21+
COMPOSE_DOCKER_CLI_BUILD: 1
22+
- name: Test
23+
run: make docker-test
24+
env:
25+
DOCKER_BUILDKIT: 1
26+
COMPOSE_DOCKER_CLI_BUILD: 1

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ RUN git clone --branch libpcap-1.10.1 --depth 1 https://github.com/the-tcpdump-g
2424
COPY . /src
2525
WORKDIR /src
2626
ARG RELEASE=0
27-
RUN make build STATIC=1 RELEASE=${RELEASE}
27+
RUN --mount=type=cache,target=/root/.cache/go-build \
28+
make build STATIC=1 RELEASE=${RELEASE}
2829

2930
FROM alpine:3.15 as packetstreamer
3031

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
IMAGE ?= docker.io/deepfenceio/deepfence_packetstreamer
2+
IMAGE_BUILD ?= docker.io/deepfenceio/deepfence_packetstreamer_build
23
CC ?= gcc
34
LDFLAGS ?=
5+
TAGS ?=
46
STATIC ?= 0
57
ifeq ($(STATIC),1)
68
LDFLAGS += -linkmode external -extldflags "-static"
9+
TAGS += musl
710
endif
811
RELEASE ?= 0
912
ifeq ($(RELEASE),1)
@@ -15,7 +18,7 @@ endif
1518
all: build
1619

1720
build:
18-
go build --ldflags '$(LDFLAGS)' -o packetstreamer ./main.go
21+
go build -tags '$(TAGS)' --ldflags '$(LDFLAGS)' -o packetstreamer ./main.go
1922

2023
docker-bin: docker-image
2124
docker cp $(shell docker create --rm $(IMAGE)):/usr/bin/packetstreamer .
@@ -26,5 +29,9 @@ docker-image:
2629
docker-push:
2730
docker push $(IMAGE)
2831

32+
docker-test:
33+
docker build -t $(IMAGE_BUILD) --target builder .
34+
docker run --rm $(IMAGE_BUILD) make test STATIC=1
35+
2936
test:
30-
go test ./...
37+
go test -tags '$(TAGS)' ./...

0 commit comments

Comments
 (0)