Skip to content

Commit

Permalink
Merge pull request smashtestio#59 from RoyceTheBiker/master
Browse files Browse the repository at this point in the history
Docker setup of Smashtest
  • Loading branch information
vptes1 authored Feb 23, 2020
2 parents 590b3fa + 826008a commit c90f52f
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 0 deletions.
38 changes: 38 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM debian:buster
WORKDIR /root

RUN apt-get -y update && \
apt-get -y install npm curl openjdk-11-jre openjdk-11-jdk procps openssh-server bash libdbus-glib-1-2 && \
curl -o chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && \
apt-get -y install -f ./chrome.deb && \
printf "\ndeb http://downloads.sourceforge.net/project/ubuntuzilla/mozilla/apt all main" >> /etc/apt/sources.list && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys CCC158AFC1289A29 && \
apt-get update && \
apt-get -y install firefox-mozilla-build && \
/usr/sbin/useradd -c SmashTest -s /bin/bash -d /home/smashtest smashtest && \
mkdir /home/smashtest && \
chown -R smashtest:smashtest /home/smashtest && \
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.4/install.sh > install.sh && \
echo '972c2b83fb0db7c3a1481bc982db7b1bfe7deae620514b94598b061b6a864baf install.sh' | /usr/bin/sha256sum -c - && \
cp ./install.sh /home/smashtest/install.sh && \
chmod 755 /home/smashtest/install.sh && \
su smashtest -c "cd /home/smashtest && \
touch .bashrc && \
bash ./install.sh && \
. .bashrc && \
nvm install node && \
npm install -g webdriver-manager && \
webdriver-manager update && \
npm install -g smashtest && \
CHROME_CONF=\".nvm/versions/node/*/lib/node_modules/smashtest/node_modules/selenium-webdriver/chrome.js\" && \
sed -i \$CHROME_CONF -e \"/return.*addArguments.*headless/{s/);/, 'disable-dev-shm-usage', 'no-sandbox');/}\" && \
mkdir .ssh && \
chmod 700 .ssh && \
ssh-keygen -t ecdsa -b 521 -f .ssh/id_ecdsa -q -N \"\" && \
cp -a .ssh/id_ecdsa.pub .ssh/authorized_keys"

COPY *sh /home/smashtest/

EXPOSE 8022 8080

ENTRYPOINT [ "/home/smashtest/start.sh" ]
33 changes: 33 additions & 0 deletions docker/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
up: ## Spin up the container
docker-compose -p SmashTest up -d
docker ps -a

stop: ## Stop running containers
docker-compose -p SmashTest stop

kill: ## Stop and remove all containers
docker-compose -p SmashTest down

build: ## Rebuild the image
docker image build -t smashtestio .

get_key: up ## Copy out the private key
docker cp $(shell docker-compose -p SmashTest ps -q):/home/smashtest/.ssh/id_ecdsa ./docker-private-key-id_ecdsa

shell: up ## Start the container with a command prompt
docker exec -it $(shell docker-compose -p SmashTest ps -q) bash

devel: ## Start up a new container from the image and open a shell
docker run --entrypoint bash -it smashtestio

status: ## Show status of containers and images
docker ps -a
docker images -a

test: get_key
ssh -tt smashtest@localhost -p 8022 -i ./docker-private-key-id_ecdsa -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null ./test.sh

flush: ## Remove local images and containers !!!DANGER!!! everything gets deleted
-$(MAKE) kill
-docker rm $(shell docker ps -a -q)
-docker rmi $(shell docker images -a -q)
59 changes: 59 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Docker For SmashTest
These files deliver a setup for running SmashTest in [Docker](https://github.com/docker/docker-ce)

These files require that the following programs be installed.
- [Docker](https://www.docker.com/)
- [Docker Compose](https://docs.docker.com/compose/)
- [make](https://www.gnu.org/software/make/)

## Makefile
Contains the Docker commands to build and use the container with little or no Docker experience.

The following **make recipes** are used as arguments given when running the **make** command.
- ``build`` Builds the Docker image and installs SmashTest, Chrome, Firefox and webdriver-manager
- ``up`` Starts a container built from the image
- ``get_key`` Copy the new private SSH key out of the container. Use this to setup a build server to do automatic testing.
- ``shell`` Connect to a running container with an interactive shell
- ``status`` Report status of images and containers
- ``test`` Run the **sample.smash** inside the container
- ``devel`` Create a new container and start an interactive shell to do development of SmashTest scripts.
- ``stop`` Shutdown the container
- ``kill`` Shutdown the container and delete it
- ``flush`` Ignorently delete all non-running containers and images. **THIS WILL DESTROY ALL DOCKER IMAGES AND CONTAINERS!**

Quickly get up and running my running this command in the same directory as ``docker-compose.yml``
```make
make build test
```
In the Makefile ``test`` calls ``get_key`` and it calls ``up`` so ``make build test`` is all that is needed.

An automated build server will use the private SSH key to upload ``smash`` files and run a smashtest command to test a target web site.

## Dockerfile
This tells Docker how to build the image.

## docker-compose.yml
This provides an elegent way to interact with the container by using a targeted name.

## README.md
You are here!

## sample.smash
Ultra simple

## start.sh
Start the services for SSH and webdriver-manager.

## test.sh
A simple smashtest command to run ``sample.smash``

# About
This Docker setup was contributed by [RoyceTheBiker](https://gitlab.com/RoyceTheBiker) and is publicly hosted on [GitLab.com](https://gitlab.com/SiliconTao-DevOps/DockerForSmashtest)

A big thank you to the helpful people in the [Smashtest community](https://gitter.im/smashtestio/community) for all their help. If you have questions, join the group, get help and then help out others.

# Links

[Running webdriverio tests using headless chrome in Docker](https://www.intricatecloud.io/2019/05/running-webdriverio-tests-using-headless-chrome-inside-a-container/)

[Issue 2473: Error "DevToolsActivePort file doesn't exist" always appears in Docker](https://bugs.chromium.org/p/chromedriver/issues/detail?id=2473)
13 changes: 13 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '2.0'

services:

SmashTest:
image: smashtestio

ports:
- "8080:8080"
- "8022:22"

volumes:
- /dev/shm:/dev/shm
6 changes: 6 additions & 0 deletions docker/sample.smash
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Open Chrome
Open Firefox

Navigate to 'google.com'

Type 'hello world[enter]' into 'textbox'
4 changes: 4 additions & 0 deletions docker/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

/etc/init.d/ssh start && \
su smashtest -c "cd; . .bashrc; webdriver-manager start"
4 changes: 4 additions & 0 deletions docker/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

smashtest --test-server=http://localhost:4444/wd/hub ./sample.smash

0 comments on commit c90f52f

Please sign in to comment.