From 66c74802d902deb5bc82e15d9216380bc31de1af Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Thu, 14 Jul 2022 14:27:40 -0700 Subject: [PATCH] Find installed browser for Docker (#17) * trying a different method to have rod find to brower on disk for docker * updated rod to find the browser on disk. This is for docker support --- Dockerfile | 5 ++++- services/input/ffxiv.go | 7 ++++++- services/input/reddit.go | 7 ++++++- services/input/youtube.go | 17 ++++++++++++----- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index dd9e2a1..3389e38 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,10 @@ RUN go install github.com/pressly/goose/v3/cmd/goose@latest FROM alpine:latest as app -RUN apk --no-cache add bash libc6-compat chromium +RUN apk --no-cache add bash +RUN apk --no-cache add libc6-compat +RUN apk --no-cache add chromium + RUN mkdir /app && mkdir /app/migrations COPY --from=build /app/collector /app COPY --from=build /go/bin/goose /app diff --git a/services/input/ffxiv.go b/services/input/ffxiv.go index 0881ef3..3f2f4c2 100644 --- a/services/input/ffxiv.go +++ b/services/input/ffxiv.go @@ -10,6 +10,7 @@ import ( "github.com/PuerkitoBio/goquery" "github.com/go-rod/rod" + "github.com/go-rod/rod/lib/launcher" "github.com/google/uuid" "github.com/jtom38/newsbot/collector/database" @@ -113,7 +114,11 @@ func (fc *FFXIVClient) GetParser() (*goquery.Document, error) { } func (fc *FFXIVClient) GetBrowser() (*rod.Browser) { - browser := rod.New().MustConnect() + var browser *rod.Browser + if path, exists := launcher.LookPath(); exists { + u := launcher.New().Bin(path).MustLaunch() + browser = rod.New().ControlURL(u).MustConnect() + } return browser } diff --git a/services/input/reddit.go b/services/input/reddit.go index 83487a8..efb41ef 100644 --- a/services/input/reddit.go +++ b/services/input/reddit.go @@ -10,6 +10,7 @@ import ( "time" "github.com/go-rod/rod" + "github.com/go-rod/rod/lib/launcher" "github.com/jtom38/newsbot/collector/database" "github.com/jtom38/newsbot/collector/domain/model" "github.com/jtom38/newsbot/collector/services/config" @@ -48,7 +49,11 @@ func NewRedditClient(Record database.Source) *RedditClient { func (rc *RedditClient) GetBrowser() *rod.Browser { - browser := rod.New().MustConnect() + var browser *rod.Browser + if path, exists := launcher.LookPath(); exists { + u := launcher.New().Bin(path).MustLaunch() + browser = rod.New().ControlURL(u).MustConnect() + } return browser } diff --git a/services/input/youtube.go b/services/input/youtube.go index e48d14c..3308c43 100644 --- a/services/input/youtube.go +++ b/services/input/youtube.go @@ -11,6 +11,7 @@ import ( "github.com/PuerkitoBio/goquery" "github.com/go-rod/rod" + "github.com/go-rod/rod/lib/launcher" "github.com/mmcdole/gofeed" "github.com/jtom38/newsbot/collector/database" @@ -18,7 +19,7 @@ import ( type YoutubeClient struct { record database.Source - + // internal variables at time of collection channelID string avatarUri string @@ -32,7 +33,7 @@ type YoutubeClient struct { var ( // This is a local slice to store what URI's have been seen to remove extra calls to the DB - YoutubeUriCache []*string + YoutubeUriCache []*string ErrYoutubeChannelIdMissing = errors.New("unable to find the channelId on the requested page") ) @@ -40,7 +41,7 @@ const YOUTUBE_FEED_URL string = "https://www.youtube.com/feeds/videos.xml?channe func NewYoutubeClient(Record database.Source) YoutubeClient { yc := YoutubeClient{ - record: Record, + record: Record, cacheGroup: "youtube", } /* @@ -109,7 +110,12 @@ func (yc *YoutubeClient) GetContent() ([]database.Article, error) { } func (yc *YoutubeClient) GetBrowser() *rod.Browser { - browser := rod.New().MustConnect() + //browser := rod.New().MustConnect() + var browser *rod.Browser + if path, exists := launcher.LookPath(); exists { + u := launcher.New().Bin(path).MustLaunch() + browser = rod.New().ControlURL(u).MustConnect() + } return browser } @@ -156,7 +162,8 @@ func (yc *YoutubeClient) GetChannelId(doc *goquery.Document) (string, error) { func (yc *YoutubeClient) GetAvatarUri() (string, error) { var AvatarUri string - browser := rod.New().MustConnect() + //browser := rod.New().MustConnect() + browser := yc.GetBrowser() page := browser.MustPage(yc.record.Url) res := page.MustElement("#channel-header-container > yt-img-shadow:nth-child(1) > img:nth-child(1)").MustAttribute("src")