Skip to content

Commit 105ced3

Browse files
committed
feat(cypress-deps): add cypress-deps feature
1 parent 87eff6d commit 105ced3

11 files changed

Lines changed: 164 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
matrix:
1717
feature: [
1818
"browsers",
19+
"cypress-deps",
1920
"docker-out",
2021
"git-lfs",
2122
"go",

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Below is a list with included features, click on the link for more details.
1616
| Name | Description |
1717
| --- | --- |
1818
| [browsers](./features/src/browsers/README.md) | A package which installs various browsers. |
19+
| [cypress-deps](./features/src/cypress-deps/README.md) | Installs all system dependencies required for running Cypress tests in a dev container. |
1920
| [docker-out](./features/src/docker-out/README.md) | A feature which installs the Docker client and re-uses the host socket. |
2021
| [git-lfs](./features/src/git-lfs/README.md) | A feature which installs Git LFS. |
2122
| [go](./features/src/go/README.md) | A feature which installs Go. |

build/build.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
var featureList = []string{
2323
"browsers",
24+
"cypress-deps",
2425
"docker-out",
2526
"git-lfs",
2627
"go",
@@ -62,6 +63,17 @@ func init() {
6263
return publishFeature("browsers")
6364
})
6465

66+
////////// cypress-deps
67+
gotaskr.Task("Feature:cypress-deps:Package", func() error {
68+
return packageFeature("cypress-deps")
69+
})
70+
gotaskr.Task("Feature:cypress-deps:Test", func() error {
71+
return testFeature("cypress-deps")
72+
})
73+
gotaskr.Task("Feature:cypress-deps:Publish", func() error {
74+
return publishFeature("cypress-deps")
75+
})
76+
6577
////////// docker-out
6678
gotaskr.Task("Feature:docker-out:Package", func() error {
6779
return packageFeature("docker-out")

features/src/cypress-deps/NOTES.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
## Notes
2+
3+
### Cypress Binary Cache
4+
5+
By default, Cypress installs binaries somewhere in the user home. This directory is not a volume and therefore is cleared when the container is rebuild which means, Cypress needs to be reinstalled in each new container.
6+
7+
To prevent this, the Cypress cache folder can be set to a folder from the workspace which is a volume (basically the cloned repository) and with that, it does not need to be reinstalled each time the container is rebuilt.
8+
9+
To do this, add the following environment variable to your container:
10+
```
11+
"containerEnv": {
12+
"CYPRESS_CACHE_FOLDER": "${containerWorkspaceFolder}/.cypress_cache"
13+
}
14+
```
15+
16+
Also don't forget to add `.cypress_cache` to your `.gitignore` file.
17+
18+
### x11 Socket
19+
20+
The Cypress UI in the dev-container is displayed via x11. If the corresponding socket is not correcly forwarded into the container, this can lead to heavy performance loss due to higher CPU usage.
21+
22+
To correctly forward the x11 socket into the container, make sure to add the following variables to the `runArgs`:
23+
```
24+
"runArgs": [
25+
"-e", "DISPLAY=${localEnv:DISPLAY}",
26+
"-v", "/tmp/.X11-unix:/tmp/.X11-unix"
27+
]
28+
```
29+
30+
### System Compatibility
31+
32+
Debian, Ubuntu
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Cypress Dependencies (cypress-deps)
2+
3+
Installs all system dependencies required for running Cypress tests in a dev container.
4+
5+
## Example Usage
6+
7+
```json
8+
"features": {
9+
"ghcr.io/postfinance/devcontainer-features/cypress-deps:0.1.0": {
10+
}
11+
}
12+
```
13+
14+
## Notes
15+
16+
### Cypress Binary Cache
17+
18+
By default, Cypress installs binaries somewhere in the user home. This directory is not a volume and therefore is cleared when the container is rebuild which means, Cypress needs to be reinstalled in each new container.
19+
20+
To prevent this, the Cypress cache folder can be set to a folder from the workspace which is a volume (basically the cloned repository) and with that, it does not need to be reinstalled each time the container is rebuilt.
21+
22+
To do this, add the following environment variable to your container:
23+
```
24+
"containerEnv": {
25+
"CYPRESS_CACHE_FOLDER": "${containerWorkspaceFolder}/.cypress_cache"
26+
}
27+
```
28+
29+
Also don't forget to add `.cypress_cache` to your `.gitignore` file.
30+
31+
### x11 Socket
32+
33+
The Cypress UI in the dev-container is displayed via x11. If the corresponding socket is not correcly forwarded into the container, this can lead to heavy performance loss due to higher CPU usage.
34+
35+
To correctly forward the x11 socket into the container, make sure to add the following variables to the `runArgs`:
36+
```
37+
"runArgs": [
38+
"-e", "DISPLAY=${localEnv:DISPLAY}",
39+
"-v", "/tmp/.X11-unix:/tmp/.X11-unix"
40+
]
41+
```
42+
43+
### System Compatibility
44+
45+
Debian, Ubuntu
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"id": "cypress-deps",
3+
"version": "0.1.0",
4+
"name": "Cypress Dependencies",
5+
"description": "Installs all system dependencies required for running Cypress tests in a dev container."
6+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
. ./functions.sh
2+
3+
"./installer_$(detect_arch)"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package main
2+
3+
import (
4+
"builder/installer"
5+
"fmt"
6+
"os"
7+
)
8+
9+
func main() {
10+
if err := runMain(); err != nil {
11+
fmt.Printf("Error: %v\n", err)
12+
os.Exit(1)
13+
}
14+
}
15+
16+
func runMain() error {
17+
fmt.Println("Installing Cypress Dependencies")
18+
return installer.Tools.Apt.InstallDependencies(
19+
"libgtk2.0-0",
20+
"libgtk-3-0",
21+
"libgbm-dev",
22+
"libnotify-dev",
23+
"libnss3",
24+
"libxss1",
25+
"libasound2",
26+
"libxtst6",
27+
"xauth",
28+
"xvfb",
29+
)
30+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
set -e
3+
4+
[[ -f "$(dirname "$0")/../functions.sh" ]] && source "$(dirname "$0")/../functions.sh"
5+
[[ -f "$(dirname "$0")/functions.sh" ]] && source "$(dirname "$0")/functions.sh"
6+
7+
check_package_installed "libgtk2.0-0"
8+
check_package_installed "libgtk-3-0"
9+
check_package_installed "libgbm-dev"
10+
check_package_installed "libnotify-dev"
11+
check_package_installed "libnss3"
12+
check_package_installed "libxss1"
13+
check_package_installed "libasound2"
14+
check_package_installed "libxtst6"
15+
check_package_installed "xauth"
16+
check_package_installed "xvfb"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"packages_installed": {
3+
"build": {
4+
"dockerfile": "Dockerfile",
5+
"options": [
6+
"--add-host=host.docker.internal:host-gateway"
7+
]
8+
},
9+
"features": {
10+
"./cypress-deps": {}
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)