Skip to content
This repository has been archived by the owner on Jun 22, 2024. It is now read-only.

Commit

Permalink
Merge from firefox-geckodriver-build branch
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmortensen committed Nov 11, 2021
2 parents 8f82b00 + 547a95d commit d88e8f0
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 29 deletions.
38 changes: 11 additions & 27 deletions NodeFirefox/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,28 @@
# NOTE: DO *NOT* EDIT THIS FILE. IT IS GENERATED.
# PLEASE UPDATE Dockerfile.txt INSTEAD OF THIS FILE
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
FROM selenium/node-base:4.0.0-20211025
LABEL authors=SeleniumHQ
FROM local-seleniarm/node-base:4.0.0-20211111
LABEL authors=SeleniumHQ,sj26,jamesmortensen

#FROM local-seleniarm/node-base:4.0.0-20211018
#LABEL authors=SeleniumHQ,sj26,jamesmortensen

USER root

#=========
# Firefox
#=========
ARG FIREFOX_VERSION=latest
RUN FIREFOX_DOWNLOAD_URL=$(if [ $FIREFOX_VERSION = "latest" ] || [ $FIREFOX_VERSION = "nightly-latest" ] || [ $FIREFOX_VERSION = "devedition-latest" ] || [ $FIREFOX_VERSION = "esr-latest" ]; then echo "https://download.mozilla.org/?product=firefox-$FIREFOX_VERSION-ssl&os=linux64&lang=en-US"; else echo "https://download-installer.cdn.mozilla.net/pub/firefox/releases/$FIREFOX_VERSION/linux-x86_64/en-US/firefox-$FIREFOX_VERSION.tar.bz2"; fi) \
RUN echo "deb http://ftp.hk.debian.org/debian/ sid main" >> /etc/apt/sources.list \
&& apt-get update -qqy \
&& apt-get -qqy --no-install-recommends install firefox libavcodec-extra \
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/* \
&& wget --no-verbose -O /tmp/firefox.tar.bz2 $FIREFOX_DOWNLOAD_URL \
&& apt-get -y purge firefox \
&& rm -rf /opt/firefox \
&& tar -C /opt -xjf /tmp/firefox.tar.bz2 \
&& rm /tmp/firefox.tar.bz2 \
&& mv /opt/firefox /opt/firefox-$FIREFOX_VERSION \
&& ln -fs /opt/firefox-$FIREFOX_VERSION/firefox /usr/bin/firefox
&& apt-get -qqy install firefox-esr libavcodec-extra \
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/*

#============
# GeckoDriver
#============
ARG GECKODRIVER_VERSION=latest
RUN GK_VERSION=$(if [ ${GECKODRIVER_VERSION:-latest} = "latest" ]; then echo "0.30.0"; else echo $GECKODRIVER_VERSION; fi) \
&& echo "Using GeckoDriver version: "$GK_VERSION \
&& wget --no-verbose -O /tmp/geckodriver.tar.gz https://github.com/mozilla/geckodriver/releases/download/v$GK_VERSION/geckodriver-v$GK_VERSION-linux64.tar.gz \
&& rm -rf /opt/geckodriver \
&& tar -C /opt -zxf /tmp/geckodriver.tar.gz \
&& rm /tmp/geckodriver.tar.gz \
&& mv /opt/geckodriver /opt/geckodriver-$GK_VERSION \
&& chmod 755 /opt/geckodriver-$GK_VERSION \
&& ln -fs /opt/geckodriver-$GK_VERSION /usr/bin/geckodriver
# geckodriver was built using the local-seleniarm/geckodriver-arm64 Debian image
COPY geckodriver /usr/local/bin/

USER 1200

#============================================
# Dumping Browser name and version for config
#============================================
RUN echo "firefox" > /opt/selenium/browser_name
RUN echo "firefox" > /opt/selenium/browser_name
47 changes: 47 additions & 0 deletions NodeFirefox/Dockerfile-geckodriver-arm64
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
FROM local-seleniarm/node-base:latest
LABEL authors=SeleniumHQ,sj26,jamesmortensen

##### tags
# local-seleniarm/geckodriver-arm64:4.0.0-$(build_date)
#####
USER root


#===========
# Debugging
#===========
WORKDIR /opt
RUN echo "deb http://ftp.hk.debian.org/debian/ sid main" >> /etc/apt/sources.list \
&& apt-get update -qqy \
&& apt install gcc build-essential git vim cargo -y \
&& curl https://sh.rustup.rs -sSf | bash -s -- -y \
&& git clone https://github.com/mozilla/geckodriver.git && cd geckodriver \
&& git checkout v0.30.0

RUN echo "alias l='ls -ltrSha'" >> /home/seluser/.bashrc

COPY build-geckodriver-arm64.sh /opt/geckodriver/

RUN chown seluser /opt/geckodriver/build-geckodriver-arm64.sh \
&& chmod 755 /opt/geckodriver/build-geckodriver-arm64.sh \
&& sudo chown -R seluser /home/seluser/.rustup /home/seluser/.cargo /opt/geckodriver

# COPY geckodriver /usr/local/bin/
# USER seluser
# RUN sudo chown -R seluser /home/seluser/.rustup /home/seluser/.cargo /opt/geckodriver \
# && cd /opt/geckodriver \
# && cargo build \
# && sudo cp target/debug/geckodriver /usr/local/bin/ \
# && sudo apt remove gcc build-essential cargo

# WORKDIR /

#============
# GeckoDriver
#============
# For arm64 we're sniffing a compatible binary out of an ubuntu package, don't look too hard!
#RUN echo "Downloading Arm64 geckodriver..."
# curl http://ports.ubuntu.com/pool/universe/f/firefox/firefox-geckodriver_75.0+build3-0ubuntu1_arm64.deb | dpkg-deb --fsys-tarfile - | tar -C / -x ./usr/bin/geckodriver;
# curl http://ports.ubuntu.com/pool/universe/f/firefox/firefox-geckodriver_93.0+build1-0ubuntu3_arm64.deb | dpkg-deb --fsys-tarfile - | tar -C / -x ./usr/bin/geckodriver;

USER 1200
22 changes: 22 additions & 0 deletions NodeFirefox/Dockerfile.arm64
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#FROM local-seleniarm/node-base:4.0.0-20211018
#LABEL authors=SeleniumHQ,sj26,jamesmortensen

USER root

#=========
# Firefox
#=========
RUN echo "deb http://ftp.hk.debian.org/debian/ sid main" >> /etc/apt/sources.list \
&& apt-get update -qqy \
&& apt-get -qqy install firefox-esr libavcodec-extra \
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/*

# geckodriver was built using the local-seleniarm/geckodriver-arm64 Debian image
COPY geckodriver /usr/local/bin/

USER 1200

#============================================
# Dumping Browser name and version for config
#============================================
RUN echo "firefox" > /opt/selenium/browser_name
59 changes: 59 additions & 0 deletions NodeFirefox/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
## Building NodeFirefox and StandaloneFirefox for ARM64

I haven't located a geckdriver binary for Debian, so we'll build it from source. Unfortunately, the build step cannot yet be automated. Trying to run it as part of a docker build or even using docker exec causes the build to fail for reasons unknown to me.

As a result, I split the build process into various steps:

### Step 0

Make sure the local-seleniarm/base:latest and local-seleniarm/node-base:latest have been built using the command that builds all of the other images. If you haven't yet done this, run this from the root of the repository.

```
$ sh build.sh
```

Before proceeding, verify that local-seleniarm/base:latest and local-seleniarm/node-base:latest exist by using `docker image ls`.


### Step 1

In Step 1, we'll build the geckodriver. The geckodriver must be built specifically for Debian and specifically for the ARM64 platform, and we'll use an intermediate, throwaway Debian container to automatically setup the build environment by installing all of the needed dependencies. Once the build environment is setup, we'll need to manually run the compile step. To start this process, run the following command from the NodeFirefox working directory:

```
$ cd NodeFirefox
$ sh build-step-1.sh # This installs dependencies and drops you into a container bash shell
```

Once the dependencies are installed, we'll automatically drop into the container's shell in the `/opt/geckodriver` directory. At this stage, run this command:

```
$ sh build-geckodriver-arm64.sh
```

This uses Rust and cargo to build geckodriver. Afterwards, the script copies the binary to `/media/share` on the host. The script then moves it to the NodeFirefox directory where it will be copied into the NodeFirefox image in the next step. Once built, exit the container:

```
$ exit
```

Before proceeding to the next step, verify the geckodriver binary is inside the NodeFirefox folder.


### Step 2

At this stage, we're ready to build both NodeFirefox and StandaloneFirefox. To build these images, run the following command:

```
$ sh build-step-2.sh
```

After this completes, we see all of the container images, both with the latest tag and today's date, using `docker image ls`.


## Running the StandaloneFirefox image

```
$ docker run --rm -it --shm-size 3g -p 4444:4444 -p 5900:5900 -p 7900:7900 local-seleniarm/standalone-firefox:latest
```

As with the x86_64 images from upstream, this also includes noVNC on port 7900, which we can access via http://localhost:7900
3 changes: 3 additions & 0 deletions NodeFirefox/build-geckodriver-arm64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

cargo build && sudo cp /opt/geckodriver/target/debug/geckodriver /media/host
15 changes: 15 additions & 0 deletions NodeFirefox/build-step-1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

BUILD_DATE=$(date +'%Y%m%d')
# Make sure other images are built first using build.sh
# We need both the Base and NodeBase to begin building NodeFirefox

# Install geckodriver binary dependencies
docker buildx build --platform linux/arm64 -f Dockerfile-geckodriver-arm64 -t local-seleniarm/geckodriver-arm64:4.0.0-$BUILD_DATE .

# build geckodriver binary and copy to build folder on host
echo 'Building geckodriver must be done manually from within an intermediate container. Run ./build-geckodriver-arm64.sh on the container, then exit...'
docker run --rm -it -v $PWD:/media/host -w /opt/geckodriver --name geckodriver-arm64 local-seleniarm/geckodriver-arm64:4.0.0-$BUILD_DATE bash


echo 'After exiting, run build-step-2.sh'
45 changes: 45 additions & 0 deletions NodeFirefox/build-step-2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

DOCKERDEB=false # if using Docker Desktop, set to false

if [[ $DOCKERDEB == true ]]
then
echo 'Getting geckodriver binary from the Docker Debian VM...'
sh get-geckodriver.sh
else
echo 'Getting geckodriver from /media/host...'
cp /media/host/geckodriver .
fi

echo 'Generate the Dockerfile.arm64...'
BUILD_DATE=$(date +'%Y%m%d')
VERSION=4.0.0
NAMESPACE=local-seleniarm
AUTHORS=SeleniumHQ,sj26,jamesmortensen

echo "# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" > ./Dockerfile
echo "# NOTE: DO *NOT* EDIT THIS FILE. IT IS GENERATED." >> ./Dockerfile
echo "# PLEASE UPDATE Dockerfile.txt INSTEAD OF THIS FILE" >> ./Dockerfile
echo "# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" >> ./Dockerfile
echo FROM ${NAMESPACE}/node-base:${VERSION}-${BUILD_DATE} >> ./Dockerfile
echo LABEL authors="$AUTHORS" >> ./Dockerfile
echo "" >> ./Dockerfile
cat ./Dockerfile.arm64 >> ./Dockerfile



echo "Building Seleniarm/NodeFirefox:$VERSION-$BUILD_DATE"
docker buildx build --platform linux/arm64 -f Dockerfile -t local-seleniarm/node-firefox:$VERSION-$BUILD_DATE .
docker tag local-seleniarm/node-firefox:$VERSION-$BUILD_DATE local-seleniarm/node-firefox:latest

# Generate the Seleniarm/StandaloneFirefox Dockerfile
cd ../Standalone && sh generate.sh StandaloneFirefox node-firefox $VERSION-$BUILD_DATE $NAMESPACE $AUTHORS
cd ../StandaloneFirefox

echo "Building Seleniarm/StandaloneFirefox:$VERSION-$BUILD_DATE"
docker buildx build --platform linux/arm64 -f Dockerfile -t local-seleniarm/standalone-firefox:$VERSION-$BUILD_DATE .
docker tag local-seleniarm/standalone-firefox:$VERSION-$BUILD_DATE local-seleniarm/standalone-firefox:latest


# Remove geckodriver image and dependencies if build is successful, since it's 4.9GB!
docker image rm local-seleniarm/geckodriver-arm64:$VERSION-$BUILD_DATE
4 changes: 2 additions & 2 deletions StandaloneFirefox/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# NOTE: DO *NOT* EDIT THIS FILE. IT IS GENERATED.
# PLEASE UPDATE Dockerfile.txt INSTEAD OF THIS FILE
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
FROM selenium/node-firefox:4.0.0-20211025
LABEL authors=SeleniumHQ
FROM local-seleniarm/node-firefox:4.0.0-20211111
LABEL authors=SeleniumHQ,sj26,jamesmortensen

USER 1200

Expand Down
15 changes: 15 additions & 0 deletions retag-latest-images-as-today.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This script retags all of the latest images with the current date tag, in case we want to rebuild images
# without rebuilding from scratch.

BUILD_DATE=$(date +'%Y%m%d')
VERSION=4.0.0
NAMESPACE=local-seleniarm

docker tag $NAMESPACE/base:latest $NAMESPACE/base:$VERSION-$BUILD_DATE
docker tag $NAMESPACE/hub:latest $NAMESPACE/hub:$VERSION-$BUILD_DATE
docker tag $NAMESPACE/node-base:latest $NAMESPACE/node-base:$VERSION-$BUILD_DATE
docker tag $NAMESPACE/node-chromium:latest $NAMESPACE/node-chromium:$VERSION-$BUILD_DATE
docker tag $NAMESPACE/standalone-chromium:latest $NAMESPACE/standalone-chromium:$VERSION-$BUILD_DATE

docker tag $NAMESPACE/node-firefox:latest $NAMESPACE/node-firefox:$VERSION-$BUILD_DATE
docker tag $NAMESPACE/standalone-firefox:latest $NAMESPACE/standalone-firefox:$VERSION-$BUILD_DATE

0 comments on commit d88e8f0

Please sign in to comment.