Skip to content

[WIP] ddtest local user #13936

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
7 changes: 4 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ services:
# dockerfile: Dockerfile
image: ghcr.io/datadog/dd-trace-py/testrunner:8b69a2610342b333f8832422ffc4f3a9327bed13@sha256:c2d067947ffdb305fc7dc7ff1f8eb7035cfa110bd1199917dd2519eadd166402
command: bash
entrypoint: /project/scripts/ddtest-entrypoint.sh
environment:
DD_SETUP_CACHE_DOWNLOADS: "1"
DD_CMAKE_INCREMENTAL_BUILD: "1"
Expand All @@ -184,11 +185,11 @@ services:
CARGO_BUILD_JOBS: "12"
network_mode: host
userns_mode: host
working_dir: /root/project/
working_dir: /project/
volumes:
- ddagent:/tmp/ddagent
- ./:/root/project
- ./.riot:/root/project/.riot
- ./:/project
- ./.riot:/project/.riot

localstack:
image: localstack/localstack:1.4.0
Expand Down
8 changes: 8 additions & 0 deletions scripts/ddtest
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ then
CMD=bash
fi

# Make UID and GID available to the testrunner container, to run with the same user as the host.
# The entrypoint at scripts/ddtest-entrypoint.sh will drop privileges to the user with the given UID and GID.
# This will ensure any file created on mounted volumes have the right ownership.
export EFFECTIVE_UID=$(id -u)
export EFFECTIVE_GID=$(id -g)

docker compose run \
-e DD_TRACE_AGENT_URL \
-e EFFECTIVE_UID \
-e EFFECTIVE_GID \
--rm \
-i \
testrunner \
Expand Down
13 changes: 13 additions & 0 deletions scripts/ddtest-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -eu

# If EFFECTIVE_UID, EFFECTIVE_GID are set, then create a user with that UID and GID
# and drop privileges to that user.
if [ -n "${EFFECTIVE_UID:-}" ] && [ -n "${EFFECTIVE_GID:-}" ]; then
groupadd -g "${EFFECTIVE_GID}" user
useradd -u "${EFFECTIVE_UID}" -g "${EFFECTIVE_GID}" -m user
env
exec su - user -c "$@"
fi

exec "$@"
Loading