From 3e73344d2e1407f50cc429e03cb9a59a19250d6c Mon Sep 17 00:00:00 2001 From: Chris Turner Date: Wed, 14 Jul 2021 08:55:52 +0100 Subject: [PATCH] feat: First release --- .github/dependabot.yml | 7 ++++ .github/workflows/release.yml | 62 +++++++++++++++++++++++++++++++++++ .gitignore | 38 +++++++++++++++++++++ Dockerfile | 43 ++++++++++++++++++++++++ README.md | 57 +++++++++++++++++++++++++++++++- 5 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/release.yml create mode 100644 .gitignore create mode 100644 Dockerfile diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..475defc --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: "/.github" + schedule: + interval: daily + open-pull-requests-limit: 99 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..818e625 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,62 @@ + +on: + workflow_dispatch: + +name: Release new version + +jobs: + create-release: + runs-on: ubuntu-latest + name: Release to DockerHub + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + + steps: + - name: Checkout master + uses: actions/checkout@v2 + + - name: Bump version + uses: anothrNick/github-tag-action@1.26.0 + env: + WITH_V: true + + - name: Get new tag + id: new_tag + uses: WyriHaximus/github-action-get-previous-tag@v1 + with: + fallback: 1.0.0 + + - name: Build changelog + id: build_changelog + uses: mikepenz/release-changelog-builder-action@v1 + + - name: Create release + id: create_release + uses: actions/create-release@v1 + with: + tag_name: ${{ steps.new_tag.outputs.tag }} + release_name: ${{ steps.new_tag.outputs.tag }} + body: ${{steps.build_changelog.outputs.changelog}} + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: peavers/quarantine:latest + + - name: Rollback if failure + if: failure() && steps.create_release.outputs.id != '' + uses: author/action-rollback@stable + with: + id: ${{ steps.create_release.id }} + tag: ${{ steps.new_tag.outputs.tag }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a281dd4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ +.DS_Store diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..697d63c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,43 @@ +FROM openjdk:16-buster +LABEL maintainer="chris@forloop.space" + +ENV DEBIAN_FRONTEND noninteractive +ENV DEBCONF_NONINTERACTIVE_SEEN true + +# Create a default user +RUN groupadd --system automation && \ + useradd --system --create-home --gid automation --groups audio,video automation && \ + mkdir --parents /home/automation/reports && \ + chown --recursive automation:automation /home/automation + +# Install dependencies +RUN apt-get -yqq update && \ + apt-get -yqq install gnupg2 && \ + apt-get -yqq install curl unzip && \ + apt-get -yqq install xvfb tinywm && \ + apt-get -yqq install fonts-ipafont-gothic xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic && \ + rm -rf /var/lib/apt/lists/* + +# Install Chrome WebDriver +RUN CHROMEDRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE` && \ + mkdir -p /opt/chromedriver-$CHROMEDRIVER_VERSION && \ + curl -sS -o /tmp/chromedriver_linux64.zip http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip && \ + unzip -qq /tmp/chromedriver_linux64.zip -d /opt/chromedriver-$CHROMEDRIVER_VERSION && \ + rm /tmp/chromedriver_linux64.zip && \ + chmod +x /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver && \ + ln -fs /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver /usr/local/bin/chromedriver + +# Install Google Chrome +RUN curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \ + echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list && \ + apt-get -yqq update && \ + apt-get -yqq install google-chrome-stable && \ + rm -rf /var/lib/apt/lists/* + +# Default configuration +ENV DISPLAY :20.0 +ENV SCREEN_GEOMETRY "1440x900x24" +ENV CHROMEDRIVER_PORT 4444 +ENV CHROMEDRIVER_WHITELISTED_IPS "127.0.0.1" +ENV CHROMEDRIVER_URL_BASE '' +ENV CHROMEDRIVER_EXTRA_ARGS '' diff --git a/README.md b/README.md index 602ab02..cfba9c9 100644 --- a/README.md +++ b/README.md @@ -1 +1,56 @@ -selenium-java-docker +#Selenium Java & Docker +This is a Dockerfile with the latest version of Google Chrome and the Google Chrome Web Driver along with the Java 16 +JDK. + +## Why +A project built in Java which requires Selenium, and a webdriver to be deployed, this is a simple way to get it done. + +## Example use +If you wanted to use this as a multi-stage build file you'd just need to add two small sections to a Dockerfile. + +```dockerfile +# Build the project using Gradle +FROM gradle:jdk16 AS build +ADD . /home/gradle/src +WORKDIR /home/gradle/src +RUN gradle build + +# Run the Jar +FROM peavers/selenium-java:latest +RUN mkdir /app +COPY --from=build /home/gradle/src/build/libs/spring-boot-application.jar /app/spring-boot-application.jar +ENTRYPOINT ["java", "-jar", "/app/spring-boot-application.jar"] +``` + +## Configure your application +The web driver is ready and accessible at `/usr/local/bin/chromedriver` so however you configure the driver path in +your application, point it there. + +If you're running the Java Selenium library through Springboot, here is an example configuration class: +```java +@Configuration +public class WebDriverConfig { + + @Bean + public WebDriver webDriver() { + + final var options = new ChromeOptions(); + + // Overwrite the values set in the Dockerfile. + System.setProperty("webdriver.chrome.whitelistedIps", ""); + System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver"); + + // Set custom options for the webdriver. + options.addArguments("--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 11_4) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/91.0.4472.124 Safari/537.36"); + options.addArguments("--lang=en_US"); + options.addArguments("--window-size=3840,2160"); + options.addArguments("--disable-extensions"); + options.addArguments("--disable-dev-shm-usage"); + options.addArguments("--no-sandbox"); + options.addArguments("--disable-gpu"); + options.addArguments("--headless"); + + return new ChromeDriver(options); + } +} +```