Run Flutter integration tests for Linux desktop in Docker - linux

I'm trying to run integration tests for a Linux desktop application in a Docker container.
I have a working project, running successful integration tests on Linux device.
I created a Docker image from the following Dockerfile content:
FROM cirrusci/flutter:stable
RUN apt-get update && \
export DEBIAN_FRONTEND=noninteractive && \
apt-get -y install --no-install-recommends unzip pkg-config clang cmake ninja-build libgtk-3-dev libappindicator1 fonts-liberation gpg-agent libxi6 libgconf-2-4 && \
wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add - && \
sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && \
apt-get update && apt-get -y install google-chrome-stable && \
CHROMEVER=$(google-chrome --product-version | grep -o "[^\.]*\.[^\.]*\.[^\.]*") && \
DRIVERVER=$(curl -s "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROMEVER") && \
wget -q --continue -P /chromedriver "http://chromedriver.storage.googleapis.com/$DRIVERVER/chromedriver_linux64.zip" && \
unzip /chromedriver/chromedriver* -d /chromedriver && \
rm -rf /var/lib/apt/lists/*
ENV PATH $CHROMEDRIVER_DIR:$PATH
I'm not sure I need Chrome and Chromedriver for my usecase, but at least it's here.
When running "flutter doctor" from this image, I get:
Doctor summary (to see all details, run flutter doctor -v):
[!] Flutter (Channel unknown, 3.3.8, on Ubuntu 22.04 LTS 5.15.0-53-generic, locale en_US.UTF-8)
! Flutter version 3.3.8 on channel unknown at /sdks/flutter
! Upstream repository unknown
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[!] Android Studio (not installed)
[✓] Connected device (2 available)
[✓] HTTP Host Availability
! Doctor found issues in 2 categories.
which seems quite OK.
However when running my integration tests, attempting to give access to my local X server (I'm using Ubuntu 22.04 on Wayland):
docker run --rm -it -v ${PWD}:/workspace --privileged -w /workspace -e DISPLAY="unix:0" -v /tmp/.X11-unix:/tmp/.X11-unix flutter:local /bin/sh -c "flutter clean && flutter test integration_test"
The tests fail with:
Deleting build... 14ms
Deleting .dart_tool... 3ms
Deleting ephemeral... 3ms
Deleting ephemeral... 0ms
Deleting ephemeral... 0ms
Deleting .flutter-plugins-dependencies... 0ms
Deleting .flutter-plugins... 0ms
Downloading Web SDK... 1,658ms
Downloading CanvasKit... 1,084ms
Downloading linux-x64/linux-x64-flutter-gtk tools... 1,090ms
Downloading linux-x64-profile/linux-x64-flutter-gtk tools... 156ms
Downloading linux-x64-release/linux-x64-flutter-gtk tools... 124ms
Running "flutter pub get" in workspace... 1,498ms
00:00 +0: loading /workspace/integration_test/main_test.dart B00:07 +0: loading /workspace/integration_test/main_test.dart
Error waiting for a debug connection: The log reader stopped unexpectedly, or never started.
00:07 +0 -1: loading /workspace/integration_test/main_test.dart [E]
TestDeviceException(Unable to start the app on the device.)
package:flutter_tools/src/test/integration_test_device.dart 60:7 IntegrationTestTestDevice.start
To run this test again: /sdks/flutter/bin/cache/dart-sdk/bin/dart test /workspace/integration_test/main_test.dart -p vm --plain-name 'loading /workspace/integration_test/main_test.dart'
00:07 +0 -1: Some tests failed.
Adding verbose to the test does not give much better than TestDeviceException(Unable to start the app on the device.)
I tried many things but I can't get it to work, and I can't find a lot of documentation on integration tests for desktop applications on Flutter, only on web applications, which is easier with headless Chrome.
If anyone has any hint about what could be wrong, I'd love it. Otherwise, I'll make my CI/CD run in shell mode on a non-headless VM instead of Docker, which I'd prefer not to.

Related

Debug remote .NET Core console app in Linux Docker fails with Visual Studio

I'm trying to debug a .NET Core 6 console app running in an Ubuntu LTS docker container on a Debian 10 Linux server from my Windows 11 Visual Studio IDE CE Preview.
Following these instructions:
I attach using SSH and Keys.
I see the containers.
I attach to the container.
I see my process.
I attach to the process.
I select Managed .NET Core for Linux.
I get this error:
Failed to launch debug adapter 'coreclr'.
Unable to find debugger script at '/nonexistent/.vs-debugger'.
Initialization log:
Determining user folder on remote system...
Checking for existing installation of debugging tools...
Downloading debugger launcher...
Creating debugger installation folder: /nonexistent/.vs-debugger
Failed: "Command 'mkdir -p '/nonexistent/.vs-debugger'' failed with code '1'. "
Unable to find debugger script at '/nonexistent/.vs-debugger'.
Failed: Unable to find debugger script at '/nonexistent/.vs-debugger'.
The program '[1] PlexCleaner' has exited with code 4294967295 (0xffffffff).
Similar error when remote attach in VSCode, and then attach to container:
[2354 ms] Start: Installing VS Code Server
[2354 ms] Start: Run in container: mkdir -p /nonexistent/.vscode-server-insiders/bin/0b3574dcef8f35fec4ee4f83dc958c1f16ef6fce-insider_1656694640395
[2360 ms]
[2361 ms] mkdir: cannot create directory ‘/nonexistent’: Permission denied
[2361 ms] Exit code 1
[2364 ms] Command in container failed: mkdir -p /nonexistent/.vscode-server-insiders/bin/0b3574dcef8f35fec4ee4f83dc958c1f16ef6fce-insider_1656694640395
[2364 ms] mkdir: cannot create directory ‘/nonexistent’: Permission denied
[2364 ms] Exit code 1
Any ideas?
There may be more elegant solutions, but I found that by manually installing the debugging tools I can attach without issue.
E.g. I now conditionally install the SDK and debug tools vs. just the runtime:
ARG DBGTOOL_INSTALL=""
RUN wget https://packages.microsoft.com/config/ubuntu/$(lsb_release -sr)/packages-microsoft-prod.deb \
&& dpkg -i packages-microsoft-prod.deb \
&& apt-get update \
&& if [ -n "$DBGTOOL_INSTALL" ] ; then \
apt-get install -y dotnet-sdk-6.0 ; \
else \
apt-get install -y dotnet-runtime-6.0 ; \
fi \
&& rm packages-microsoft-prod.deb \
&& dotnet --info
# Install remote debug tools
RUN if [ -n "$DBGTOOL_INSTALL" ] ; then \
wget https://aka.ms/getvsdbgsh \
&& sh getvsdbgsh -v latest -l /vsdbg \
&& rm getvsdbgsh ; \
fi

Flutter tests error on CI server after SDK upgrade

Working on upgrading an app from using Flutter SDK 2.0.6 to 2.8.1. Updated all the tests so that they pass locally on Intel Macbook Pro. Upgraded the docker image our CircleCI server uses to point to use the new SDK. The docker file looks like:
FROM circleci/android:api-30
RUN sudo apt-get install -y locales
RUN sudo dpkg-reconfigure locales
RUN /usr/sbin/locale-gen C.UTF-8
ENV LANG='C.UTF-8' LC_ALL='C.UTF-8'
RUN curl https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_2.8.1-stable.tar.xz -o /tmp/flutter.tar.xz && \
sudo tar -xvJ -C /opt -f /tmp/flutter.tar.xz && \
sudo chown -R circleci:circleci /opt/flutter && \
rm -f /tmp/flutter.tar.xz
ENV PATH="${PATH}:/opt/flutter/bin"
Now some of the unit tests on the CI server fail with the following error:
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following SocketException was thrown running a test:
Connection failed (OS Error: No such file or directory, errno = 2), address =
/var/run/dbus/system_bus_socket, port = 0
When the exception was thrown, this was the stack:
#0 _NativeSocket.startConnect (dart:io-patch/socket_patch.dart:681:35)
I'm a little out of my depth with running flutter in a CI server. What does that error mean, and what steps can I take to troubleshoot?
Later on in the stack trace it is ConnectivityLinux._startListenConnectivity (package:connectivity_plus_linux/src/connectivity.dart:61:20)
It turns out I needed to pass in a mocked connectionStream in my tests.

How to develop a new IoTAgent

I'm developing a new IoT Agent according to https://iotagent-node-lib.readthedocs.io/en/latest/howto/index.html
and I'm trying to run the following code: node index.js
but a warning shows up: (node:6176) [DEP0097] DeprecationWarning: Using a domain property in MakeCallback is deprecated. Use the async_context variant of MakeCallback or the AsyncResource class instead.
DEP0097 - Deprecation Warning (NODE.JS)
Any suggestions how to solve it?
thank you!
It appears that you are running your IoT Agent under Node 14. The Domain API has been deprecated and this is the cause of your warning. There is code within the IoT Agent Node lib currently uses the Domain API for communications with Telefonica Steelskin.
The IoT Agents are tested against LTS node releases, (currently 10 and 12 see here) and Node 14 doesn't hit LTS until October 2020, so I would expect an interim release should fix the issue.
In the meantime if you run your agent under an earlier version of Node - for example via Docker. An example can be found in the Custom IoT Agent tutorial Dockerfile
ARG NODE_VERSION=10.17.0-slim
FROM node:${NODE_VERSION}
COPY . /opt/iotXML/
WORKDIR /opt/iotXML
RUN \
apt-get update && \
apt-get install -y git && \
npm install pm2#3.2.2 -g && \
echo "INFO: npm install --production..." && \
npm install --production && \
# Remove Git and clean apt cache
apt-get clean && \
apt-get remove -y git && \
apt-get -y autoremove && \
chmod +x docker/entrypoint.sh
USER node
ENV NODE_ENV=production
# Expose 4041 for NORTH PORT, 7896 for HTTP PORT
EXPOSE ${IOTA_NORTH_PORT:-4041} ${IOTA_HTTP_PORT:-7896}
ENTRYPOINT ["docker/entrypoint.sh"]
CMD ["-- ", "config.js"]
The node version can be altered by adding NODE_VERSION to the Docker build command when building the Docker container.
The problem has to do with docker for windows toolbox. I installed linux and the custom iot agent worked. I think the problem ocurred because of the environment variables. For some reason windows 10 doesn't initiate .env archive variables that exist in the project.

Problem with Android Studio emulator in Docker container

I have a Docker container with Android studio 3.6 and it works perfectly. The problem is that the emulator does not run because the Ubuntu machine does not have the CPU to reproduce x86. Does anyone know how to include it in the Dockerfile ?. Thank you.
This is my Dockerfile:
FROM ubuntu:16.04
RUN dpkg --add-architecture i386
RUN apt-get update
# Download specific Android Studio bundle (all packages).
RUN apt-get install -y curl unzip
RUN apt-get install -y git
RUN curl 'https://uit.fun/repo/android-studio-ide-3.6.3-linux.tar.gz' > /studio.tar.gz && \
tar -zxvf studio.tar.gz && rm /studio.tar.gz
# Install X11
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get install -y xorg
# Install other useful tools
RUN apt-get install -y vim ant
# install Java
RUN apt-get install -y default-jdk
# Install prerequisites
RUN apt-get install -y libz1 libncurses5 libbz2-1.0:i386 libstdc++6 libbz2-1.0 lib32stdc++6 lib32z1
RUN apt-get install wget
RUN wget 'https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip' -P /tmp \
&& unzip -d /opt/android /tmp/sdk-tools-linux-4333796.zip
RUN apt install xserver-xorg-video-amdgpu
# Clean up
RUN apt-get clean
RUN apt-get purge
ENTRYPOINT [ "android-studio/bin/studio.sh" ]
When you're using ubuntu in docker, the only way to run an android emulator is to find a system image with "arm" (e.g. system-images;android-25;google_apis;armeabi-v7a).
However, even though you're able to run emulator in the container, you will probably be disappointed about that. Since emulator based on arm is typically slow enough to boot, not to mention that running in docker could be even slower.
If you really want to create it, you can do something like below.
sdkmanager "system-images;android-25;google_apis;armeabi-v7a"
avdmanager create avd -n demoTest -d "pixel" -k "system-images;android-25;google_apis;armeabi-v7a" -g "google_apis" -b "armeabi-v7a"
emulator #demoTest -no-window -no-audio -verbose &
Once you got this prompt message
emulator: got message from guest system fingerprint HAL
Your emulator is ready to go.

Cant launch chrome in docker linux container

I have an asp.net core application that uses the jsreport nuget packages to run reports. I am attempting to deploy it with a linux docker container. I seem to be having trouble getting chrome to launch when I run a report. I am getting the error:
Failed to launch chrome! Running as root without --no-sandbox is not supported.
I have followed the directions on the .net local reporting page (https://jsreport.net/learn/dotnet-local) regarding docker, but I am still getting the error.
Here is my full docker file:
#use the .net core 2.1 runtime default image
FROM microsoft/dotnet:2.1-aspnetcore-runtime
#set the working directory to the server
WORKDIR /server
#copy all contents in the current directory to the container server directory
COPY . /server
#install node
RUN apt-get update -yq \
&& apt-get install curl gnupg -yq \
&& curl -sL https://deb.nodesource.com/setup_8.x | bash \
&& apt-get install nodejs -yq
#install jsreport-cli
RUN npm install jsreport-cli -g
#install chrome for jsreport linux
RUN apt-get update && \
apt-get install -y gnupg libgconf-2-4 wget && \
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && \
apt-get update && \
apt-get install -y google-chrome-unstable --no-install-recommends
ENV chrome:launchOptions:executablePath google-chrome-unstable
ENV chrome:launchOptions:args --no-sandbox
#expose port 80
EXPOSE 80
CMD dotnet Server.dll
Is there another step that I am missing somewhere?
Its little late but may be can help someone else.
For me, the only option that was needed to fix this issue in the docker container was to run chrome in a headless mode (so cause was in tests not in dockerfile).
ChromeOptions options = new ChromeOptions().setHeadless(true);
WebDriver driver = new ChromeDriver(options);
Results: Now tests run successfully, without any errors.
Expanding on Pramod's answer, my own issues were only solved by running with both the --headless and --no-sandbox flags.

Resources