devcontainers / features

A collection of Dev Container Features managed by Dev Container spec maintainers. See https://github.com/devcontainers/feature-starter to publish your own
https://containers.dev/features
MIT License
813 stars 314 forks source link

[Feature] Headless browser (chrome/chromium/firefox) #189

Open snebjorn opened 1 year ago

snebjorn commented 1 year ago

I'd love if I could add a headless browser to my dev container using the dev container features.

"features": {
  "headless-chrome": "latest",
  "headless-chromium": "latest",
  "headless-firefox": "latest",
}

All (that I know) JS/TS testing frameworks need it. Manually adding it without having to resort to --no-sandbox is very complicated. I have yet to succeed at it 😞 --no-sandbox is considered insecure and strongly discouraged.

joshspicer commented 1 year ago

I agree, this sounds like an awesome Feature to add!

Not exactly the same as what you're looking for, but want to point you to the existing desktop-lite Feature, that spins up a basic desktop environment that one can connect to via VNC. (https://github.com/devcontainers/features/tree/main/src/desktop-lite)


I'm not sure if this is something that would interest you in implementing, but we have starter code for self-authoring Features if it interested you to give it a go. We're investing a lot in making it quick/easy for members of the community to self-author (spec), and would welcome any feedback on the process.

https://github.com/devcontainers/feature-template

Useful Feature collections can then be registered via PR and will appear in our tooling for the rest of the community to enjoy (see some existing community Features at the bottom of this list 😃 https://containers.dev/features)

snebjorn commented 1 year ago

@joshspicer thanks for the links. I gave it a shot. But it seems there's an issue with running the tests. Not sure what is going on.

https://github.com/snebjorn/devcontainer-feature/actions/runs/3193079539/jobs/5211272135

When running locally I get this error:

root ➜ /workspaces/devcontainer-feature (main ✗) $ devcontainer features test --features chromium --base-image mcr.microsoft.com/devcontainers/base:ubuntu .

┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐
|    dev container 'features' |   
│           v0.19.0           │
└ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘

>  baseImage:         mcr.microsoft.com/devcontainers/base:ubuntu
>  Target Folder:     /workspaces/devcontainer-feature
>  features:          chromium
>  workspaceFolder:   /tmp/devcontainercli/container-features-test/1665008951184

⏳ Building test container...

[1 ms] @devcontainers/cli 0.19.0. Node.js v18.9.1. linux 5.10.16.3-microsoft-standard-WSL2 x64.
[518 ms] Start: Run: docker buildx build --load --build-context dev_containers_feature_content_source=/tmp/devcontainercli-root/container-features/0.19.0-1665008951744 --build-arg _DEV_CONTAINERS_BASE_IMAGE=mcr.microsoft.com/devcontainers/base:ubuntu --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp --target dev_containers_target_stage -t vsc-1665008951184-78f48eade62e871b44e50fb7260d24e9-features -f /tmp/devcontainercli-root/container-features/0.19.0-1665008951744/Dockerfile.extended /tmp/devcontainercli-root/empty-folder
[+] Building 16.8s (10/12)                                                      
[+] Building 17.0s (11/12)                                                      
 => [internal] load build definition from Dockerfile.extended              0.1s
[+] Building 17.1s (11/12)                                                      
 => [internal] load build definition from Dockerfile.extended              0.1s
[+] Building 17.3s (11/12)                                                      
 => [internal] load build definition from Dockerfile.extended              0.1s
[+] Building 17.4s (11/12)                                                      
 => [internal] load build definition from Dockerfile.extended              0.1s
 => => transferring dockerfile: 550B                                       0.0s
 => [internal] load .dockerignore                                          0.1s
 => => transferring context: 2B                                            0.0s
 => resolve image config for docker.io/docker/dockerfile:1.4              16.0s
 => CACHED docker-image://docker.io/docker/dockerfile:1.4@sha256:9ba7531b  0.0s
 => [internal] load .dockerignore                                          0.0s
[+] Building 17.5s (12/12) FINISHED                                             
 => [internal] load build definition from Dockerfile.extended              0.1s
 => => transferring dockerfile: 550B                                       0.0s
 => [internal] load .dockerignore                                          0.1s
 => => transferring context: 2B                                            0.0s
 => resolve image config for docker.io/docker/dockerfile:1.4              16.0s
 => CACHED docker-image://docker.io/docker/dockerfile:1.4@sha256:9ba7531b  0.0s
 => [internal] load .dockerignore                                          0.0s
 => [internal] load build definition from Dockerfile.extended              0.0s
 => [internal] load metadata for mcr.microsoft.com/devcontainers/base:ubu  0.2s
 => [context dev_containers_feature_content_source] load .dockerignore     0.1s
 => => transferring dev_containers_feature_content_source: 2B              0.0s
 => [context dev_containers_feature_content_source] load from client       0.1s
 => => transferring dev_containers_feature_content_source: 20.01kB         0.0s
 => CACHED [dev_containers_target_stage 1/3] FROM mcr.microsoft.com/devco  0.0s
 => [dev_containers_target_stage 2/3] COPY --from=dev_containers_feature_  0.1s
 => ERROR [dev_containers_target_stage 3/3] RUN cd /tmp/build-features/ch  0.6s
------                                                                          
 > [dev_containers_target_stage 3/3] RUN cd /tmp/build-features/chromium_1 && chmod +x ./devcontainer-features-install.sh && ./devcontainer-features-install.sh:
#0 0.496 ===========================================================================
#0 0.496 Feature       : ./chromium                                             
#0 0.496 Description   : Chromium                                               
#0 0.496 Id            : Unknown                                                
#0 0.496 Version       : 1.0.0
#0 0.496 Documentation : 
#0 0.496 Options       :
#0 0.496 
#0 0.496 ===========================================================================
#0 0.506 ./devcontainer-features-install.sh: 26: ./install.sh: not found
#0 0.506 ERROR: Feature "./chromium" (Unknown) failed to install!
------
ERROR: failed to solve: executor failed running [/bin/sh -c cd /tmp/build-features/chromium_1 && chmod +x ./devcontainer-features-install.sh && ./devcontainer-features-install.sh]: exit code: 127
[-] Failed to launch container:

Command failed: docker buildx build --load --build-context dev_containers_feature_content_source=/tmp/devcontainercli-root/container-features/0.19.0-1665008951744 --build-arg _DEV_CONTAINERS_BASE_IMAGE=mcr.microsoft.com/devcontainers/base:ubuntu --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp --target dev_containers_target_stage -t vsc-1665008951184-78f48eade62e871b44e50fb7260d24e9-features -f /tmp/devcontainercli-root/container-features/0.19.0-1665008951744/Dockerfile.extended /tmp/devcontainercli-root/empty-folder

Also where is the docs for dev-container-features-test-lib?

jkeech commented 1 year ago

I'm not sure about the local test execution, but the one in the action shows the following error: https://github.com/snebjorn/devcontainer-feature/actions/runs/3193079539/jobs/5211272135#step:4:151

./install.sh: 15: Bad substitution

That maps to this line in the install script: https://github.com/snebjorn/devcontainer-feature/blob/main/src/chromium/install.sh#L15, so I think the $PATH substitution is not working properly in the script.

snebjorn commented 1 year ago

I copied the script from here https://github.com/devcontainers/features/blob/main/src/dotnet/install.sh#L33-L64 Does it not work or do I need to something to make it work?

samruddhikhandale commented 1 year ago

Hi @snebjorn, were you able to fix the test? Happy to take a look.

snebjorn commented 1 year ago

Hi @samruddhikhandale I don't recall what was the error when running the test on github. But running it locally still doesn't work.

vscode ➜ /workspaces/devcontainer-feature (main) $ devcontainer features test --features chromium --base-image mcr.microsoft.com/devcontainers/base:debian .

┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐
|    dev container 'features' |   
│           v0.23.2           │
└ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘

>  baseImage:         mcr.microsoft.com/devcontainers/base:debian
>  Target Folder:     /workspaces/devcontainer-feature
>  features:          chromium
>  workspaceFolder:   /tmp/devcontainercli/container-features-test/1667776825229

⏳ Building test container...

[1 ms] @devcontainers/cli 0.23.2. Node.js v18.10.0. linux 5.10.102.1-microsoft-standard-WSL2 x64.
[484 ms] Start: Run: docker buildx build --load --build-context dev_containers_feature_content_source=/tmp/devcontainercli-vscode/container-features/0.23.2-1667776825751 --build-arg _DEV_CONTAINERS_BASE_IMAGE=mcr.microsoft.com/devcontainers/base:debian --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp --target dev_containers_target_stage -t vsc-1667776825229-2b0794bc36a5dc7b81f7946755ddffcb-features -f /tmp/devcontainercli-vscode/container-features/0.23.2-1667776825751/Dockerfile.extended /tmp/devcontainercli-vscode/empty-folder
[+] Building 11.4s (13/15)                                                      
 => [internal] load build definition from Dockerfile.extended              0.1s
 => => transferring dockerfile: 1.02kB                                     0.0s
 => [internal] load .dockerignore                                          0.1s
 => => transferring context: 2B                                            0.0s
[+] Building 11.5s (13/15)                                                      
 => [internal] load build definition from Dockerfile.extended              0.1s
 => => transferring dockerfile: 1.02kB                                     0.0s
 => [internal] load .dockerignore                                          0.1s
 => => transferring context: 2B                                            0.0s
[+] Building 11.7s (13/15)                                                      
 => [internal] load build definition from Dockerfile.extended              0.1s
 => => transferring dockerfile: 1.02kB                                     0.0s
 => [internal] load .dockerignore                                          0.1s
 => => transferring context: 2B                                            0.0s
[+] Building 11.8s (14/15)                                                      
 => [internal] load build definition from Dockerfile.extended              0.1s
 => => transferring dockerfile: 1.02kB                                     0.0s
 => [internal] load .dockerignore                                          0.1s
 => => transferring context: 2B                                            0.0s
[+] Building 11.8s (14/15)                                                      
 => [internal] load build definition from Dockerfile.extended              0.1s
 => => transferring dockerfile: 1.02kB                                     0.0s
 => [internal] load .dockerignore                                          0.1s
 => => transferring context: 2B                                            0.0s
 => resolve image config for docker.io/docker/dockerfile:1.4              10.5s
 => CACHED docker-image://docker.io/docker/dockerfile:1.4@sha256:9ba7531b  0.0s
 => [internal] load build definition from Dockerfile.extended              0.0s
 => [internal] load .dockerignore                                          0.0s
 => [internal] load metadata for mcr.microsoft.com/devcontainers/base:deb  0.9s
 => [context dev_containers_feature_content_source] load .dockerignore     0.1s
 => => transferring dev_containers_feature_content_source: 2B              0.0s
 => [context dev_containers_feature_content_source] load from client       0.1s
 => => transferring dev_containers_feature_content_source: 22.08kB         0.0s
 => [dev_containers_feature_content_normalize 1/3] FROM mcr.microsoft.com  0.0s
 => CACHED [dev_containers_feature_content_normalize 2/3] COPY --from=dev  0.0s
 => CACHED [dev_containers_feature_content_normalize 3/3] RUN chmod -R 07  0.0s
 => CACHED [dev_containers_target_stage 2/4] COPY --from=dev_containers_f  0.0s
 => CACHED [dev_containers_target_stage 3/4] RUN echo "_CONTAINER_USER_HO  0.0s
 => ERROR [dev_containers_target_stage 4/4] RUN cd /tmp/build-features/ch  0.6s
------
 > [dev_containers_target_stage 4/4] RUN cd /tmp/build-features/chromium_1 && chmod +x ./devcontainer-features-install.sh && ./devcontainer-features-install.sh:
#0 0.493 ===========================================================================
#0 0.493 Feature       : ./chromium
#0 0.493 Description   : Chromium
#0 0.493 Id            : Unknown
#0 0.493 Version       : 1.0.0
#0 0.493 Documentation : 
#0 0.493 Options       :
#0 0.493 
#0 0.493 ===========================================================================
#0 0.503 ./devcontainer-features-install.sh: 27: ./install.sh: not found
#0 0.503 ERROR: Feature "./chromium" (Unknown) failed to install!
------
ERROR: failed to solve: executor failed running [/bin/sh -c cd /tmp/build-features/chromium_1 && chmod +x ./devcontainer-features-install.sh && ./devcontainer-features-install.sh]: exit code: 127
[-] Failed to launch container:

Command failed: docker buildx build --load --build-context dev_containers_feature_content_source=/tmp/devcontainercli-vscode/container-features/0.23.2-1667776825751 --build-arg _DEV_CONTAINERS_BASE_IMAGE=mcr.microsoft.com/devcontainers/base:debian --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp --target dev_containers_target_stage -t vsc-1667776825229-2b0794bc36a5dc7b81f7946755ddffcb-features -f /tmp/devcontainercli-vscode/container-features/0.23.2-1667776825751/Dockerfile.extended /tmp/devcontainercli-vscode/empty-folder