Skip to content

Commit

Permalink
feat(integration): separate base build and kubectl trace image
Browse files Browse the repository at this point in the history
Signed-off-by: Lorenzo Fontana <lo@linux.com>
  • Loading branch information
fntlnz committed Jan 8, 2019
1 parent 5aad5f7 commit 8c62a48
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 62 deletions.
52 changes: 0 additions & 52 deletions Dockerfile.bpftrace

This file was deleted.

35 changes: 35 additions & 0 deletions Dockerfile.bpftracebase
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
ARG bpftracesha

FROM alpine:3.8 as builder
ENV STATIC_LINKING=ON
ENV RUN_TESTS=0
RUN apk add --update \
bison \
build-base \
clang-dev \
clang-static \
cmake \
elfutils-dev \
flex-dev \
git \
linux-headers \
llvm5-dev \
llvm5-static \
zlib-dev

# Put LLVM directories where CMake expects them to be
RUN ln -s /usr/lib/cmake/llvm5 /usr/lib/cmake/llvm
RUN ln -s /usr/include/llvm5/llvm /usr/include/llvm
RUN ln -s /usr/include/llvm5/llvm-c /usr/include/llvm-c

WORKDIR /

RUN git clone https://github.com/iovisor/bpftrace.git /bpftrace

WORKDIR /bpftrace

#RUN git checkout ${bpftracesha}

WORKDIR /bpftrace/docker

RUN sh build.sh /bpftrace/build-release Release
21 changes: 21 additions & 0 deletions Dockerfile.tracerunner
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ARG bpftracesha

FROM quay.io/fntlnz/kubectl-trace-bpftrace-base:${bpftracesha} as bpftrace
FROM golang:1.11.4-alpine3.8 as gobuilder

RUN apk update
RUN apk add make bash git

ADD . /go/src/github.com/iovisor/kubectl-trace
WORKDIR /go/src/github.com/iovisor/kubectl-trace

RUN make _output/bin/trace-runner

FROM alpine:3.8

RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
COPY --from=bpftrace /bpftrace/build-release/src/bpftrace /bin/bpftrace
COPY --from=gobuilder /go/src/github.com/iovisor/kubectl-trace/_output/bin/trace-runner /bin/trace-runner

ENTRYPOINT ["/bin/trace-runner"]

28 changes: 19 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ GIT_COMMIT := $(if $(shell git status --porcelain --untracked-files=no),${COMMIT
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
GIT_BRANCH_CLEAN := $(shell echo $(GIT_BRANCH) | sed -e "s/[^[:alnum:]]/-/g")

IMAGE_BPFTRACE_BRANCH := quay.io/fntlnz/kubectl-trace-bpftrace:$(GIT_BRANCH_CLEAN)
IMAGE_BPFTRACE_COMMIT := quay.io/fntlnz/kubectl-trace-bpftrace:$(GIT_COMMIT)
IMAGE_BPFTRACE_LATEST := quay.io/fntlnz/kubectl-trace-bpftrace:latest
IMAGE_TRACERUNNER_BRANCH := quay.io/fntlnz/kubectl-trace-bpftrace:$(GIT_BRANCH_CLEAN)
IMAGE_TRACERUNNER_COMMIT := quay.io/fntlnz/kubectl-trace-bpftrace:$(GIT_COMMIT)
IMAGE_TRACERUNNER_LATEST := quay.io/fntlnz/kubectl-trace-bpftrace:latest

BPFTRACESHA ?= 2ae2a53f62622631a304def6c193680e603994e3
IMAGE_BPFTRACE_BASE := quay.io/fntlnz/kubectl-trace-bpftrace-base:$(BPFTRACESHA)

IMAGE_BUILD_FLAGS ?= "--no-cache"

Expand All @@ -35,18 +38,18 @@ clean:

.PHONY: image/build
image/build:
$(DOCKER) build $(IMAGE_BUILD_FLAGS) -t $(IMAGE_BPFTRACE_BRANCH) -f Dockerfile.bpftrace .
$(DOCKER) tag $(IMAGE_BPFTRACE_BRANCH) $(IMAGE_BPFTRACE_COMMIT)
$(DOCKER) build --build-arg bpftracesha=$(BPFTRACESHA) $(IMAGE_BUILD_FLAGS) -t $(IMAGE_TRACERUNNER_BRANCH) -f Dockerfile.tracerunner .
$(DOCKER) tag $(IMAGE_TRACERUNNER_BRANCH) $(IMAGE_TRACERUNNER_COMMIT)

.PHONY: image/push
image/push:
$(DOCKER) push $(IMAGE_BPFTRACE_BRANCH)
$(DOCKER) push $(IMAGE_BPFTRACE_COMMIT)
$(DOCKER) push $(IMAGE_TRACERUNNER_BRANCH)
$(DOCKER) push $(IMAGE_TRACERUNNER_COMMIT)

.PHONY: image/latest
image/latest:
$(DOCKER) tag $(IMAGE_BPFTRACE_COMMIT) $(IMAGE_BPFTRACE_LATEST)
$(DOCKER) push $(IMAGE_BPFTRACE_LATEST)
$(DOCKER) tag $(IMAGE_TRACERUNNER_COMMIT) $(IMAGE_TRACERUNNER_LATEST)
$(DOCKER) push $(IMAGE_TRACERUNNER_LATEST)

.PHONY: test
test:
Expand All @@ -56,3 +59,10 @@ test:
integration:
TEST_KUBECTLTRACE_BINARY=$(shell pwd)/$(kubectl_trace) $(GO) test -v ./integration/...

.PHONY: bpftraceimage/build
bpftraceimage/build:
$(DOCKER) build --build-arg bpftracesha=$(BPFTRACESHA) $(IMAGE_BUILD_FLAGS) -t $(IMAGE_BPFTRACE_BASE) -f Dockerfile.bpftracebase .

.PHONY: bpftraceimage/push
bpftraceimage/push:
$(DOCKER) push $(IMAGE_BPFTRACE_BASE)
2 changes: 1 addition & 1 deletion integration/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func (k *KubectlTraceSuite) TestRunNode(c *check.C) {

nodeName := nodes[0].String()
bpftraceProgram := `kprobe:do_sys_open { printf("%s: %s\n", comm, str(arg1)) }'`
out := k.KubectlTraceCmd(c, "run", "-e", bpftraceProgram, nodeName)
out := k.KubectlTraceCmd(c, "run", "-e", bpftraceProgram, nodeName, "-a")
match, err := regexp.MatchString("trace (\\w+-){4}\\w+ created", out)
c.Assert(err, check.IsNil)
c.Assert(match, check.Equals, true)
Expand Down

0 comments on commit 8c62a48

Please sign in to comment.