-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from ankudinov/add-host-ubuntu
add host-ubuntu initial version
- Loading branch information
Showing
5 changed files
with
260 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
name: Create Ubuntu host container image | ||
|
||
on: | ||
push: | ||
branches: ['**'] # branches will be filtered in the jobs | ||
paths: | ||
- .github/workflows/container_build_host_ubuntu.yml | ||
- .github/workflows/container_build_child.yml | ||
- containers/host-ubuntu/** | ||
workflow_dispatch: | ||
branches: ['**'] # branches will be filtered in the jobs | ||
|
||
jobs: | ||
build-demo-container: | ||
# fork - build container from any branch for testing | ||
# parent repo - build on main branch only | ||
if: github.repository != 'aristanetworks/acLabs' || github.ref == 'refs/heads/main' | ||
uses: ./.github/workflows/container_build_child.yml | ||
with: | ||
container_name: "host-ubuntu" | ||
image_tags: "latest" | ||
from_image: "ubuntu" | ||
from_variant: "24.04" | ||
username: "admin" | ||
user_id: "1001" | ||
group_id: "1001" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
ARG FROM_IMAGE | ||
ARG FROM_VARIANT | ||
|
||
FROM ${FROM_IMAGE}:${FROM_VARIANT} | ||
|
||
ARG USERNAME | ||
|
||
# Install essential tools. | ||
RUN apt-get update \ | ||
&& apt-get install -y --no-install-recommends \ | ||
make \ | ||
curl \ | ||
git-all \ | ||
python3 \ | ||
python3-pip \ | ||
sudo \ | ||
wget \ | ||
# TODO: have to review the bottom part later | ||
ca-certificates \ | ||
cdpr \ | ||
dnsutils \ | ||
dsniff \ | ||
ipcalc \ | ||
iperf \ | ||
iperf3 \ | ||
fping \ | ||
gnupg \ | ||
gsutil \ | ||
ifenslave \ | ||
inetutils-traceroute \ | ||
iputils-* \ | ||
libkrb5-dev \ | ||
lldpd \ | ||
locales \ | ||
mtr \ | ||
nano \ | ||
net-tools \ | ||
netplan.io \ | ||
openssh-server \ | ||
snapd \ | ||
tzdata \ | ||
# ufw \ | ||
vim | ||
# no need to reduce the image size for now | ||
# && rm -rf /var/lib/apt/lists/* \ | ||
# && rm -Rf /usr/share/doc && rm -Rf /usr/share/man \ | ||
# && apt-get clean | ||
|
||
COPY ./entrypoint.sh /bin/entrypoint.sh | ||
RUN chmod +x /bin/entrypoint.sh | ||
|
||
USER ${USERNAME} | ||
|
||
ENTRYPOINT [ "/bin/entrypoint.sh" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"build": { | ||
"dockerfile": "./Dockerfile", | ||
"context": ".", | ||
"args": { | ||
"FROM_IMAGE": "${localEnv:FROM_IMAGE}", | ||
"FROM_VARIANT": "${localEnv:FROM_VARIANT}", | ||
"USERNAME": "${localEnv:USERNAME}", | ||
"UID": "${localEnv:UID}", | ||
"GID": "${localEnv:GID}" | ||
} | ||
}, | ||
"features": { | ||
"ghcr.io/devcontainers/features/common-utils:2":{ | ||
"installZsh": true, | ||
"installOhMyZsh": true, | ||
"configureZshAsDefaultShell": true, | ||
"username": "${localEnv:USERNAME}", | ||
"userUid": "${localEnv:UID}", | ||
"userGid": "${localEnv:GID}", | ||
// do not update packages to reduce build time | ||
"upgradePackages": "false" | ||
} | ||
// Add sshd | ||
// "ghcr.io/devcontainers/features/sshd:1": { | ||
// "version": "latest" | ||
// } | ||
}, | ||
|
||
// Set `remoteUser` to `root` to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. | ||
"remoteUser": "${localEnv:USERNAME}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#!/bin/bash | ||
|
||
# preserve environment variables | ||
if [ "$(id -u)" != "0" ]; then | ||
exec sudo --preserve-env=TMODE,TACTIVE,TBACKUP,SSH_PASSWORD,IPV4,IPV6,GW,STATIC_ROUTE "$0" "$@" | ||
fi | ||
|
||
# set admin password for SSH access | ||
if [ -z "${SSH_PASSWORD}" ]; then | ||
SSH_PASSWORD='admin' | ||
fi | ||
|
||
echo "admin:${SSH_PASSWORD}" | sudo chpasswd | ||
|
||
# start SSH server | ||
sudo service ssh start | ||
|
||
UPLINK='eth1' | ||
|
||
# TMODE is expected to be set via the containerlab topology file prior to deployment | ||
# Expected values are "lacp" or "static" or "active-backup" which will bond eth1 and eth2 | ||
if [ -z "$TMODE" ]; then | ||
TMODE='none' | ||
fi | ||
|
||
# TACTIVE and TBACKUP to be set via the containerlab topology file for active-backup runner | ||
# expected values are "eth1" or "eth2" default is "eth1" active and "eth2" backup | ||
if [ -z "$TACTIVE" ]; then | ||
TACTIVE='eth1' | ||
TBACKUP='eth2' | ||
elif [ "$TACTIVE" == 'eth1' ]; then | ||
TBACKUP='eth2' | ||
elif [ "$TACTIVE" == 'eth2' ]; then | ||
TBACKUP='eth1' | ||
fi | ||
|
||
if [ "$TMODE" == 'lacp' ]; then | ||
|
||
UPLINK='bond0' | ||
|
||
sudo ip link set eth1 down | ||
sudo ip link set eth2 down | ||
|
||
sudo ip link add ${UPLINK} type bond mode 802.3ad | ||
|
||
sudo ip link set eth1 master ${UPLINK} | ||
sudo ip link set eth2 master ${UPLINK} | ||
|
||
if [ -z "$UPLINK_MAC" ]; then | ||
UPLINK_MAC="c0:d6:82:00:$(openssl rand -hex 1):$(openssl rand -hex 1)" | ||
fi | ||
sudo ip link set dev ${UPLINK} address "${UPLINK_MAC}" | ||
sudo ip link set ${UPLINK} up | ||
|
||
elif ! [ -z "${PHONE}" ] ; then | ||
|
||
UPLINK='br0' | ||
|
||
# Create br0 | ||
sudo ip link add name br0 type bridge | ||
|
||
if [ -z "$UPLINK_MAC" ]; then | ||
UPLINK_MAC="30:86:2d:00:$(openssl rand -hex 1):$(openssl rand -hex 1)" | ||
fi | ||
sudo ip link set dev ${UPLINK} address "${UPLINK_MAC}" | ||
|
||
# Disable STP, provide add'l visibility | ||
sudo ip link set ${UPLINK} type bridge stp_state 0 | ||
sudo ip link set ${UPLINK} type bridge vlan_stats_per_port 1 | ||
|
||
# Bring up Bridge Interface and add eth1 & eth2 (Note: eths must be UP to add) | ||
sudo ip link set dev ${UPLINK} up | ||
sudo ip link set eth1 master ${UPLINK} | ||
sudo ip link set eth2 master ${UPLINK} | ||
|
||
# Add Simple Multicast Support | ||
#sysctl net.ipv4.conf.br0.mc_forwarding=1 | ||
#sysctl net.ipv6.conf.br0.mc_forwarding=1 | ||
sudo ip link set ${UPLINK} type bridge mcast_stats_enabled 1 | ||
|
||
# Customize LLDP | ||
# lldpcli configure ports eth1,eth2,br0 lldp status rx-only | ||
fi | ||
|
||
# configure IP addresses and routes | ||
if ! [ -z "${IPV4}" ]; then | ||
sudo ip addr add ${IPV4} dev ${UPLINK} | ||
fi | ||
|
||
if ! [ -z "${IPV6}" ]; then | ||
sudo ip -6 addr add ${IPV6} dev ${UPLINK} | ||
fi | ||
|
||
if ! [ -z "${GW}" ]; then | ||
# add static routes | ||
sudo ip route add ${STATIC_ROUTE} via ${GW} dev ${UPLINK} | ||
sudo ip route add 224.0.0.0/4 via ${GW} dev ${UPLINK} | ||
fi | ||
|
||
# Execute command from docker cli if any. | ||
if [ ${@+True} ]; then | ||
exec "$@" | ||
# Otherwise just enter sh or zsh. | ||
else | ||
if [ -f "/bin/zsh" ]; then | ||
exec zsh | ||
else | ||
exec sh | ||
fi | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters