Skip to content

Commit

Permalink
Add a helper script to build and update the dashboard UI in a running…
Browse files Browse the repository at this point in the history
… container
  • Loading branch information
nwmac committed Aug 15, 2024
1 parent cb6adea commit 02b4a5a
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions scripts/patch-docker-container
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env bash

DIR=$(cd $(dirname $0)/..; pwd)

CYAN="\033[96m"
YELLOW="\033[93m"
RESET="\033[0m"
BOLD="\033[1m"

echo -e "${CYAN}${BOLD}============================================================${RESET}"
echo -e "${CYAN}${BOLD}Patch running Rancher Docker container with dev Dashboard UI${RESET}"
echo -e "${CYAN}${BOLD}============================================================${RESET}"
echo ""
echo "This script will build the Dashboard UI and copy the built UI into the specified running Rancher container"
echo ""

if [ -z "$1" ]; then
echo -e "${YELLOW}Need ID of Rancher container to patch${RESET}"
exit 1
fi

DOCKER=$(docker version > /dev/null)
if [ $? -ne 0 ]; then
echo -e "${YELLOW}Can not run Docker commands - is Docker running?${RESET}"
exit 1
fi

CONTAINER=$1

# Check container exists and looks like a Rancher container
VERSION=$(docker exec ${CONTAINER} /bin/bash -c "printenv CATTLE_DASHBOARD_UI_VERSION")

if [ $? -ne 0 ]; then
echo -e "${YELLOW}Could not get version env var from container - check the container ID${RESET}"
exit 1
fi

echo "Dashboard UI version from existing container: ${VERSION}"

# Check we have node and yarn installed

node --version > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "${YELLOW}node does not appear to be installed - this is required to build the UI${RESET}"
exit 1
fi

yarn --version > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "${YELLOW}yarn does not appear to be installed - this is required to build the UI${RESET}"
exit 1
fi

if [ ! -d node_modules ]; then
echo -e "${YELLOW}node_modules folder does not exist - running yarn install${RESET}"
yarn install
fi

set -e

# Prepare dist folder
DIST=${DIR}/dist
mkdir -p ${DIST}
DIST=$DIST/production

# Clean old build
rm -rf ${DIST}

echo -e "${CYAN}Building production build of Dashboard${RESET}"

# Build dashboard with the correct router base
OUTPUT_DIR=${DIST} ROUTER_BASE='/dashboard/' RESOURCE_BASE='/dashboard/' yarn run build

# Delete the existing UI in the conatiner
docker exec ${CONTAINER} rm -rf /usr/share/rancher/ui-dashboard/dashboard
docker cp ${DIST} ${CONTAINER}:/usr/share/rancher/ui-dashboard/dashboard

echo ""
echo "All done"
echo -e "${YELLOW}Note: It is recommended to set the Rancher 'ui-offline-preferred' setting to 'Local' to ensure the embedded UI is always used${RESET}"
echo ""

0 comments on commit 02b4a5a

Please sign in to comment.