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
This commit is contained in:
James Tombleson 2022-07-14 14:27:40 -07:00 committed by GitHub
parent 9d662936d5
commit 66c74802d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 8 deletions

View File

@ -7,7 +7,10 @@ RUN go install github.com/pressly/goose/v3/cmd/goose@latest
FROM alpine:latest as app 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 RUN mkdir /app && mkdir /app/migrations
COPY --from=build /app/collector /app COPY --from=build /app/collector /app
COPY --from=build /go/bin/goose /app COPY --from=build /go/bin/goose /app

View File

@ -10,6 +10,7 @@ import (
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
"github.com/go-rod/rod" "github.com/go-rod/rod"
"github.com/go-rod/rod/lib/launcher"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/jtom38/newsbot/collector/database" "github.com/jtom38/newsbot/collector/database"
@ -113,7 +114,11 @@ func (fc *FFXIVClient) GetParser() (*goquery.Document, error) {
} }
func (fc *FFXIVClient) GetBrowser() (*rod.Browser) { 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 return browser
} }

View File

@ -10,6 +10,7 @@ import (
"time" "time"
"github.com/go-rod/rod" "github.com/go-rod/rod"
"github.com/go-rod/rod/lib/launcher"
"github.com/jtom38/newsbot/collector/database" "github.com/jtom38/newsbot/collector/database"
"github.com/jtom38/newsbot/collector/domain/model" "github.com/jtom38/newsbot/collector/domain/model"
"github.com/jtom38/newsbot/collector/services/config" "github.com/jtom38/newsbot/collector/services/config"
@ -48,7 +49,11 @@ func NewRedditClient(Record database.Source) *RedditClient {
func (rc *RedditClient) GetBrowser() *rod.Browser { 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 return browser
} }

View File

@ -11,6 +11,7 @@ import (
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
"github.com/go-rod/rod" "github.com/go-rod/rod"
"github.com/go-rod/rod/lib/launcher"
"github.com/mmcdole/gofeed" "github.com/mmcdole/gofeed"
"github.com/jtom38/newsbot/collector/database" "github.com/jtom38/newsbot/collector/database"
@ -32,7 +33,7 @@ type YoutubeClient struct {
var ( var (
// This is a local slice to store what URI's have been seen to remove extra calls to the DB // 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") 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 { func NewYoutubeClient(Record database.Source) YoutubeClient {
yc := YoutubeClient{ yc := YoutubeClient{
record: Record, record: Record,
cacheGroup: "youtube", cacheGroup: "youtube",
} }
/* /*
@ -109,7 +110,12 @@ func (yc *YoutubeClient) GetContent() ([]database.Article, error) {
} }
func (yc *YoutubeClient) GetBrowser() *rod.Browser { 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 return browser
} }
@ -156,7 +162,8 @@ func (yc *YoutubeClient) GetChannelId(doc *goquery.Document) (string, error) {
func (yc *YoutubeClient) GetAvatarUri() (string, error) { func (yc *YoutubeClient) GetAvatarUri() (string, error) {
var AvatarUri string var AvatarUri string
browser := rod.New().MustConnect() //browser := rod.New().MustConnect()
browser := yc.GetBrowser()
page := browser.MustPage(yc.record.Url) page := browser.MustPage(yc.record.Url)
res := page.MustElement("#channel-header-container > yt-img-shadow:nth-child(1) > img:nth-child(1)").MustAttribute("src") res := page.MustElement("#channel-header-container > yt-img-shadow:nth-child(1) > img:nth-child(1)").MustAttribute("src")