Hey guys, today I will post about an example of Docker file where you can run your protractor automation in a Docker container on firefox and chrome.
You will need to have the known hosts and the public key from github to be able to clone the repository and run the automation. Also you need to install java to be able to run the selenium server in your docker container.
Create an empty file in your project and paste these instructions:
Docker file
FROM node
WORKDIR /tmp
#Install required applications
RUN echo 'deb http://httpredir.debian.org/debian jessie-backports main' >> /etc/apt/sources.list.d/jessie-backports.list
RUN apt-get update && \
apt install -y -t jessie-backports openjdk-8-jre-headless ca-certificates-java && \
apt-get install -y xvfb wget openjdk-8-jre && \
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && \
dpkg --unpack google-chrome-stable_current_amd64.deb && \
apt-get install -f -y && \
apt-get clean && \
rm google-chrome-stable_current_amd64.deb && \
apt-get install -y pkg-mozilla-archive-keyring
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
RUN export JAVA_HOME
#Install Firefox on Linux
RUN touch /etc/apt/sources.list.d/debian-mozilla.list
RUN echo "deb http://mozilla.debian.net/ jessie-backports firefox-release" >> /etc/apt/sources.list.d/debian-mozilla.list
RUN wget mozilla.debian.net/pkg-mozilla-archive-keyring_1.1_all.deb
RUN dpkg -i pkg-mozilla-archive-keyring_1.1_all.deb
RUN apt-get update && apt-get install -y -t jessie-backports firefox
#Creating user
RUN useradd -ms /bin/bash admin
# Copy key for github for user admin
ADD id_rsa /home/ci_box/.ssh/id_rsa
ADD known_hosts /home/ci_box/.ssh/known_hosts
ADD id_rsa /home/ci_box/.ssh/id_rsa
RUN chmod 700 /home/ci_box/.ssh/id_rsa; chown -R admin:staff /home/ci_box/.ssh
ADD known_hosts /home/ci_box/.ssh/known_hosts
#Changing user
USER admin
#To avoid conflicts with host machine dbus
ENV DBUS_SESSION_BUS_ADDRESS=/dev/null
#Copying script which will clone repository
WORKDIR /home/admin/workspace
ADD docker.sh ./docker.sh
#Open the bash
CMD ["/bin/bash"]
Script to clone the branch
#!/bin/bash
#Branch and repository
BRANCH=$1
REPOSITORY=$2
#Clone the repository
git clone -b ${BRANCH} rsouza@github.com:azevedorafaela/${REPOSITORY}.git
cd ${REPOSITORY}
#Script to run your automation
./tests.sh ${BRANCH}
Script to run the tests
#!/bin/bash
set -e
#Starting dbus daemon and exporting related environmental variables
export $(dbus-launch)
#Starting X server to be able to run firefox
Xvfb :1 -screen 0 1200x800x24 &
# Clean the target with reports
rm -rf target
# Install all dependencies
npm install
# Run tests
DISPLAY=:1.0 npm run regression
Build the image in the folder that contains the docker file
docker build -t rafazzevedo/test .
Push the image to your account
docker login
docker push rafazzevedo/test
Run the automation in the container:
docker run --name=test rafazzevedo/test:latest /home/admin/docker.sh master regression
See you guys soon !