From 95c92b8db70565d55a9030aec45b76ea153803f1 Mon Sep 17 00:00:00 2001 From: toby cabot Date: Wed, 10 May 2023 17:33:11 -0400 Subject: [PATCH 1/3] Update Dockerfile to work with golang 1.20 base image The previous base image (Ubuntu 20.10) was a non-LTS release and is now unsupported so the Docker build command failed because it couldn't find the apt repos. Using golang base images simplifies the Dockerfile (since we no longer need to install golang ourselves) and since they're based on Debian Bullseye they'll be supported for a while. --- Dockerfile | 17 ++--------------- Makefile | 3 +-- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1fbb0ca..53a1804 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,13 @@ -FROM ubuntu:20.10 - -# Define variables. -ARG GOVERSION=1.15.15 -ARG ARCH=amd64 +FROM golang:1.20-bullseye # Download development environment. RUN apt-get update && \ apt-get install -y \ - libbpf-dev \ - make \ clang \ llvm \ + libbpf-dev \ libelf-dev -# Install Go specific version. -RUN apt-get install -y wget && \ - wget https://golang.org/dl/go${GOVERSION}.linux-${ARCH}.tar.gz && \ - tar -xf go${GOVERSION}.linux-${ARCH}.tar.gz && \ - mv go/ /usr/local/ && \ - ln -s /usr/local/go/bin/go /usr/local/bin/ && \ - rm -rf go${GOVERSION}.linux-${ARCH}.tar.gz - # Setup working directory. RUN mkdir -p /app WORKDIR /app diff --git a/Makefile b/Makefile index 09092c8..2449ec2 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ all: $(TARGET) $(TARGET_BPF) go_env := CC=clang CGO_CFLAGS="-I $(LIBBPF_HEADERS)" CGO_LDFLAGS="$(LIBBPF_OBJ)" $(TARGET): $(GO_SRC) - $(go_env) go build -o $(TARGET) + $(go_env) go build -o $(TARGET) -buildvcs=false $(TARGET_BPF): $(BPF_SRC) clang \ @@ -25,4 +25,3 @@ $(TARGET_BPF): $(BPF_SRC) .PHONY: clean clean: go clean - \ No newline at end of file From 39805fc690b96a30ca9866220eae6a2efe11e6cb Mon Sep 17 00:00:00 2001 From: toby cabot Date: Wed, 10 May 2023 17:36:27 -0400 Subject: [PATCH 2/3] Allow user to specify make target when running Docker image The make target used to be hard-coded in the Docker entrypoint so you could only make the "all" target. Now the target is in the CMD so you can override it, e.g.: $ docker run --rm -v $(pwd)/:/app/:z hello clean The default behavior is the same as before, i.e., "make all". --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 53a1804..234cd10 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,4 +13,5 @@ RUN mkdir -p /app WORKDIR /app # Execute build command. -ENTRYPOINT ["/usr/bin/make", "all"] +ENTRYPOINT ["/usr/bin/make"] +CMD ["all"] From ed85ae895e90452530baa96e813ba17c3e8c129b Mon Sep 17 00:00:00 2001 From: toby cabot Date: Wed, 17 May 2023 09:08:27 -0400 Subject: [PATCH 3/3] Rebuild when headers (or Makefile) change --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 2449ec2..e6dfd61 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,8 @@ ARCH=$(shell uname -m) TARGET := hello TARGET_BPF := $(TARGET).bpf.o -GO_SRC := *.go -BPF_SRC := *.bpf.c +GO_SRC := *.go Makefile +BPF_SRC := *.bpf.c *.bpf.h Makefile LIBBPF_HEADERS := /usr/include/bpf LIBBPF_OBJ := /usr/lib/$(ARCH)-linux-gnu/libbpf.a