Skip to content

Commit

Permalink
feat: multi-arch
Browse files Browse the repository at this point in the history
  • Loading branch information
darkweaver87 committed Oct 1, 2024
1 parent 7fbad19 commit 47860f0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pipenv shell

# Build a new version of the base Docker container - ONLY NEEDED WHEN WE CHANGE DEPENDENCIES
export SCRAPER_BASE_VERSION="0.8.0" # Only need to change this when we update dependencies
docker buildx use default # use same buildx context for all containers to build
docker buildx use typesense-builder || docker buildx create --name typesense-builder --driver docker-container --use --bootstrap # use same buildx context for all containers to build
docker buildx build --load -f ./scraper/dev/docker/Dockerfile.base -t typesense/docsearch-scraper-base:${SCRAPER_BASE_VERSION} .
docker push typesense/docsearch-scraper-base:${SCRAPER_BASE_VERSION}
docker tag typesense/docsearch-scraper-base:${SCRAPER_BASE_VERSION} typesense/docsearch-scraper-base:latest
Expand All @@ -157,7 +157,7 @@ docker push typesense/docsearch-scraper-base:latest
# Build a new version of the scraper Docker container
export SCRAPER_VERSION="0.9.1"
export SCRAPER_BASE_VERSION="latest"
docker buildx use default # use same buildx context for all containers to build
docker buildx use typesense-builder || docker buildx create --name typesense-builder --driver docker-container --use --bootstrap # use same buildx context for all containers to build
docker buildx build -f ./scraper/dev/docker/Dockerfile --build-arg SCRAPER_BASE_VERSION=${SCRAPER_BASE_VERSION} -t typesense/docsearch-scraper:${SCRAPER_VERSION} .
docker push typesense/docsearch-scraper:${SCRAPER_VERSION}
docker tag typesense/docsearch-scraper:${SCRAPER_VERSION} typesense/docsearch-scraper:latest
Expand Down
9 changes: 9 additions & 0 deletions cli/src/commands/abstract_build_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class AbstractBuildDocker(AbstractCommand):
def build_docker_file(file, image="typesense/docsearch-scraper-dev",
local_tag=False):
tags = [image]
AbstractBuildDocker.setup_buildx()

if local_tag:
tag = AbstractBuildDocker.get_local_tag().decode()
Expand All @@ -30,3 +31,11 @@ def get_local_tag():
from subprocess import check_output
return check_output(
['git', 'describe', '--abbrev=0', '--tags']).strip()

@staticmethod
def setup_buildx():
from subprocess import check_output, CalledProcessError
try:
return check_output(['docker', 'buildx', 'use', 'typesense-builder']).strip()
except CalledProcessError:
return check_output(['docker', 'buildx', 'create', '--name', 'typesense-builder', '--driver', 'docker-container', '--use', '--bootstrap']).strip()
3 changes: 1 addition & 2 deletions scraper/dev/docker/Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ RUN apt-get update -y && apt-get install -yq \
libgconf-2-4 \
default-jdk

RUN apt-get update -y && apt-get install -yq \
chromium-driver
RUN apt-get update -y && apt-get install -yq chromium-driver

RUN wget -q https://github.com/SeleniumHQ/selenium/releases/download/selenium-4.4.0/selenium-server-4.4.0.jar
RUN wget -q https://repo1.maven.org/maven2/org/testng/testng/7.6.1/testng-7.6.1.jar
Expand Down
11 changes: 9 additions & 2 deletions scraper/src/config/browser_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,15 @@ def init(config_original_content, js_render, user_agent):
chrome_options.add_argument('--headless')
chrome_options.add_argument('user-agent={0}'.format(user_agent))

webdriver_service = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=webdriver_service, options=chrome_options)
CHROMIUMDRIVER_PATH = os.environ.get('CHROMIUMDRIVER_PATH', "/usr/bin/chromedriver")

if os.path.isfile(CHROMIUMDRIVER_PATH):
webdriver_service = Service(executable_path=CHROMIUMDRIVER_PATH)
driver = webdriver.Chrome(service=webdriver_service, options=chrome_options)
else:
webdriver_service = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=webdriver_service, options=chrome_options)

CustomDownloaderMiddleware.driver = driver
JsExecutor.driver = driver
return driver
Expand Down

0 comments on commit 47860f0

Please sign in to comment.