From 6babe327b4ac2fce4683bc76055049861435ed60 Mon Sep 17 00:00:00 2001 From: Marvin Zhang Date: Wed, 20 Nov 2024 14:42:15 +0800 Subject: [PATCH] ci: updated base-image --- .../install/chromedriver/chromedriver.sh | 64 +++++++++++++++---- docker/base-image/install/node/node.sh | 26 ++++---- 2 files changed, 65 insertions(+), 25 deletions(-) diff --git a/docker/base-image/install/chromedriver/chromedriver.sh b/docker/base-image/install/chromedriver/chromedriver.sh index 2677b376..c8bc0cf5 100644 --- a/docker/base-image/install/chromedriver/chromedriver.sh +++ b/docker/base-image/install/chromedriver/chromedriver.sh @@ -1,25 +1,63 @@ #!/bin/bash -# version +# version - using "stable" for installation but not for verification version="stable" # deps apt-get install -y xvfb libxi6 libgconf-2-4 -# install chrome -npx @puppeteer/browsers install chrome@${version} +# install puppeteer browsers package globally first +npm install -g @puppeteer/browsers -# verify chrome version -if [[ ! "$(google-chrome --version)" =~ ^Google\ Chrome\ ${version} ]]; then - echo "ERROR: chrome version does not match. expected: \"Google Chrome ${version}\", but actual is \"$(google-chrome --version)\"" - exit 1 +# install chrome with auto-yes +npx -y @puppeteer/browsers install chrome@${version} + +# verify chrome is installed (without specific version check) +if ! command -v google-chrome &> /dev/null; then + echo "ERROR: Chrome is not installed properly" + exit 1 fi -# install chromedriver -npx @puppeteer/browsers install chromedriver@${version} +# install chromedriver with auto-yes +npx -y @puppeteer/browsers install chromedriver@${version} -# verify chromedriver version -if [[ ! "$(chromedriver --version)" =~ ^ChromeDriver\ ${version} ]]; then - echo "ERROR: chromedriver version does not match. expected: \"ChromeDriver ${version}\", but actual is \"$(chromedriver --version)\"" - exit 1 +# verify chromedriver is installed (without specific version check) +if ! command -v chromedriver &> /dev/null; then + echo "ERROR: ChromeDriver is not installed properly" + exit 1 fi + +# Print installed versions for reference +echo "Installed Chrome version: $(google-chrome --version)" +echo "Installed ChromeDriver version: $(chromedriver --version)" + +# Create a temporary directory for the test +TEST_DIR=$(mktemp -d) +cd "$TEST_DIR" + +# Create a simple test script +cat > test.py << 'EOL' +from selenium import webdriver +from selenium.webdriver.chrome.options import Options + +try: + chrome_options = Options() + chrome_options.add_argument('--headless') + chrome_options.add_argument('--no-sandbox') + chrome_options.add_argument('--disable-dev-shm-usage') + + driver = webdriver.Chrome(options=chrome_options) + driver.get('https://www.google.com') + print("ChromeDriver test successful!") + driver.quit() +except Exception as e: + print(f"ChromeDriver test failed: {str(e)}") + exit(1) +EOL + +# Run the test +python3 test.py + +# Clean up +cd - +rm -rf "$TEST_DIR" diff --git a/docker/base-image/install/node/node.sh b/docker/base-image/install/node/node.sh index 12af4299..4b85d99e 100644 --- a/docker/base-image/install/node/node.sh +++ b/docker/base-image/install/node/node.sh @@ -1,23 +1,25 @@ #!/bin/bash +version="22" + # installs nvm (Node Version Manager) curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash -# download and install Node.js (you may need to restart the terminal) -nvm install 22 +# ensure changes take effect immediately +export NVM_DIR="$HOME/.nvm" +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm +[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion -# set node version -nvm use 22 +# download and install Node.js (you may need to restart the terminal) +nvm install ${version} + +# set node version and make it the default +nvm use ${version} +nvm alias default ${version} # verifies the right Node.js version is in the environment -if [[ ! "$(node -v)" =~ ^v22 ]]; then - echo "Node.js version is not v22.x" - exit 1 -fi - -# verifies the right npm version is in the environment -if [[ ! "$(npm -v)" =~ ^10 ]]; then - echo "npm version is not 10.x" +if [[ ! "$(node -v)" =~ ^v${version} ]]; then + echo "Node.js version is not v${version}.x" exit 1 fi