FritzTheCat9 / FreakFightsFan

FreakFightsFan contains information and statistics about federations, events, fights and fighters of freak fight federations. I created this application because I am a fan of freak fights and I wanted to practice building fullstack applications with .NET technologies.
0 stars 0 forks source link

fix: import fighters images do not work on linux (no chromedriver dependencies are installed) #23

Open FritzTheCat9 opened 1 month ago

FritzTheCat9 commented 1 month ago

I got logs on docker like this when trying to use selenium to get instagram fighters images:

2024-05-04 15:34:53 [13:34:53 ERR 06dfff20-b2d0-4dde-a569-7f96e37f7765] [Api Exception] "OpenQA.Selenium.WebDriverException: Cannot start the driver service on http://localhost:40937/\n   at OpenQA.Selenium.DriverService.Start()\n   at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)\n   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)\n   at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)\n   at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)\n   at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)\n   at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory, ChromeOptions options, TimeSpan commandTimeout)\n   at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory, ChromeOptions options)\n   at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory)\n   at FreakFightsFan.Api.Features.Images.Commands.ImportFighterImagesFeature.Handler.Handle(ImportFighterImagesCommand command, CancellationToken cancellationToken) in /src/FreakFightsFan.Api/Features/Images/Commands/ImportFighterImagesFeature.cs:line 70\n   at FreakFightsFan.Api.Behaviors.UnitOfWorkPipelineBehavior`2.Handle(TRequest request, RequestHandlerDelegate`1 next, CancellationToken cancellationToken) in /src/FreakFightsFan.Api/Behaviors/UnitOfWorkPipelineBehavior.cs:line 31\n   at FreakFightsFan.Api.Behaviors.ValidationPipelineBehavior`2.Handle(TRequest request, RequestHandlerDelegate`1 next, CancellationToken cancellationToken) in /src/FreakFightsFan.Api/Behaviors/ValidationPipelineBehavior.cs:line 37\n   at FreakFightsFan.Api.Behaviors.LoggingBehavior`2.Handle(TRequest request, RequestHandlerDelegate`1 next, CancellationToken cancellationToken) in /src/FreakFightsFan.Api/Behaviors/LoggingBehavior.cs:line 27\n   at FreakFightsFan.Api.Features.Images.Commands.ImportFighterImagesFeature.<>c.<<Endpoint>b__0_0>d.MoveNext() in /src/FreakFightsFan.Api/Features/Images/Commands/ImportFighterImagesFeature.cs:line 24\n--- End of stack trace from previous location ---\n   at Microsoft.AspNetCore.Http.RequestDelegateFactory.ExecuteTaskResult[T](Task`1 task, HttpContext httpContext)\n   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|7_0(Endpoint endpoint, Task requestTask, ILogger logger)\n   at FreakFightsFan.Api.Auth.CustomAuthorizationMiddlewareResultHandler.HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult) in /src/FreakFightsFan.Api/Auth/CustomAuthorizationMiddlewareResultHandler.cs:line 21\n   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)\n   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)\n   at FreakFightsFan.Api.Exceptions.ExceptionMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) in /src/FreakFightsFan.Api/Exceptions/ExceptionMiddleware.cs:line 21"
2024-05-04 15:34:53 [13:34:53 INF 06dfff20-b2d0-4dde-a569-7f96e37f7765] Request finished "HTTP/1.1" "GET" "http"://"localhost:5000""""/api/images/import""" - 500 null "application/json" 118.8442ms
2024-05-04 15:34:02 /app/chromedriver/linux64/chromedriver: error while loading shared libraries: libglib-2.0.so.0: cannot open shared object file: No such file or directory
2024-05-04 15:34:53 /app/chromedriver/linux64/chromedriver: error while loading shared libraries: libglib-2.0.so.0: cannot open shared object file: No such file or directory
2024-05-04 15:43:47 /app/chromedriver/linux64/chromedriver: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory
2024-05-04 15:46:04 /app/chromedriver/linux64/chromedriver: error while loading shared libraries: libxcb.so.1: cannot open shared object file: No such file or directory
OpenQA.Selenium.WebDriverException: unknown error: cannot find Chrome binary\n   at OpenQA.Selenium.Remote.Remot

Add something like that to API dockerfile:

# Chromedriver
USER root

# Install dependencies
RUN apt-get update && apt-get install -y wget unzip xvfb libxi6 libgconf-2-4 libnss3

# Install Chrome
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
RUN apt-get -y update
RUN apt-get install -y google-chrome-stable

USER app
FritzTheCat9 commented 1 month ago

import works on http://localhost:7000 when debugging in visual studio