Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to launch chromium in debian:bullseye-slim docker container #912

Closed
subash-krishnappa opened this issue Jul 28, 2023 · 11 comments
Closed
Labels
question Questions related to rod

Comments

@subash-krishnappa
Copy link

subash-krishnappa commented Jul 28, 2023

Rod Version: v0.114.1

Am trying to launch chromium in docker container, have used a dockerFile to download the dependency:

partial content of DockerFile:
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN apt -y install ./google-chrome-stable_current_amd64.deb

RUN apt -y install chromium

Code snippet to get binary
image

But i get an error as below
image

But the same test when triggered locally works perfectly fine, kindly guide me if thrs any configs that am missing here?

Code to launch chromium:

image
@subash-krishnappa subash-krishnappa added the question Questions related to rod label Jul 28, 2023
@ysmood
Copy link
Member

ysmood commented Jul 28, 2023

Please provide reproducible code.

@subash-krishnappa
Copy link
Author

subash-krishnappa commented Jul 28, 2023

image I have created a sample project for reproducing the issue, its accessible at:

https://github.com/subash-krishnappa/goRodSample

@ysmood
Copy link
Member

ysmood commented Jul 29, 2023

Please check this: https://go-rod.github.io/#/compatibility?id=os

@subash-krishnappa
Copy link
Author

subash-krishnappa commented Jul 30, 2023

i did refer to the link provided, and have included the instructions to install chrome, this is my updated docker file:

image

docker image is built using the command:
docker buildx build --platform linux/amd64 --tag rod-test:latest . -f ./Dockerfile

But still facing the same error:
image

Same has been updated in the sample project:
https://github.com/subash-krishnappa/goRodSample

System ChipSet: Apple M1 PRO

@subash-krishnappa subash-krishnappa changed the title Unable to launch chromium in Debian : buster slim docker container Unable to launch chromium in debian:bullseye-slim docker container Jul 30, 2023
@github-actions
Copy link

Please fix the format of your markdown:

12:1 MD033/no-inline-html Inline HTML [Element: img]
15:1 MD033/no-inline-html Inline HTML [Element: img]
21:1 MD033/no-inline-html Inline HTML [Element: img]

generated by check-issue

@ysmood
Copy link
Member

ysmood commented Jul 30, 2023

Please read: https://go-rod.github.io/#/custom-launch?id=the-launcher-lib

func main() {
    path, _ := launcher.LookPath()
    u := launcher.New().Bin(path).MustLaunch()
    rod.New().ControlURL(u).MustConnect().MustPage("https://example.com")
}

@subash-krishnappa
Copy link
Author

subash-krishnappa commented Jul 31, 2023

Update the code to look for existing chrome path :

package sample

import (
	"context"
	"log"
	"testing"
	"time"

	"github.com/go-rod/rod"
	"github.com/go-rod/rod/lib/launcher"
)

func TestSampleRodSetup(t *testing.T) {

	path, err := launcher.LookPath()
	if err != false {
		log.Println(err)
	}
	debugUrl := launcher.New().
		Bin(path).
		Devtools(false).
		Headless(true).
		Leakless(false).
		NoSandbox(true).
		MustLaunch()
	log.Println(debugUrl)

	browser := rod.New().ControlURL(debugUrl).MustConnect().Context(context.Background())
	browser.SlowMotion(time.Second * 1)
	browser.Trace(true)

	page := browser.MustPage("https://www.wikipedia.org/")

	page.MustElement("#searchInput").MustInput("earth")
	page.MustElement("#search-form > fieldset > button").MustClick()

	time.Sleep(time.Second * 3)
	page.Close()
	browser.Close()
}

Locally it works fine here is the console output
image

Docker file contents remains the same:
docker buildx build --platform linux/amd64 --tag rod-test:latest . -f ./Dockerfile

FROM golang as builder

ARG goproxy="https://proxy.golang.org,direct"
ENV GO111MODULE=on
ENV CGO_ENABLED 0
USER root
WORKDIR /app
COPY go.* ./
ADD . .
RUN apt-get update
RUN apt-get install ca-certificates

RUN go test . -c -o ./rod-test

FROM debian:bullseye-slim

RUN apt-get -y update --allow-unauthenticated -qq -o Acquire::https::Verify-Peer=false -o Acquire::Check-Valid-Until=false
RUN apt-get install -y wget
RUN apt-get update && apt-get install -y \
    fonts-liberation \
    libasound2 \
    libatk-bridge2.0-0 \
    libatk1.0-0 \
    libatspi2.0-0 \
    libcups2 \
    libdbus-1-3 \
    libdrm2 \
    libgbm1 \
    libgtk-3-0 \
    libnspr4 \
    libnss3 \
    libwayland-client0 \
    libxcomposite1 \
    libxdamage1 \
    libxfixes3 \
    libxkbcommon0 \
    libxrandr2 \
    xdg-utils \
    libu2f-udev \
    libvulkan1 
 RUN wget --no-check-certificate https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
 RUN apt-get install -y ./google-chrome-stable_current_amd64.deb

WORKDIR /app
COPY --from=builder /app .

RUN chmod +x rod-test

ENTRYPOINT [ "./rod-test"]

but it still fails in container with the error below:

image

@ysmood
Copy link
Member

ysmood commented Jul 31, 2023

Why not just run the chromium on your container without rod? I think it doesn't matter you use rod or not.

As the link I sent to you in previous comment:

On some platforms, you might need to install the browser manually, Rod can't guarantee the auto-downloaded browser will always work. If you want Rod to support a platform, please raise an issue for it.

@subash-krishnappa
Copy link
Author

Does it mean, instead of installing a google-chrome stable, just install chromium & chromium-browser in docker container?
Coz i would still need rod to perform web automation, Please confirm?

@ysmood
Copy link
Member

ysmood commented Jul 31, 2023

It means you have to make sure chrome works on your OS, not rod.

@subash-krishnappa
Copy link
Author

This issue stands resolved, Thanks @ysmood for your inputs..
Final code changes:

FROM golang as builder

ARG goproxy="https://proxy.golang.org,direct"
ENV GO111MODULE=on
ENV CGO_ENABLED 0
USER root
WORKDIR /app
COPY go.* ./
ADD . .
RUN apt-get update
RUN apt-get install ca-certificates

RUN go test . -c -o ./rod-test

FROM debian:bullseye-slim

RUN apt-get update && apt-get install -y wget 

RUN wget --no-check-certificate https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN dpkg -i google-chrome-stable_current_amd64.deb --fix-missing; apt-get -fy install
RUN apt-get -y install chromium

WORKDIR /app
COPY --from=builder /app .

RUN chmod +x rod-test

ENTRYPOINT [ "./rod-test"]

import (
	"log"
	"testing"
	"time"

	"github.com/go-rod/rod"
	"github.com/go-rod/rod/lib/launcher"
)

func TestSampleRodSetup(t *testing.T) {

	path, _ := launcher.LookPath()
	log.Println(path)
	debugUrl := launcher.New().
		Bin(path).
		Devtools(false).
		Headless(true).
		Leakless(true).
		NoSandbox(true).
		RemoteDebuggingPort(9222).
		Proxy(""). //provide your org proxy address here
		MustLaunch()
	log.Println(debugUrl)

	browser := rod.New().ControlURL(debugUrl)
	browser.SlowMotion(time.Second * 1)
	browser.Trace(true)

	page := browser.MustConnect().MustIgnoreCertErrors(true).MustPage("https://www.wikipedia.org/")

	page.MustElement("#searchInput").MustInput("earth")
	page.MustElement("#search-form > fieldset > button").MustClick()

	time.Sleep(time.Second * 3)
	page.Close()
	browser.Close()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Questions related to rod
Projects
None yet
Development

No branches or pull requests

2 participants