AppiumTestDistribution / appium-device-farm

This is an Appium 2.0 plugin designed to manage and create driver sessions on available devices.
https://devicefarm.org
Other
337 stars 102 forks source link

Device-farm plugin cannot be detected. #712

Closed win5923 closed 1 year ago

win5923 commented 1 year ago

Hello, I am using https://github.com/appium/appium-docker-android to install device-farm and appium-dashboard with Docker Appium. However, for some reason, appium-dashboard can be detected, but device-farm cannot. Below is my Dockerfile:

FROM ubuntu:focal-20230308

ENV DEBIAN_FRONTEND=noninteractive

#==================
# General Packages
#------------------
# ca-certificates
#   SSL client
# curl
#   Transfer data from or to a server
# gnupg
#   Encryption software. It is needed for nodejs
# libgconf-2-4
#   Required package for chrome and chromedriver to run on Linux
# libqt5webkit5
#   Web content engine (Fix issue in Android)
# openjdk-11-jdk
#   Java
# sudo
#   Sudo user
# tzdata
#   Timezone
# unzip
#   Unzip zip file
# wget
#   Network downloader
# xvfb
#   X virtual framebuffer
# zip
#   Make a zip file
#==================
RUN apt-get -qqy update && \
    apt dist-upgrade -y && \
    apt-get -qqy --no-install-recommends install \
    ca-certificates \
    curl \
    gnupg \
    libgconf-2-4 \
    libqt5webkit5 \
    openjdk-11-jdk \
    sudo \
    tzdata \
    unzip \
    wget \
    xvfb \
    zip \
  && rm -rf /var/lib/apt/lists/*

#===============
# Set JAVA_HOME
#===============
ENV JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64" \
    PATH=$PATH:$JAVA_HOME/bin

#===============================
# Set Timezone (UTC as default)
#===============================
ENV TZ "UTC"
RUN echo "${TZ}" > /etc/timezone \
  && dpkg-reconfigure --frontend noninteractive tzdata

#===============
# Create a user
#===============
ARG USER_PASS=secret
RUN groupadd androidusr \
         --gid 1301 \
  && useradd androidusr \
         --uid 1300 \
         --gid 1301 \
         --create-home \
         --shell /bin/bash \
  && usermod -aG sudo androidusr \
  && echo androidusr:${USER_PASS} | chpasswd \
  && echo 'androidusr ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers

WORKDIR /home/androidusr

#=====================
# Install Android SDK
#=====================
ENV SDK_VERSION=commandlinetools-linux-8512546_latest
ENV ANDROID_BUILD_TOOLS_VERSION=33.0.0
ENV ANDROID_FOLDER_NAME=cmdline-tools
ENV ANDROID_DOWNLOAD_PATH=/home/androidusr/${ANDROID_FOLDER_NAME} \
    ANDROID_HOME=/opt/android \
    ANDROID_TOOL_HOME=/opt/android/${ANDROID_FOLDER_NAME}

RUN wget -O tools.zip https://dl.google.com/android/repository/${SDK_VERSION}.zip && \
    unzip tools.zip && rm tools.zip && \
    chmod a+x -R ${ANDROID_DOWNLOAD_PATH} && \
    chown -R 1300:1301 ${ANDROID_DOWNLOAD_PATH} && \
    mkdir -p ${ANDROID_TOOL_HOME} && \
    mv ${ANDROID_DOWNLOAD_PATH} ${ANDROID_TOOL_HOME}/tools
ENV PATH=$PATH:${ANDROID_TOOL_HOME}/tools:${ANDROID_TOOL_HOME}/tools/bin

# https://askubuntu.com/questions/885658/android-sdk-repositories-cfg-could-not-be-loaded
RUN mkdir -p ~/.android && \
    touch ~/.android/repositories.cfg && \
    echo y | sdkmanager "platform-tools" && \
    echo y | sdkmanager "build-tools;$ANDROID_BUILD_TOOLS_VERSION" && \
    mv ~/.android .android && \
    chown -R 1300:1301 .android
ENV PATH=$PATH:$ANDROID_HOME/platform-tools:$ANDROID_HOME/build-tools

#====================================
# Install latest nodejs, npm, appium
# Using this workaround to install Appium -> https://github.com/appium/appium/issues/10020 -> Please remove this workaround asap
#====================================
ENV NODE_VERSION=18
ENV APPIUM_VERSION=2.0.0-beta.63
RUN curl -sL https://deb.nodesource.com/setup_${NODE_VERSION}.x | bash && \
    apt-get -qqy install nodejs && \
    npm install -g appium@${APPIUM_VERSION} && \
    exit 0 && \
    npm cache clean && \
    apt-get remove --purge -y npm && \
    apt-get autoremove --purge -y && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
    apt-get clean

#====================================================
# Fix permission issue to download e.g. chromedriver
#====================================================
RUN chown -R 1300:1301 /usr/lib/node_modules/appium

#==============
# Copy scripts
#==============
ENV SCRIPT_PATH="appium-docker-android"
RUN mkdir -p ${SCRIPT_PATH}
COPY start.sh \
     generate_selenium_config.sh \
     wireless_autoconnect.sh \
     wireless_connect.sh \
     ${SCRIPT_PATH}/
RUN chown -R 1300:1301 ${SCRIPT_PATH}
ENV APP_PATH=/home/androidusr/${SCRIPT_PATH}

#==================
# Use created user
#==================
USER 1300:1301

#===============================
# Install basic Android drivers
#===============================
ENV APPIUM_DRIVER_FLUTTER_VERSION="1.14.3"
ENV APPIUM_DRIVER_ESPRESSO_VERSION="2.20.1"
ENV APPIUM_DRIVER_UIAUTOMATOR2_VERSION="2.14.0"
ENV APPIUM_PLUGIN_DASHBOARD_VERSION="2.0.2"
ENV APPIUM_PLUGIN_DEVICE_FARM_VERSION="7.2.0"
RUN appium driver install --source=npm appium-espresso-driver@${APPIUM_DRIVER_ESPRESSO_VERSION} && \
    appium driver install --source=npm appium-flutter-driver@${APPIUM_DRIVER_FLUTTER_VERSION} && \
    appium driver install --source=npm appium-uiautomator2-driver@${APPIUM_DRIVER_UIAUTOMATOR2_VERSION} && \
    sudo appium plugin install --source=npm appium-device-farm@${APPIUM_PLUGIN_DEVICE_FARM_VERSION} && \
    appium plugin install --source=npm appium-dashboard@${APPIUM_PLUGIN_DASHBOARD_VERSION}

#===============
# Expose Port
#---------------
# 4723
#   Appium port
#===============
EXPOSE 4723

#==============
# Start script
#==============
CMD ./${SCRIPT_PATH}/start.sh

Here is the log for Appium:

Prepare adb to have access to device
* daemon not running; starting now at tcp:5037
* daemon started successfully
adb can be used now
[Appium] Attempting to load plugin appium-dashboard...
[debug] [Appium] Requiring plugin at /home/androidusr/.appium/node_modules/appium-dashboard
[ADB] Found 1 'build-tools' folders under '/opt/android' (newest first):
[ADB]     /opt/android/build-tools/33.0.0
[ADB] Using 'adb' from '/opt/android/platform-tools/adb'
[debug] [ADB] Running '/opt/android/platform-tools/adb -P 5037 start-server'
[Appium] Welcome to Appium v2.0.0-beta.63
[Appium] Non-default server args:
[Appium] { allowCors: true,
[Appium]   basePath: '/wd/hub',
[Appium]   keepAliveTimeout: 800,
[Appium]   relaxedSecurityEnabled: true,
[Appium]   usePlugins: [ 'device-farm', 'appium-dashboard' ] }
[Appium] Attempting to load driver espresso...
[debug] [Appium] Requiring driver at /home/androidusr/.appium/node_modules/appium-espresso-driver
[Appium] Attempting to load driver flutter...
[debug] [Appium] Requiring driver at /home/androidusr/.appium/node_modules/appium-flutter-driver
[Appium] Attempting to load driver uiautomator2...
[debug] [Appium] Requiring driver at /home/androidusr/.appium/node_modules/appium-uiautomator2-driver
[appium-dashboard] Dashboard plugin is enabled and will be served at http://localhost:4723/dashboard
[appium-dashboard] If the appium server is started with different port other than 4723, then use the correct port number to access the device farm dashboard
(node:34) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exit listeners added to [process]. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)
[Appium] You have enabled CORS requests from any host. Be careful not to visit sites which could maliciously try to start Appium sessions on your machine
[Appium] Appium REST http interface listener started on 0.0.0.0:4723/wd/hub
[Appium] Available drivers:
[Appium]   - espresso@2.20.1 (automationName 'Espresso')
[Appium]   - flutter@1.14.3 (automationName 'Flutter')
[Appium]   - uiautomator2@2.14.0 (automationName 'UiAutomator2')
[Appium] Available plugins:
[Appium]   - appium-dashboard@v2.0.2 (ACTIVE)
[appium-dashboard] Video directory created /home/androidusr/.cache/appium-dashboard-plugin/videos

If I install device-farm without using sudo, the following error will occur:

#0 57.60 - Installing 'appium-device-farm@7.2.0'
#0 77.69 ✖ Installing 'appium-device-farm@7.2.0'
#0 77.69 Error: ✖ Encountered an error when installing package: npm command 'install --save-dev --omit=peer --save-exact --global-style --no-package-lock appium-device-farm@7.2.0 --json' failed with code 1.
#0 77.69 
#0 77.69 STDOUT:
#0 77.69 {
#0 77.69   "error": {
#0 77.69     "code": 1,
#0 77.69     "summary": "command failed",
#0 77.69     "detail": "sh -c node postinstall.js install\nCopying the relevant binary for your platform linux\n\u001b[32m go-ios installed, run 'ios --help' for details\n[Error: EACCES: permission denied, rename 'bin/ios' -> '/usr/bin/ios'] {\n  errno: -13,\n  code: 'EACCES',\n  syscall: 'rename',\n  path: 'bin/ios',\n  dest: '/usr/bin/ios'\n}"
#0 77.69   }
#0 77.69 }
#0 77.69 
#0 77.69 STDERR:
#0 77.69 npm WARN config global-style This option has been deprecated in favor of `--install-strategy=shallow`
#0 77.69 npm WARN deprecated debug@4.1.1: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
#0 77.69 npm ERR! code 1
#0 77.69 npm ERR! path /home/androidusr/.appium/node_modules/appium-device-farm/node_modules/go-ios
#0 77.69 npm ERR! command failed
#0 77.69 npm ERR! command sh -c node postinstall.js install
#0 77.69 npm ERR! Copying the relevant binary for your platform linux
#0 77.69 npm ERR!  go-ios installed, run 'ios --help' for details
#0 77.69 npm ERR! [Error: EACCES: permission denied, rename 'bin/ios' -> '/usr/bin/ios'] {
#0 77.69 npm ERR!   errno: -13,
#0 77.69 npm ERR!   code: 'EACCES',
#0 77.69 npm ERR!   syscall: 'rename',
#0 77.69 npm ERR!   path: 'bin/ios',
#0 77.69 npm ERR!   dest: '/usr/bin/ios'
#0 77.69 npm ERR! }
#0 77.69 
#0 77.69 npm ERR! A complete log of this run can be found in:
#0 77.69 npm ERR!     /home/androidusr/.npm/_logs/2023-04-18T08_31_08_395Z-debug-0.log
saikrishna321 commented 1 year ago

@win5923 Can you check this - https://github.com/AppiumTestDistribution/appium-device-farm/issues/699#issuecomment-1506654568

win5923 commented 1 year ago

sure.but I don't have espressoBuildConfig.json file.

saikrishna321 commented 1 year ago

Can you share the sample project with dockerfile and start.sh

win5923 commented 1 year ago

I mean the dockerfile in #699 (comment), I don't have the files mentioned in its command:

COPY start_device_farm.sh
espressoBuildConfig.json
keystore.jks
/root/
ValzRon commented 1 year ago

@win5923 What does your start script look like? Are you using a config file (json/yaml) for your Appium start params?

win5923 commented 1 year ago

@ValzRon https://github.com/appium/appium-docker-android/blob/master/Appium/start.sh Yes,the start script is from docker-appium-android

saikrishna321 commented 1 year ago

@win5923 @ValzRon I observed go-ios fails to install on certain docker images. Like appium-docker-android

saikrishna321 commented 1 year ago

713