Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QACOE-242: add Dockerfile and instructions how to use cypress with docker #11

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cypress-studio/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM cypress/included:8.5.0

COPY . /cypress-studio
WORKDIR /cypress-studio

ENTRYPOINT npx cypress run
75 changes: 75 additions & 0 deletions cypress-studio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,81 @@ The main goal of this experiment is to share with the community how `Cypress Stu

<p align="right">(<a href="#top">back to top</a>)</p>

<!-- DOCKER SECTION -->
## How to run tests with docker

### Prerequisites
Install the latest Docker engine on the local machine following instructions <a href="https://docs.docker.com/engine/install/">here.</a>

### How to run cypress tests on the local machine
For executing tests without need to install cypress or nodejs on local machine run following in `cypress-studio` folder:
```sh
docker run -it -v $PWD:/e2e -w /e2e cypress/included:8.5.0
```

### Build docker image with tests
Run following in `cypress-studio`folder:
```sh
docker build -t modus/cypress-studio:latest .
```

Run tests locally:
```sh
docker run -it modus/cypress-studio:latest
```

### Push image in a docker repository

To push the image in a private repo, we have to retag the image to point on the target docker repository. Otherwise, the default is Dockerhub.

```sh
docker tag modus/cypress-studio:latest path-to-private-repo.com/repo/cypress-studio:latest
```
Where `path-to-private-repo.com/repo/cypress-studio:latest`is provate target docker repository.

Credentials for the target docker repository are needed for the push.

Push image with:
```sh
docker push path-to-private-repo.com/repo/cypress-studio:latest
```

## Deploy on Kubernetes
### Prerequisites
Docker image is built and pushed in the target repository. Install `kubectl` tool and configure access to Kubernetes cluster.
Installation instructions are <a href="https://kubernetes.io/docs/tasks/tools/">here.</a><br>
Alternatively, run on a local machine mini cube - follow instructions <a href="https://minikube.sigs.k8s.io/docs/start/">here.</a>

### Kubernetes YAML example

Save following YAML as `modus-test-job.yaml`
```YAML
apiVersion: batch/v1
kind: Job
metadata:
name: modus-cypress-test-job
spec:
template:
spec:
containers:
- name: modus-cypress-test-job
image: path-to-private-repo.com/repo/cypress-studio:latest
```

Deploy job on kubernetes:
```sh
kubectl apply -f modus-test-job.yaml
```

Find exact name of the jobs pod with:
```sh
kubectl get pods
```

Using `kubectl logs modus-cypress-test-job-XXX` get logs/results where `modus-cypress-test-job-XXX`is the name of the job.
On development/testing, cluster logs could be redirected to the central logging system, and results could be visible there.


<!-- CONTACT -->
## Contact

Expand Down
23 changes: 23 additions & 0 deletions nightwatchJS/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM node

RUN apt update && apt-get clean && apt install -y x11vnc xvfb fluxbox wmctrl wget libnss3-dev libgdk-pixbuf2.0-dev libgtk-3-dev libxss-dev vim nano

RUN wget -q -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.list \
&& apt-get update && apt-get -y install google-chrome-stable

COPY . /app
WORKDIR /app

RUN npm install nightwatch
RUN npm install chromedriver

RUN useradd app -d /app \
&& mkdir -p /app \
&& chown -v -R app:app /app

USER app

EXPOSE 9515

ENTRYPOINT npm test
77 changes: 77 additions & 0 deletions nightwatchJS/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,82 @@ OR
this command will trigger all tests and its subfolder tests via Chrome browser


<!-- DOCKER SECTION -->
## How to run tests with docker

### Prerequisites
Install the latest Docker engine on the local machine following instructions <a href="https://docs.docker.com/engine/install/">here.</a>

### Build docker image with tests
Run following in `nightwatchJS`folder:
```sh
docker build -t modus/nightwatchjs:latest .
```

Run tests locally:
```sh
docker run -it modus/nightwatchjs:latest
```


### Push image to a docker repository

To push the image to a private repo, we have to retag the image to point on the target docker repository. Otherwise, the default is Dockerhub.

Push to DockerGub (need credentials for DockerHub)
```sh
docker push modus/nightwatchjs:latest
```

Push to private repository:

```sh
docker tag modus/nightwatchjs:latest path-to-private-repo.com/repo/nightwatchjs:latest
```
Where `path-to-private-repo.com/repo/nightwatchjs:latest`is private target docker repository.

Credentials for the target docker repository are needed for the push.

Push image with:
```sh
docker push path-to-private-repo.com/repo/nightwatchjs:latest
```

## Deploy on Kubernetes
### Prerequisites
Docker image is built and pushed in the target repository. Install `kubectl` tool and configure access to Kubernetes cluster. <br>
Installation instructions are <a href="https://kubernetes.io/docs/tasks/tools/">here.</a><br>
Alternatively, run on a local machine mini cube - follow instructions <a href="https://minikube.sigs.k8s.io/docs/start/">here.</a>

### Kubernetes YAML example

Save following YAML as `modus-test-job.yaml`
```YAML
apiVersion: batch/v1
kind: Job
metadata:
name: modus-nightwatch-test-job
spec:
template:
spec:
containers:
- name: modus-nightwatch-test-job
image: modus/nightwatchjs:latest
```
Previous YAML assume that docker image is pushed on DockerHub.

Deploy job on kubernetes:
```sh
kubectl apply -f modus-test-job.yaml
```

Find exact name of the jobs pod with:
```sh
kubectl get pods
```

Using `kubectl logs modus-nightwatch-test-job-XXX` get logs/results where `modus-nightwatch-test-job-XXX`is the name of the job.
On development/testing, cluster logs could be redirected to the central logging system, and results could be visible there.



18 changes: 16 additions & 2 deletions nightwatchJS/nightwatch.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,22 @@ module.exports = {
"test_settings" : {
"default" : {
"desiredCapabilities": {
"browserName": "chrome"
"browserName": "chrome",
"chromeOptions" : {
"args" : ["headless", "no-sandbox", "disable-gpu"]
}
}
}
},

"chrome" : {
"desiredCapabilities": {
"browserName": "chrome",
"chromeOptions" : {
"args" : ["headless", "no-sandbox", "disable-gpu"]
},
"javascriptEnabled": true,
"acceptSslCerts": true
}
}
},
}