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

Add with-browser Docker image #829

Merged
merged 7 commits into from
Aug 27, 2024
Merged

Add with-browser Docker image #829

merged 7 commits into from
Aug 27, 2024

Conversation

The-9880
Copy link
Contributor

@The-9880 The-9880 commented Aug 19, 2024

Issue: https://github.com/grafana/synthetic-monitoring/issues/71
Adds a 3rd stage to the Dockerfile to build the sm-agent image from an Alpine base, installing chromium-switshader.

The Drone CI pipeline is also updated to publish new image versions (tagged *-with-browser) corresponding to the new build target:

  • latest-with-browser
  • <semver-long>-with-browser

We should probably prevent this from publishing until we have some logic in the agent that can leverage it.

@The-9880 The-9880 requested a review from a team as a code owner August 19, 2024 09:51
@The-9880 The-9880 force-pushed the build-browser-image branch from d5101df to dc88a47 Compare August 19, 2024 09:53
@CLAassistant
Copy link

CLAassistant commented Aug 19, 2024

CLA assistant check
All committers have signed the CLA.

@The-9880 The-9880 requested a review from nadiamoe August 19, 2024 10:01
Copy link
Member

@nadiamoe nadiamoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few small comments, and a few bigger ones that we can leave for follow-up PRs if this one has been tested working.

scripts/configs/drone/main.jsonnet Outdated Show resolved Hide resolved
scripts/configs/drone/main.jsonnet Outdated Show resolved Hide resolved
step(
'docker publish (with browser) tags',
[
'{ echo latest-with-browser,$(eval ./scripts/version)-with-browser ; } > .tags', // use with-browser tags for docker plugin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to use a shorter -browser suffix instead of -with-browser, just for the sake of brevity. I think the short version does not leave much room for ambiguity. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree! I noticed other Docker images like that for k6 were using -with-browser, but I don't mind shortening it for us

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, normally I would want it to be consistent with other releases but because we build a longer tag name for our images, including the commit hash, I think I like keeping it shorter for this case

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... that's a good point, consistency is good... I don't see a clear winner but I'm still leaning towards -browser for short. Maybe we can ask the rest of the team to see if anyone has a strong opinion?

Dockerfile Show resolved Hide resolved
Dockerfile Show resolved Hide resolved
Dockerfile Outdated
Comment on lines 27 to 28
ENV SM_CHROME_BIN=/usr/bin/chromium-browser
ENV SM_CHROME_PATH=/usr/lib/chromium/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these two for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wondered if providing an env var might be useful instead of relying on PATH to have chromium/assuming the binary name, for when sm-agent leverages it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we add xk6-browser to the k6 setup for this? We may want to add K6_BROWSER_HEADLESS and K6_BROWSER_ARGS for that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xk6-browser is now part of k6, so it's already there :D

I believe it should already be looking for the correct path, but we definitely want to tweak K6_BROWSER_ARGS. For instance, --disable-dev-shm-usage is required for some webpages to not crash on a container.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The K6 Dockerfile seems to do the following:

# no-sandbox chrome arg is required to run chrome browser in
# alpine and avoids the usage of SYS_ADMIN Docker capability
ENV K6_BROWSER_ARGS=no-sandbox

Should we be using no-sandbox as well? I'll add it tentatively to this PR, will re-request your review again before I merge anything.

Dockerfile Outdated
COPY --from=release /usr/local/lib/synthetic-monitoring-agent/pre-stop.sh /usr/local/lib/synthetic-monitoring-agent/pre-stop.sh
COPY --from=release /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt

ENTRYPOINT ["/usr/local/bin/synthetic-monitoring-agent"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With browser added in, we'll have the agent start the k6 process, which will itself start a chromium process, which will spawn a gazillion processes itself. I think this calls for adding tini to make sure all those children are properly terminated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

# third stage with alpine base for better access to chromium
FROM alpine:3.18 as with-browser

RUN apk --no-cache add chromium-swiftshader
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point we will be running everything as root. I think this can be left for a follow-up as well, but running a browser as root makes me a bit scared so we might want to avoid that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I can add a user and operate the remainder of the target from there

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-thinking this (sorry)... This might get us into problems where running the agent as non-root might cause some check types to fail. e.g. traceroute/ping checks require either elevated privileges or net_raw capabilities to be added to the binary.

It might be better for now to run everything as root, and open an issue to narrow-down the privileges without breaking agent checks.

Copy link
Member

@nadiamoe nadiamoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this passes some happy path tests, it looks good to me as a first iteration to unblock early adopters and internal tests.

I'd suggest to open a few follow-up issues to act on before we make this more widely available:

  • Migrate base image to alpine to consolidate in one distro
  • Pin and auto update chromium versions (Copy from ci/renovate: update pinned alpine packages crocochrome#5 when it is merged)
  • Run both agent and chromium as non-root, granting required capabilities (i.e. net_raw) to the agent binary.

@nadiamoe
Copy link
Member

Forgot to mention, making sure that --disable-dev-shm-usage is passed to chromium is probably something we should figure out in this PR.

@The-9880 The-9880 requested a review from nadiamoe August 20, 2024 19:35
Copy link
Member

@nadiamoe nadiamoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

step(
'docker publish (with browser) tags',
[
'{ echo latest-browser,$(eval ./scripts/version)-browser ; } > .tags', // use with-browser tags for docker plugin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a small nit, is there a reason for this command using eval and curly braces?
On my PC, this seems to work:

echo "latest-browser,$(./scripts/version)-browser"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should work - updating!

Updates the Dockerfile into a multi-stage build. The new final stage is based off of Alpine to enable
simple access to chromium-swiftshader as the choice of headless browser. The Drone CI config is
updated with additional stages to tag and push alternate Docker images corresponding to this stage.
@The-9880 The-9880 force-pushed the build-browser-image branch from 637fb3f to 4adbab7 Compare August 27, 2024 14:50
@The-9880
Copy link
Contributor Author

Merging without re-approval as the only change was to sort out the .drone.yml conflict with main.

@The-9880 The-9880 merged commit dd89415 into main Aug 27, 2024
2 checks passed
@The-9880 The-9880 deleted the build-browser-image branch August 27, 2024 18:10
ka3de added a commit that referenced this pull request Sep 2, 2024
* k6runner: always log error code and string to user's logger
* Update module golang.org/x/sync to v0.8.0 (#812)
* Update module golang.org/x/net to v0.28.0 (#813)
* Build(deps): Bump the prometheus-go group across 1 directory with 2 updates (#827)
* Update ghcr.io/grafana/grafana-build-tools Docker tag to v0.22.0 (#817)
* Update module go.k6.io/k6 to v0.53.0 (#823)
* Update dependency grafana/k6 to v0.53.0
* Update module github.com/miekg/dns to v1.1.62
* Update github.com/grafana/loki/pkg/push digest to 9315b3d
* Update golang.org/x/exp digest to 9b4947d
* Update github.com/securego/gosec/v2 digest to ab3f6c1
* Update github.com/grafana/loki/pkg/push digest to 246a1df
* Update ghcr.io/grafana/grafana-build-tools Docker tag to v0.23.0
* Build(deps): Bump github.com/prometheus/client_golang
* Update module github.com/securego/gosec to v2
* renovate: fix grafana-build-tools dependency regex
* Update ghcr.io/grafana/grafana-build-tools Docker tag to v0.23.0
* drone: regenerate pipelines
* Add with-browser Docker image (#829)
* Update module github.com/prometheus/prometheus to v0.54.1 (#843)
* Update module github.com/prometheus/common to v0.56.0 (#849)
* Build(deps): Bump google.golang.org/grpc from 1.65.0 to 1.66.0
* Build(deps): Bump github.com/prometheus/common
* renovate: group prometheus-go updates
* renovate: enable default managers
* renovate: add `dependencies` label to PRs
* dependabot: remove
* Update renovatebot/github-action action to v40.2.7 (#859)
* go: upgrade to 1.23 (#838)
* Update module github.com/golangci/golangci-lint to v1.60.0 (#825)
* Update alpine Docker tag to v3.20 (#858)
* Update actions/checkout action to v4.1.7 (#857)
* Dockerfile: pin hash of debian:stable-slim image (#828)
* Update module github.com/mccutchen/go-httpbin/v2 to v2.14.1 (#860)
* Update module github.com/securego/gosec to v2 (#861)
* feat: Validate browser capability (#809)

Signed-off-by: ka3de <[email protected]>
@ka3de ka3de mentioned this pull request Sep 2, 2024
ka3de added a commit that referenced this pull request Sep 2, 2024
* k6runner: always log error code and string to user's logger
* Update module golang.org/x/sync to v0.8.0 (#812)
* Update module golang.org/x/net to v0.28.0 (#813)
* Build(deps): Bump the prometheus-go group across 1 directory with 2 updates (#827)
* Update ghcr.io/grafana/grafana-build-tools Docker tag to v0.22.0 (#817)
* Update module go.k6.io/k6 to v0.53.0 (#823)
* Update dependency grafana/k6 to v0.53.0
* Update module github.com/miekg/dns to v1.1.62
* Update github.com/grafana/loki/pkg/push digest to 9315b3d
* Update golang.org/x/exp digest to 9b4947d
* Update github.com/securego/gosec/v2 digest to ab3f6c1
* Update github.com/grafana/loki/pkg/push digest to 246a1df
* Update ghcr.io/grafana/grafana-build-tools Docker tag to v0.23.0
* Build(deps): Bump github.com/prometheus/client_golang
* Update module github.com/securego/gosec to v2
* renovate: fix grafana-build-tools dependency regex
* Update ghcr.io/grafana/grafana-build-tools Docker tag to v0.23.0
* drone: regenerate pipelines
* Add with-browser Docker image (#829)
* Update module github.com/prometheus/prometheus to v0.54.1 (#843)
* Update module github.com/prometheus/common to v0.56.0 (#849)
* Build(deps): Bump google.golang.org/grpc from 1.65.0 to 1.66.0
* Build(deps): Bump github.com/prometheus/common
* renovate: group prometheus-go updates
* renovate: enable default managers
* renovate: add `dependencies` label to PRs
* dependabot: remove
* Update renovatebot/github-action action to v40.2.7 (#859)
* go: upgrade to 1.23 (#838)
* Update module github.com/golangci/golangci-lint to v1.60.0 (#825)
* Update alpine Docker tag to v3.20 (#858)
* Update actions/checkout action to v4.1.7 (#857)
* Dockerfile: pin hash of debian:stable-slim image (#828)
* Update module github.com/mccutchen/go-httpbin/v2 to v2.14.1 (#860)
* Update module github.com/securego/gosec to v2 (#861)
* feat: Validate browser capability (#809)

Signed-off-by: ka3de <[email protected]>
ka3de added a commit that referenced this pull request Sep 2, 2024
* k6runner: always log error code and string to user's logger
* Update module golang.org/x/sync to v0.8.0 (#812)
* Update module golang.org/x/net to v0.28.0 (#813)
* Build(deps): Bump the prometheus-go group across 1 directory with 2 updates (#827)
* Update ghcr.io/grafana/grafana-build-tools Docker tag to v0.22.0 (#817)
* Update module go.k6.io/k6 to v0.53.0 (#823)
* Update dependency grafana/k6 to v0.53.0
* Update module github.com/miekg/dns to v1.1.62
* Update github.com/grafana/loki/pkg/push digest to 9315b3d
* Update golang.org/x/exp digest to 9b4947d
* Update github.com/securego/gosec/v2 digest to ab3f6c1
* Update github.com/grafana/loki/pkg/push digest to 246a1df
* Update ghcr.io/grafana/grafana-build-tools Docker tag to v0.23.0
* Build(deps): Bump github.com/prometheus/client_golang
* Update module github.com/securego/gosec to v2
* renovate: fix grafana-build-tools dependency regex
* Update ghcr.io/grafana/grafana-build-tools Docker tag to v0.23.0
* drone: regenerate pipelines
* Add with-browser Docker image (#829)
* Update module github.com/prometheus/prometheus to v0.54.1 (#843)
* Update module github.com/prometheus/common to v0.56.0 (#849)
* Build(deps): Bump google.golang.org/grpc from 1.65.0 to 1.66.0
* Build(deps): Bump github.com/prometheus/common
* renovate: group prometheus-go updates
* renovate: enable default managers
* renovate: add `dependencies` label to PRs
* dependabot: remove
* Update renovatebot/github-action action to v40.2.7 (#859)
* go: upgrade to 1.23 (#838)
* Update module github.com/golangci/golangci-lint to v1.60.0 (#825)
* Update alpine Docker tag to v3.20 (#858)
* Update actions/checkout action to v4.1.7 (#857)
* Dockerfile: pin hash of debian:stable-slim image (#828)
* Update module github.com/mccutchen/go-httpbin/v2 to v2.14.1 (#860)
* Update module github.com/securego/gosec to v2 (#861)
* feat: Validate browser capability (#809)

Signed-off-by: ka3de <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants