Continuing with my question below, I have completed the chrome driver setup.
In the shell script that is run during deploy, “#! /usr/bin/env bash” in the shell script executed during deploy appears to cause an error
I had tried some after that, but it didn’t work, so let me ask again for advice.
The content is that when the following code (java) is executed, an error occurs at the point “WebDriver driver = new ChromeDriver(options);”.
■ source code(java)
WebDriverManager wdm = WebDriverManager.chromedriver().clearDriverCache().cachePath("/opt/render/project/.render/chrome").avoidOutputTree();
wdm.setup();
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--no-sandbox");
options.addArguments("--user-agent=" + SystemContentBean.RequestHeader.USER_AGENT);
WebDriver driver = new ChromeDriver(options);
■ error message
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Probably as per the error message, but I believe it is because the “chrome driver” is not finding “chrome”.
Can you please let me know if you know how to make the “chrome driver” find “chrome”?
To be sure, the “Dockerfile” is configured as follows.
■ Dockerfile
FROM maven:3.9.6-eclipse-temurin-21 AS build
COPY . .
RUN mvn clean package -Dmaven.test.skip=true
FROM eclipse-temurin:21-alpine
# gitとgit-secretsをインストール
RUN apk update && \
apk add bash git make && \
apk add --upgrade grep
RUN git clone https://github.com/awslabs/git-secrets /home/alpine/git-secrets
WORKDIR /home/alpine/git-secrets
RUN make && \
make install
# dpkgをインストール(debファイルを使ったパッケージのインストールを行うため)
# ※ apt-getは「Alpine Linux」で使えないらしいので「apk add」に修正
RUN apk add --update dpkg
# Javaアプリケーションのjarをコピー
COPY --from=build /target/xbot-nonmoral.jar xbot-nonmoral.jar
# ローカルのrender-build.shをコピー
COPY render-build.sh .
# render-build.shに実行権限を付与
# render-build.shを実行
RUN chmod +x ./render-build.sh && \
./render-build.sh
# seleniumの設定
ENV PATH="${PATH}:/opt/render/project/.render/chrome/opt/google/chrome/"
ENTRYPOINT ["java", "-jar", "xbot-nonmoral.jar"]
■ render-build.sh
#!/usr/bin/env bash
# exit on error
set -o errexit
CURRENT_DIR=$(pwd)
STORAGE_DIR=/opt/render/project/.render
if [ ! -d "$STORAGE_DIR/chrome" ]; then
echo "...Downloading Chrome"
mkdir -p $STORAGE_DIR/chrome
cd $STORAGE_DIR/chrome
wget -P ./ https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
dpkg -x ./google-chrome-stable_current_amd64.deb $STORAGE_DIR/chrome
rm ./google-chrome-stable_current_amd64.deb
cd "$CURRENT_DIR" # Make sure we return to where we were
else
echo "...Using Chrome from cache"
fi