Created
October 23, 2019 13:41
Example of dockerfile that can run selenium code headlessly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM maven:3.6.2-jdk-11-slim AS build | |
ARG ssh_prv_key | |
ARG ssh_pub_key | |
RUN apt-get update && \ | |
apt-get install -yq \ | |
git \ | |
openssh-server | |
# Authorize SSH Host | |
RUN mkdir -p /root/.ssh && \ | |
chmod 0700 /root/.ssh && \ | |
ssh-keyscan github.com > /root/.ssh/known_hosts | |
# Add the keys and set permissions | |
RUN echo "$ssh_prv_key" > /root/.ssh/id_rsa && \ | |
echo "$ssh_pub_key" > /root/.ssh/id_rsa.pub && \ | |
chmod 600 /root/.ssh/id_rsa && \ | |
chmod 600 /root/.ssh/id_rsa.pub | |
# clone and install data lib | |
WORKDIR /usr/src/ | |
RUN git clone git@github.com:gnboorse/college-scraper-data.git && mvn -f /usr/src/college-scraper-data/pom.xml clean install | |
COPY src /usr/src/app/src | |
COPY pom.xml /usr/src/app | |
RUN mvn -f /usr/src/app/pom.xml clean package | |
FROM openjdk:11-slim | |
ARG api_version | |
EXPOSE 8080 | |
RUN apt-get -y update && \ | |
apt-get -yq install curl \ | |
wget \ | |
chromium \ | |
unzip \ | |
xvfb \ | |
xsel \ | |
# libgconf2 \ | |
libxml2-dev \ | |
libxslt-dev \ | |
libz-dev \ | |
xclip | |
# Chromedriver | |
RUN wget -q "https://chromedriver.storage.googleapis.com/76.0.3809.68/chromedriver_linux64.zip" -O /tmp/chromedriver.zip \ | |
&& unzip /tmp/chromedriver.zip -d /opt/scraper \ | |
&& rm /tmp/chromedriver.zip | |
RUN mkdir -p /opt/scraper | |
WORKDIR /opt/scraper | |
COPY --from=build /usr/src/app/target/college-scraper-${api_version}.jar scraper.jar | |
HEALTHCHECK --interval=30s --timeout=3s \ | |
CMD curl -f http://localhost:8080/healthcheck || exit 1 | |
EXPOSE 8080 | |
CMD [ "java", "-jar", "scraper.jar", "-h", "-u", "https://api.scraper.boorse.app", "-q", "primary" ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment