Improved the script to add more useful packages and improved the entrypoint script.
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Ameer Hamza Khan
2025-07-27 13:09:14 +00:00
parent eada31f646
commit bb6dc6ab2e
3 changed files with 101 additions and 60 deletions

View File

@@ -65,27 +65,3 @@ steps:
- type=local\\,src=/cache/${DRONE_REPO}/ubuntu-20.04 - type=local\\,src=/cache/${DRONE_REPO}/ubuntu-20.04
cache_to: cache_to:
- type=local,dest=/cache/${DRONE_REPO}/ubuntu-20.04,mode=max - type=local,dest=/cache/${DRONE_REPO}/ubuntu-20.04,mode=max
- name: ubuntu-18
image: *image
depends_on: *depends
environment:
UBUNTU_VER: 18.04
settings:
<<: *settings
repo: ${DRONE_REPO_LINK:8}/ubuntu-18.04
extra_tags:
- ${DRONE_REPO_LINK:8}:18.04
cache_from:
- type=local\\,src=/cache/${DRONE_REPO}/ubuntu-18.04
cache_to:
- type=local,dest=/cache/${DRONE_REPO}/ubuntu-18.04,mode=max
# - name: send_n8n
# image: curlimages/curl:latest
# depends_on:
# - ubuntu-22
# - ubuntu-20
# - ubuntu-18
# commands:
# - curl https://n8n.ahkhan.me/webhook/drone/gitea/docker/ubuntu -H 'Authorization:Bearer wJlK5lDvTUS03Cfd4RWKyQ'

View File

@@ -2,40 +2,60 @@ ARG UBUNTU_VER
FROM ubuntu:${UBUNTU_VER} FROM ubuntu:${UBUNTU_VER}
ARG TARGETPLATFORM
ENV DEBIAN_FRONTEND=noninteractive ENV DEBIAN_FRONTEND=noninteractive
# Enable autocompletion # Enable autocompletion and install packages in optimized layers
RUN rm /etc/apt/apt.conf.d/docker-* RUN rm /etc/apt/apt.conf.d/docker-* && \
RUN echo "if [ -f /etc/bash_completion ] && ! shopt -oq posix; then \ echo 'if [ -f /etc/bash_completion ] && ! shopt -oq posix; then . /etc/bash_completion; fi' >> /root/.bashrc
. /etc/bash_completion; \
fi" >> /root/.bashrc
RUN apt update RUN apt update && apt install -y \
# Basic utilities
curl wget nano lsb-release sudo bash-completion jq git screen cron \
# Basic networking tools
net-tools iputils-ping iproute2 iptables dnsutils \
# Network diagnostic and probing tools
tcpdump traceroute netcat-openbsd nmap telnet whois mtr-tiny socat \
# Network performance tools
iperf3 speedtest-cli \
# Network configuration utilities
resolvconf bridge-utils vlan \
# VPN and tunneling tools
wireguard-tools openvpn stunnel4 \
# Packet analysis tools
tshark \
# Programming languages and runtimes
python3 python3-pip python3-venv python3-dev \
# Development tools
software-properties-common build-essential \
# Remote access
openssh-server \
# Localization
locales
# Note: Keeping apt cache for dev convenience
RUN apt install -y curl wget nano lsb-release nano sudo bash-completion jq git screen cron # Install Node.js using official NodeSource repository
RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - && \
apt-get install -y nodejs
RUN apt install -y net-tools iputils-ping tcpdump traceroute iproute2 iptables iperf3 dnsutils speedtest-cli # Configure locales
RUN apt install -y software-properties-common
RUN apt install -y openssh-server
# Installing locales
RUN apt install -y locales
ENV LC_ALL=en_US.UTF-8 ENV LC_ALL=en_US.UTF-8
ENV LANG=en_US.UTF-8 ENV LANG=en_US.UTF-8
RUN locale-gen en_US.UTF-8 RUN locale-gen en_US.UTF-8
# Allow non-root users to run sudo command without password. # Configure SSH
RUN mkdir -p /var/run/sshd
# Allow non-root users to run sudo command without password
RUN echo "ALL ALL=NOPASSWD:ALL" > /etc/sudoers.d/01-allow-sudo RUN echo "ALL ALL=NOPASSWD:ALL" > /etc/sudoers.d/01-allow-sudo
COPY scripts/entrypoint.sh /entrypoint.sh COPY scripts/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENV LOG_FILE=/dev/null ENV LOG_FILE=/dev/null
# Reset DEBIAN_FRONTEND # Reset DEBIAN_FRONTEND
ENV DEBIAN_FRONTEND="" ENV DEBIAN_FRONTEND=""
CMD [ "/entrypoint.sh" ] EXPOSE 22
CMD ["/entrypoint.sh"]

View File

@@ -1,33 +1,78 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -x set -x
term_handler() { # Gracefully update package lists if network is available
eval $USER_COMMAND_EXIT echo "Checking network connectivity..."
eval $SYS_COMMAND_EXIT if ping -c 1 -W 5 8.8.8.8 >/dev/null 2>&1 || ping -c 1 -W 5 1.1.1.1 >/dev/null 2>&1; then
echo "Network detected, refreshing package lists..."
if sudo apt update; then
echo "Package lists updated successfully"
else
echo "Warning: apt update failed despite network connectivity"
echo "Falling back to cached package lists"
fi
else
echo "No network connectivity detected, using cached package lists"
fi
exit 143; # 128 + 15 -- SIGTERM # Global variable to track background processes
TAIL_PID=""
term_handler() {
echo "Received termination signal, cleaning up..."
# Kill the tail process if it's running
if [[ -n "$TAIL_PID" ]]; then
kill "$TAIL_PID" 2>/dev/null
fi
# Run user-defined exit commands
eval "$COMMAND_EXIT"
echo "Cleanup completed, exiting..."
exit 0
} }
# setup handler when the container is exited # Setup signal handlers for graceful shutdown
trap 'kill ${!}; term_handler' SIGTERM trap 'term_handler' SIGTERM SIGINT
# setup home directory for the current user. It is useful for attaching vscode with container. # setup home directory for the current user. It is useful for attaching vscode with container.
user_name=$(whoami) user_name=$(whoami)
user_home="/home/$user_name" user_home="/home/$user_name"
sudo mkdir -p $user_home
sudo chown -R $(id -u):$(id -g) $user_home
cp -r /etc/skel/. $user_home
if [[ $LOG_FILE != "/dev/null" ]]; # Only create home directory if it doesn't exist (handles mounted /etc/passwd case)
then if [[ ! -d "$user_home" ]]; then
sudo touch $LOG_FILE sudo mkdir -p "$user_home"
sudo chown -R $(id -u):$(id -g) $LOG_FILE sudo chown -R "$(id -u):$(id -g)" "$user_home"
# Copy skeleton files only if home directory was created
cp -r /etc/skel/. "$user_home" 2>/dev/null || true
fi fi
if [[ $LOG_FILE != "/dev/null" ]]; then
sudo touch "$LOG_FILE"
sudo chown -R "$(id -u):$(id -g)" "$LOG_FILE"
fi
echo "Starting SSH service..."
sudo service ssh start sudo service ssh start
eval $USER_COMMAND_INIT # Run initialization commands
eval $SYS_COMMAND_INIT eval "$COMMAND_INIT"
eval $USER_COMMAND_SETUP
tail -f $LOG_FILE & wait ${!} # Start the main process loop
if [[ $LOG_FILE == "/dev/null" ]]; then
# If no log file, just wait for signals
echo "Container ready, waiting for signals..."
while true; do
sleep 1 &
wait $!
done
else
# If log file specified, tail it
echo "Container ready, tailing log file: $LOG_FILE"
tail -f "$LOG_FILE" &
TAIL_PID=$!
# Wait for the tail process or signals
wait $TAIL_PID
fi