Skip to content

Commit b46f217

Browse files
feat: include iptables block binary in iptables monitor image
1 parent bcd6fb7 commit b46f217

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ REPO_ROOT ?= $(shell git rev-parse --show-toplevel)
3535
REVISION ?= $(shell git rev-parse --short HEAD)
3636
ACN_VERSION ?= $(shell git describe --exclude "azure-iptables-monitor*" --exclude "azure-ip-masq-merger*" --exclude "azure-ipam*" --exclude "dropgz*" --exclude "zapai*" --exclude "ipv6-hp-bpf*" --exclude "azure-block-iptables*" --tags --always)
3737
IPV6_HP_BPF_VERSION ?= $(notdir $(shell git describe --match "ipv6-hp-bpf*" --tags --always))
38-
AZURE_BLOCK_IPTABLES_VERSION ?= $(notdir $(shell git describe --match "azure-block-iptables*" --tags --always))
38+
AZURE_BLOCK_IPTABLES_VERSION ?= $(notdir $(shell git describe --match "azure-block-iptables*" --tags --always))
3939
AZURE_IPAM_VERSION ?= $(notdir $(shell git describe --match "azure-ipam*" --tags --always))
4040
AZURE_IP_MASQ_MERGER_VERSION ?= $(notdir $(shell git describe --match "azure-ip-masq-merger*" --tags --always))
41-
AZURE_IPTABLES_MONITOR_VERSION ?= $(notdir $(shell git describe --match "azure-iptables-monitor*" --tags --always))
41+
AZURE_IPTABLES_MONITOR_VERSION ?= $(notdir $(shell git describe --match "azure-block-iptables*" --match "azure-iptables-monitor*" --tags --always))
4242
CNI_VERSION ?= $(ACN_VERSION)
4343
CNS_VERSION ?= $(ACN_VERSION)
4444
NPM_VERSION ?= $(ACN_VERSION)
@@ -467,7 +467,8 @@ azure-iptables-monitor-image: ## build azure-iptables-monitor container image.
467467
TAG=$(AZURE_IPTABLES_MONITOR_PLATFORM_TAG) \
468468
TARGET=$(OS) \
469469
OS=$(OS) \
470-
ARCH=$(ARCH)
470+
ARCH=$(ARCH) \
471+
EXTRA_BUILD_ARGS="--build-arg AZURE_BLOCK_IPTABLES_VERSION=$(AZURE_BLOCK_IPTABLES_VERSION)"
471472

472473
azure-iptables-monitor-image-push: ## push azure-iptables-monitor container image.
473474
$(MAKE) container-push \

azure-iptables-monitor/Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,40 @@ WORKDIR /azure-iptables-monitor
1717
COPY ./azure-iptables-monitor .
1818
RUN GOOS=$OS CGO_ENABLED=0 go build -a -o /go/bin/iptables-monitor -trimpath -ldflags "-s -w -X main.version="$VERSION"" -gcflags="-dwarflocationlists=true" .
1919

20+
FROM go AS azure-block-iptables
21+
ARG OS
22+
ARG AZURE_BLOCK_IPTABLES_VERSION
23+
ARG ARCH
24+
WORKDIR /azure-container-networking
25+
COPY ./bpf-prog/azure-block-iptables ./bpf-prog/azure-block-iptables
26+
COPY ./go.mod ./go.sum ./
27+
# Install BPF development dependencies for Azure Linux (mariner)
28+
RUN tdnf install -y llvm clang libbpf-devel gcc binutils glibc
29+
# Set up C include path for BPF
30+
ENV C_INCLUDE_PATH=/usr/include/bpf
31+
# Set up architecture-specific symlinks for cross-compilation support
32+
RUN if [ "$ARCH" = "amd64" ]; then \
33+
ARCH_DIR=x86_64-linux-gnu; \
34+
elif [ "$ARCH" = "arm64" ]; then \
35+
ARCH_DIR=aarch64-linux-gnu; \
36+
fi && \
37+
for dir in /usr/include/"$ARCH_DIR"/*; do \
38+
if [ -d "$dir" ]; then \
39+
ln -sfn "$dir" /usr/include/$(basename "$dir"); \
40+
elif [ -f "$dir" ]; then \
41+
ln -Tsfn "$dir" /usr/include/$(basename "$dir"); \
42+
fi \
43+
done || true
44+
RUN GOOS=$OS CGO_ENABLED=0 go generate ./bpf-prog/azure-block-iptables/...
45+
RUN GOOS=$OS CGO_ENABLED=0 go build -a -o /go/bin/azure-block-iptables -trimpath -ldflags "-s -w -X main.version="$AZURE_BLOCK_IPTABLES_VERSION"" -gcflags="-dwarflocationlists=true" ./bpf-prog/azure-block-iptables/cmd/azure-block-iptables
46+
2047
FROM mariner-core AS iptables
2148
RUN tdnf install -y iptables
2249

2350
FROM mariner-distroless AS linux
2451
COPY --from=iptables /usr/sbin/*tables* /usr/sbin/
2552
COPY --from=iptables /usr/lib /usr/lib
2653
COPY --from=azure-iptables-monitor /go/bin/iptables-monitor azure-iptables-monitor
54+
COPY --from=azure-block-iptables /go/bin/azure-block-iptables azure-block-iptables
2755

2856
ENTRYPOINT ["/azure-iptables-monitor"]

0 commit comments

Comments
 (0)