From 74c287b4b467e086584b8dec8e0cdb0f06ef081f Mon Sep 17 00:00:00 2001 From: Sree Iyer Date: Thu, 10 Sep 2026 14:08:44 +0000 Subject: [PATCH] Enable auto-complete in root login 1. Made auto complete to work in the root login also 2. Removed copy of hwsku.json 3. Upgraded deploy/vm/Dockerfile to a more recent Ubuntu 4. Added checks and retry in the docker save script 5. pkt-handler was being rebuilt as a safety option and this was adding random build logs on the console. Removed this 6. A script to download the official alpine build from github Signed-off-by: Sree Iyer --- docker-sonic-alpinevs.mk | 9 ----- docker-sonic-alpinevs/Dockerfile.j2 | 6 +++- pkt-handler.mk | 15 +++++++- src/build/build_alpinevs_docker_save.sh | 48 +++++++++++++++++++++++-- src/deploy/kne/vm/Dockerfile | 6 ++-- src/services/init/debian/install | 1 - utils/get_official_build.sh | 40 +++++++++++++++++++++ 7 files changed, 109 insertions(+), 16 deletions(-) create mode 100755 utils/get_official_build.sh diff --git a/docker-sonic-alpinevs.mk b/docker-sonic-alpinevs.mk index b6beba9..29440a7 100644 --- a/docker-sonic-alpinevs.mk +++ b/docker-sonic-alpinevs.mk @@ -46,14 +46,12 @@ SONIC_DOCKER_IMAGES += $(DOCKER_SONIC_ALPINEVS) SONIC_TRIXIE_DOCKERS += $(DOCKER_SONIC_ALPINEVS) ALPINEVS_DOCKER_STAGING_DIR := $(PLATFORM_PATH)/docker-sonic-alpinevs/bin -ALPINEVS_PKT_HANDLER_SRC_DIR := $(PLATFORM_PATH)/src/services/pkt-handler ALPINEVS_CONFIG_SRC := $(PLATFORM_PATH)/src/services/config/alpinevs-config.sh ALPINEVS_INIT_SRC := $(PLATFORM_PATH)/docker-sonic-alpinevs/alpinevs-init.sh ALPINEVS_ADMIN_USERNAME_FILE := $(ALPINEVS_DOCKER_STAGING_DIR)/sonic-admin.username ALPINEVS_ADMIN_PASSWORD_HASH := $(ALPINEVS_DOCKER_STAGING_DIR)/sonic-admin.password.hash ALPINEVS_DOCKER_STAGE_FILES := \ - $(ALPINEVS_DOCKER_STAGING_DIR)/pkt-handler \ $(ALPINEVS_DOCKER_STAGING_DIR)/alpinevs-config.sh \ $(ALPINEVS_DOCKER_STAGING_DIR)/alpinevs-init.sh \ $(ALPINEVS_ADMIN_USERNAME_FILE) \ @@ -77,13 +75,6 @@ $(ALPINEVS_ADMIN_PASSWORD_HASH): | $(ALPINEVS_DOCKER_STAGING_DIR) printf '%s\n' '!' > "$@"; \ fi -# Always rebuild it before staging the Docker build-context copy -.PHONY: $(ALPINEVS_DOCKER_STAGING_DIR)/pkt-handler -$(ALPINEVS_DOCKER_STAGING_DIR)/pkt-handler: | $(ALPINEVS_DOCKER_STAGING_DIR) - $(MAKE) -C $(ALPINEVS_PKT_HANDLER_SRC_DIR) clean - $(MAKE) -C $(ALPINEVS_PKT_HANDLER_SRC_DIR) all - cp $(ALPINEVS_PKT_HANDLER_SRC_DIR)/pkt-handler $@ - $(ALPINEVS_DOCKER_STAGING_DIR)/alpinevs-config.sh: \ $(ALPINEVS_CONFIG_SRC) | $(ALPINEVS_DOCKER_STAGING_DIR) cp -L $< $@ diff --git a/docker-sonic-alpinevs/Dockerfile.j2 b/docker-sonic-alpinevs/Dockerfile.j2 index 9f96dfd..b17cf31 100644 --- a/docker-sonic-alpinevs/Dockerfile.j2 +++ b/docker-sonic-alpinevs/Dockerfile.j2 @@ -115,7 +115,7 @@ RUN sed -ri 's/^# save ""$/save ""/g; \ COPY ["50-default.conf", "/etc/rsyslog.d/"] COPY ["start.sh", "orchagent.sh", "telemetry.sh", "files/update_chassisdb_config", "/usr/bin/"] -COPY ["alpinevs-script.sh", "alpinevs-healthcheck.sh", "p4rt.sh", "bin/alpinevs-init.sh","bin/alpinevs-config.sh","bin/pkt-handler", "/usr/bin/"] +COPY ["alpinevs-script.sh", "alpinevs-healthcheck.sh", "p4rt.sh", "bin/alpinevs-init.sh","bin/alpinevs-config.sh","/usr/bin/"] COPY ["uptime", "/usr/local/bin/uptime"] COPY ["docker", "/usr/local/bin/docker"] COPY ["supervisord.conf.j2", "/usr/share/sonic/templates/"] @@ -178,6 +178,10 @@ RUN sonic_admin="$(cat /tmp/sonic-admin.username)" && \ COPY sshd.conf /etc/supervisor/conf.d/sshd.conf +# Enable CLI completion in interactive root shells, including sudo su. +RUN printf '\nif [ -r /usr/share/bash-completion/bash_completion ]; then\n . /usr/share/bash-completion/bash_completion\nfi\n' \ + >> /root/.bashrc + ENV PLATFORM=x86_64-kvm_x86_64-r0 ENV HWSKU=alpinevs ENV SOC_TARGET_SERVER=127.0.0.1:50000 diff --git a/pkt-handler.mk b/pkt-handler.mk index df1f522..bec5273 100644 --- a/pkt-handler.mk +++ b/pkt-handler.mk @@ -4,6 +4,19 @@ ALPINE_SRC_PATH=platform/alpinevs PKT_HANDLER = lucius-pkthandler_1.0-2_$(CONFIGURED_ARCH).deb $(PKT_HANDLER)_SRC_PATH = $(ALPINE_SRC_PATH)/src/services/pkt-handler $(PKT_HANDLER)_DEPENDS += $(LIBNL3_DEV) $(LIBNL_GENL3_DEV) - $(PKT_HANDLER)_RDEPENDS += $(LIBNL3) $(LIBNL_GENL3) + +PKT_HANDLER_SRC_FILES = \ + $(wildcard $($(PKT_HANDLER)_SRC_PATH)/*.go) \ + $(wildcard $($(PKT_HANDLER)_SRC_PATH)/go.mod) \ + $(wildcard $($(PKT_HANDLER)_SRC_PATH)/go.sum) \ + $($(PKT_HANDLER)_SRC_PATH)/Makefile \ + $($(PKT_HANDLER)_SRC_PATH)/lucius-pkthandler.service \ + $(wildcard $($(PKT_HANDLER)_SRC_PATH)/debian/*) + +$(addprefix $(DEBS_PATH)/,$(PKT_HANDLER)): $(PKT_HANDLER_SRC_FILES) + +$(DEBS_PATH)/$(PKT_HANDLER): $(PKT_HANDLER_SRC_FILES) +$(DOCKER_SONIC_ALPINEVS)_CONTAINER_DEBS += $(PKT_HANDLER) + SONIC_DPKG_DEBS += $(PKT_HANDLER) diff --git a/src/build/build_alpinevs_docker_save.sh b/src/build/build_alpinevs_docker_save.sh index 439fba8..9b509b6 100755 --- a/src/build/build_alpinevs_docker_save.sh +++ b/src/build/build_alpinevs_docker_save.sh @@ -1,4 +1,48 @@ -gzip -d -c target/sonic-alpinevs.img.gz > platform/alpinevs/src/deploy/kne/vm/vm.img +#!/bin/bash +set -eo pipefail + +IMAGE_FILE="target/sonic-alpinevs.img.gz" +VM_DIR="platform/alpinevs/src/deploy/kne/vm" +MAX_RETRIES=3 +RETRY_DELAY=5 + +# 1. Check if input image exists before proceeding +if [ ! -f "$IMAGE_FILE" ]; then + echo "ERROR: File '$IMAGE_FILE' not found. Please run the build to produce sonic-alpinevs.img.gz first." >&2 + exit 1 +fi + +# 2. Decompress input image +mkdir -p "$VM_DIR" +gzip -d -c "$IMAGE_FILE" > "$VM_DIR/vm.img" + +# 3. Ensure Docker service is running sudo service docker status > /dev/null 2>&1 || (sudo service docker start > /dev/null 2>&1 && ./scripts/wait_for_docker.sh 60) -DOCKER_BUILDKIT=0 docker build platform/alpinevs/src/deploy/kne/vm -t alpine-vs:latest + +# 4. Docker build with retry logic for network/package retrieval failures +build_passed=0 +for ((i=1; i<=MAX_RETRIES; i++)); do + echo "Building docker image 'alpine-vs:latest' (Attempt $i/$MAX_RETRIES)..." + if DOCKER_BUILDKIT=0 docker build "$VM_DIR" -t alpine-vs:latest; then + build_passed=1 + echo "Docker build succeeded." + break + else + echo "WARNING: Docker build failed on attempt $i." >&2 + if [ $i -lt $MAX_RETRIES ]; then + echo "Retrying in ${RETRY_DELAY} seconds..." >&2 + sleep $RETRY_DELAY + fi + fi +done + +if [ $build_passed -ne 1 ]; then + echo "ERROR: Docker build failed after $MAX_RETRIES attempts." >&2 + exit 1 +fi + +# 5. Save the final image tarball +mkdir -p target docker save alpine-vs:latest | gzip -c > target/sonic-alpinevs-docker.tar.gz + +echo "Successfully built and exported target/sonic-alpinevs-docker.tar.gz" diff --git a/src/deploy/kne/vm/Dockerfile b/src/deploy/kne/vm/Dockerfile index c34e222..a3bdde9 100644 --- a/src/deploy/kne/vm/Dockerfile +++ b/src/deploy/kne/vm/Dockerfile @@ -1,8 +1,10 @@ -FROM ubuntu:20.04 +FROM ubuntu:22.04 ARG DEBIAN_FRONTEND=noninteractive RUN apt-get update -qy \ - && apt-get upgrade -qy \ + && apt-get install -qy --no-install-recommends software-properties-common \ + && add-apt-repository -y universe \ + && apt-get update -qy \ && apt-get install -y \ bridge-utils \ iproute2 \ diff --git a/src/services/init/debian/install b/src/services/init/debian/install index 911545e..316f1c4 100644 --- a/src/services/init/debian/install +++ b/src/services/init/debian/install @@ -4,4 +4,3 @@ alpinevs-init.service lib/systemd/system/ pmon_daemon_control.json usr/share/sonic/device/x86_64-kvm_x86_64-r0/alpine_vs sai.profile usr/share/sonic/device/x86_64-kvm_x86_64-r0/alpine_vs platform.json usr/share/sonic/device/x86_64-kvm_x86_64-r0/alpine_vs -hwsku.json usr/share/sonic/device/x86_64-kvm_x86_64-r0/alpine_vs diff --git a/utils/get_official_build.sh b/utils/get_official_build.sh new file mode 100755 index 0000000..14441e1 --- /dev/null +++ b/utils/get_official_build.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +set -euo pipefail + + +#Script to download the official alpine build from Github + +API="https://dev.azure.com/mssonic/build/_apis/build" + +# DEFINITION_ID = 1 to download alpine from sonic-buildimage master build, +# DEFINITION_ID = 3412 to download alpine from the alpine official build +# Both are practically the same +DEFINITION_ID="1" +BRANCH="master" +ARTIFACT="sonic-buildimage.alpinevs" +IMAGE="target/sonic-alpinevs.img.gz" + +BUILD_ID=$( + curl -fsSL \ + "$API/builds?definitions=$DEFINITION_ID&branchName=refs/heads/$BRANCH&resultFilter=succeeded&queryOrder=finishTimeDescending&%24top=1&api-version=7.1" | jq -er '.value[0].id' +) + +ZIP_URL=$( + curl -fsSL "$API/builds/$BUILD_ID/artifacts?artifactName=$ARTIFACT&api-version=7.1" | jq -er '.resource.downloadUrl' +) + +echo "Build ID: $BUILD_ID" +echo "Artifact ZIP URL: $ZIP_URL" + +OUTPUT_FILE="${ARTIFACT}-${BUILD_ID}.zip" +echo "Downloading $OUTPUT_FILE..." + +curl -L -C - \ + --retry 100 \ + --retry-delay 5 \ + --retry-all-errors \ + --connect-timeout 60 \ + -o "$OUTPUT_FILE" \ + "$ZIP_URL" + +echo "Download complete: $(pwd)/$OUTPUT_FILE"