File tree Expand file tree Collapse file tree 16 files changed +364
-0
lines changed
Expand file tree Collapse file tree 16 files changed +364
-0
lines changed Original file line number Diff line number Diff line change 1+ name : docker-publish-ghcr
2+
3+ on :
4+ workflow_dispatch :
5+ push :
6+ pull_request :
7+
8+ permissions :
9+ packages : write
10+
11+ env :
12+ PLATFORMS : linux/amd64,linux/arm64
13+ BUILD_DIRS : |
14+ tutorials/net/mtu/
15+
16+ jobs :
17+ docker_build_and_publish :
18+ runs-on : ubuntu-latest
19+ steps :
20+ - name : " Checkout repository..."
21+ uses : actions/checkout@v4
22+ with :
23+ path : code
24+ fetch-depth : 0
25+ fetch-tags : 1
26+
27+ - name : " Set up Docker buildx"
28+ uses : docker/setup-buildx-action@v3
29+
30+ - name : " Login to GitHub Container Registry (ghcr.io)"
31+ uses : docker/login-action@v3
32+ with :
33+ registry : ghcr.io
34+ username : ${{github.actor}}
35+ password : ${{secrets.GITHUB_TOKEN}}
36+
37+ - name : " Build and push to ghcr"
38+ run : |
39+ cd code
40+ export TAG=latest
41+
42+ if [ "${GITHUB_REF_NAME}" = "main" ]; then
43+ export PUSH="--push"
44+ fi
45+
46+ for dir in ${BUILD_DIRS}; do
47+ TAG="$(<${dir}/docker/tag):latest"
48+ echo "Building '${dir}/docker/Dockerfile' with tag '${TAG}'..."
49+ docker buildx build --platform ${PLATFORMS} ${PUSH} -f ${dir}/docker/Dockerfile ${dir} --tag ghcr.io/${GITHUB_REPOSITORY}:${TAG}
50+ done
Original file line number Diff line number Diff line change 1+ * ~
2+ . *
3+ ! .github /
4+
5+ # Generated by make
6+ * . [oa ]
7+ * .l [oa ]
8+ * .swp
9+ * .swo
10+ test /ns /. *
11+ __pycache__ /
Original file line number Diff line number Diff line change 1+ SCENARIO=" error"
2+ if [ -f /bp/.scenario ]; then
3+ SCENARIO=$( < /bp/.scenario)
4+ fi
5+
6+ NS=" "
7+ if [ -f /bp/.ns ]; then
8+ NS=" #$( < /bp/.ns) "
9+ fi
10+
11+ if tput setaf 1 > /dev/null 2>&1 ; then
12+ PS1=" \[\e[36m\]bp\[\e[33m\](${SCENARIO}${NS} )\[\e[0m\]"
13+ else
14+ PS1=" bp(${SCENARIO}${NS} )"
15+ fi
16+
17+ PS1=" ${PS1} \$ "
18+
19+ # Ask before removing files
20+ alias rm=' rm -i'
21+
22+ alias _exec=' exec'
23+ alias help=" /bp/help.sh"
24+ alias describe=" /bp/describe.sh"
25+
26+ _check_ns (){
27+ if ! ip netns list | grep -qw ${1} ; then
28+ echo " Invalid namespace: '${1} '"
29+ return 1
30+ fi
31+ }
32+
33+ exec (){
34+ if [ -z " ${1:- } " ] || [ -z " ${2:- } " ] ; then
35+ echo " Usage: exec <namespace_name> <command>"
36+ return 1
37+ fi
38+ NS=${1}
39+ shift
40+ _check_ns " ${NS} "
41+ ip netns exec ${NS} ${@ }
42+ }
43+
44+ shell (){
45+ if [ -z " ${1:- } " ]; then
46+ echo " Usage: shell <namespace_name>"
47+ return 1
48+ fi
49+ _check_ns " ${1} "
50+
51+ echo " ${1} " > /bp/.ns
52+ ip netns exec ${1} bash --rcfile /bp/.bashrc -i
53+ rm -rf /bp/.ns || true
54+ }
Original file line number Diff line number Diff line change 1+ docker /
Original file line number Diff line number Diff line change 1+ =================================================
2+ 🐧 bitpuff.io MTU tutorial 🐧
3+ =================================================
4+ Welcome to the MTU tutorial!
5+ Type 'help' to get the list of shortcut commands.
6+ -------------------------------------------------
Original file line number Diff line number Diff line change 1+ ## MTU tutorial
2+
3+ This folder contains the code (Dockerfile, Makefiles and scripts) supporting
4+ the [ MTU tutorial] ( https://bitpuff.io/tutorials/networking/mtu/ ) .
5+
6+ ## How to use it
7+
8+ XXX
9+
10+ ## Scenarios
11+
12+ ### ` simple-two-router ` (default)
13+
14+ XXX add diagram
Original file line number Diff line number Diff line change 1+ SUDO=$( [ " $( id -u) " -eq 0 ] || echo sudo)
2+
3+ if [ " ${VERBOSE:- 0} " == " 1" ]; then
4+ set -x
5+ fi
6+
7+ _log (){
8+ echo " [${1} ] ${2} "
9+ }
10+
11+ log_info (){
12+ _log " INFO" " ${1} "
13+ }
14+
15+ log_warn (){
16+ _log " WARN" " ${1} "
17+ }
18+
19+ log_err (){
20+ _log " ERROR" " ${1} "
21+ }
22+
23+ log_debug (){
24+ _log " DBG" " ${1} "
25+ }
26+
27+ # $1 namespace name
28+ create_ns () {
29+ ${SUDO} ip netns add ${1}
30+ ${SUDO} ip netns exec ${1} ip link set up dev lo
31+ }
32+
33+ # $1 namespace name
34+ destroy_ns () {
35+ ${SUDO} ip netns del ${1}
36+ }
37+
38+ # $1 ns1
39+ # $2 iface1 name
40+ # $3 ns2
41+ # $4 iface2 name
42+ create_link () {
43+ ${SUDO} ip netns exec ${1} ip link add ${2} type veth peer name _tmp
44+ ${SUDO} ip netns exec ${1} ip link set up dev ${2}
45+ ${SUDO} ip netns exec ${1} ip link set netns ${3} dev _tmp
46+ ${SUDO} ip netns exec ${3} ip link set _tmp name ${4}
47+ ${SUDO} ip netns exec ${3} ip link set up dev ${4}
48+ }
49+
50+ # $1 ns1
51+ # $2 iface1 name
52+ destroy_link () {
53+ ${SUDO} ip netns exec ${1} ip link del ${2}
54+ }
55+
56+ # $1 ns
57+ # $2 dev
58+ # $3 addr
59+ addr_add (){
60+ ${SUDO} ip netns exec ${1} ip addr add ${3} dev ${2}
61+ }
62+
63+ # $1 ns
64+ # $2 route
65+ route_add (){
66+ ${SUDO} ip netns exec ${1} ip route add ${2}
67+ }
68+
69+ list_scenarios (){
70+ find . -maxdepth 1 -type d ! -name ' .*' -printf ' %P\n'
71+ }
72+
73+ # $1 scenario name
74+ setup_scenario () {
75+ if [ ! -d " ${1} " ]; then
76+ log_err " Invalid scenario ${1} "
77+ echo " Valid scenarios are '$( list_scenarios) '"
78+ exit 1
79+ fi
80+
81+ cd ${1} && ./setup.sh
82+ }
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ set -euo pipefail
4+
5+ source /bp/common.sh
6+
7+ if [ ! -f /bp/.scenario ]; then
8+ log_err " Unknown or invalid scenario"
9+ fi
10+ SCENARIO=$( < /bp/.scenario)
11+
12+ echo " ================================================="
13+ echo " 🐧 Scenario: '${SCENARIO} ' 🐧 "
14+ echo " ================================================="
15+ echo" "
16+
17+ cat /bp/${SCENARIO} /TOPOLOGY.md
18+ echo" "
19+ for ns in $( ip netns list) ; do
20+ echo " ================================================="
21+ echo -e " \033[1;34mNamespace: $ns \033[0m"
22+ echo " -------------------------------------------------"
23+ echo " IP addressing:"
24+ ip netns exec ${ns} ip -brief addr
25+ echo " "
26+ echo " Routing table:"
27+ ip netns exec ${ns} ip -brief route
28+ echo -e " \n"
29+ done
Original file line number Diff line number Diff line change 1+ FROM debian:latest
2+
3+ LABEL maintainer=
"Marc Sune <[email protected] >" 4+ LABEL version="latest"
5+ LABEL description="bitpuff.io MTU tutorial docker image"
6+ LABEL org.opencontainers.image.authors=
"Marc Sune <[email protected] >" 7+ LABEL org.opencontainers.image.url="https://github.com/bitpuff-io/code/"
8+ LABEL org.opencontainers.image.documentation="https://bitpuff.io/tutorials/networking/mtu/"
9+ LABEL org.opencontainers.image.source="https://github.com/bitpuff-io/code/"
10+ LABEL org.opencontainers.image.licenses="BSD"
11+
12+ RUN apt update && apt install -y --no-install-recommends \
13+ curl \
14+ iproute2 \
15+ iputils-ping \
16+ make \
17+ python3-scapy \
18+ tcpdump \
19+ && rm -rf /var/lib/apt/lists/*
20+
21+ RUN mkdir /bp
22+ COPY . /bp
23+ WORKDIR /root
24+ CMD ["/bp/entrypoint.sh" ]
You can’t perform that action at this time.
0 commit comments