selenoid icon indicating copy to clipboard operation
selenoid copied to clipboard

Add ability to set docker user and command/entrypoint

Open lionelnicolas opened this issue 2 years ago • 6 comments

This adds support for user, cmd and entrypoint attributes, which can be set in the browsers.json config, and overridable using capabilities. If not set, the behavior remains unchanged: it's still going to use the USER and the CMD / ENTRYPOINT instruction set in the docker image.

This is useful to be able to use an alternative entrypoint at container startup, which may need to run administrative tasks in the container.

My current use-case for this is that I'm using an IPv6-enabled docker network, and in some tests I want to be able to run IPv6-only connectivity. To achieve that, I'm running a custom entrypoint before calling the existing /entrypoint.sh, which simply delete the IPv4 default route to break external IPv4 connectivity, based on an environment variable set from the capabilities.

# if IPv6 only is requested, delete the default IPv4 route to nuke IPv4 external connectivity
if [ "$(echo ${IPV6_ONLY:-} | tr '[A-Z]' '[a-z]')" = "true" ]; then
	ip -4 route del default || true
fi

exec /entrypoint.sh

I'm also thinking about creating a PR in https://github.com/aerokube/images/ to add support for pre/post hooks in the existing entrypoint.sh. So I could use --volume /path/to/my/script:/entrypoint.pre.d/10-kill-ipv4:ro when starting the browser containers, but I'll still need to be able to run the container as root.

lionelnicolas avatar Jun 25 '22 18:06 lionelnicolas

Marking as draft for now as coverage tests will probably fail.

lionelnicolas avatar Jun 25 '22 18:06 lionelnicolas

Added coverage for tests

lionelnicolas avatar Jun 25 '22 21:06 lionelnicolas

@lionelnicolas shouldn't this be implemented as custom Docker images instead?

vania-pooh avatar Jun 26 '22 08:06 vania-pooh

Codecov Report

Merging #1238 (5ac944a) into master (8a0f80a) will increase coverage by 0.36%. The diff coverage is 100.00%.

:exclamation: Current head 5ac944a differs from pull request most recent head f32d7fa. Consider uploading reports for the commit f32d7fa to get more accurate results

@@            Coverage Diff             @@
##           master    #1238      +/-   ##
==========================================
+ Coverage   76.27%   76.63%   +0.36%     
==========================================
  Files          12       12              
  Lines        1437     1451      +14     
==========================================
+ Hits         1096     1112      +16     
+ Misses        260      258       -2     
  Partials       81       81              
Flag Coverage Δ
go 76.63% <100.00%> (+0.36%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
config/config.go 97.22% <ø> (ø)
session/session.go 92.59% <ø> (ø)
service/docker.go 75.27% <100.00%> (+1.07%) :arrow_up:
service/service.go 71.11% <0.00%> (ø)
selenoid.go 87.50% <0.00%> (+0.37%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update fbf82d8...f32d7fa. Read the comment docs.

codecov[bot] avatar Jun 26 '22 08:06 codecov[bot]

Yeah I thought about that too, but I wanted to be able to use upstream selenoid images to avoid having to manage custom images.

lionelnicolas avatar Jun 26 '22 16:06 lionelnicolas

@vania-pooh What do you think about this PR ? I think this is something that could be useful to some people. If you agree with that patch maybe I should update the documentation too.

Otherwise, feel free to close the PR, and then I'll handle custom docker images on my side.

lionelnicolas avatar Jul 07 '22 04:07 lionelnicolas

Let's not overcomplicate things.

vania-pooh avatar Oct 04 '22 18:10 vania-pooh