From 80111ed915892f6391db17abadec6efab15af3b9 Mon Sep 17 00:00:00 2001 From: kerwenwwer Date: Mon, 8 Apr 2024 21:53:36 +0800 Subject: [PATCH] Remove cache after installing packages in Dockerfile and refactor. --- .env | 2 -- Dockerfile | 26 +++++++++++++++++++++----- k8s/entrypoint.sh | 2 +- 3 files changed, 22 insertions(+), 8 deletions(-) delete mode 100644 .env diff --git a/.env b/.env deleted file mode 100644 index 6bd6742..0000000 --- a/.env +++ /dev/null @@ -1,2 +0,0 @@ -MY_PROTO=UDP -#DEBUG=--debug \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 73d94ba..dd59fbf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,29 @@ -FROM golang:1.19 AS ebpf-tcp-proxy +# Use golang:1.19 as the base image for building ebpf-tcp-proxy +FROM golang:1.19 AS eGossip +# Run as root for package installations and configurations USER root -RUN apt-get update && apt-get install -y bpftool iproute2 lsof netcat-traditional -RUN apt install -y tmux tshark iputils-ping iproute2 net-tools tcpdump traceroute +# Combine package installations into a single RUN command to reduce layers, +# adding --no-install-recommends to minimize image size and +# cleaning up the apt cache to reduce unnecessary bloat +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + bpftool \ + iproute2 \ + lsof \ + netcat-traditional \ + iputils-ping \ + net-tools && \ + rm -rf /var/lib/apt/lists/* # This command removes the apt cache +# Copy necessary files from the host to the container filesystem COPY bpf/* /bpf/ COPY bin/xdp-gossip /usr/local/bin/xdp-gossip - COPY k8s/entrypoint.sh /entrypoint.sh + +# Ensure the entrypoint script is executable RUN chmod +x /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file + +# Set the entrypoint script to run when the container starts +ENTRYPOINT ["/entrypoint.sh"] diff --git a/k8s/entrypoint.sh b/k8s/entrypoint.sh index 5164944..bb641de 100644 --- a/k8s/entrypoint.sh +++ b/k8s/entrypoint.sh @@ -1,2 +1,2 @@ #!/bin/sh -/usr/local/bin/xdp-gossip server --name "${POD_NAME}" --link eth0 --proto "${PROTO}" +/usr/local/bin/xdp-gossip server --name "${POD_NAME}" --link eth0 --proto "${PROTO}" \ No newline at end of file