Skip to content

Commit

Permalink
Run docker container as current user, not as root
Browse files Browse the repository at this point in the history
  • Loading branch information
blishko committed Oct 30, 2024
1 parent b5b8084 commit 125b2f0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
3 changes: 2 additions & 1 deletion scripts/ci/build_emscripten.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ set -ev
SCRIPT_DIR="$(realpath "$(dirname "$0")/..")"
# shellcheck source=scripts/common.sh
source "${SCRIPT_DIR}/common.sh"
ROOT_DIR="${SCRIPT_DIR}/.."

function build() {
local build_dir="$1"
local prerelease_source="${2:-ci}"

cd /root/project
cd "${ROOT_DIR}"

# shellcheck disable=SC2166
if [[ "$CIRCLE_BRANCH" = release || -n "$CIRCLE_TAG" || -n "$FORCE_RELEASE" || "$(git tag --points-at HEAD 2>/dev/null)" == v* ]]
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/build_ossfuzz.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -ex

ROOTDIR="/root/project"
ROOTDIR="/project"
BUILDDIR="${ROOTDIR}/build"
mkdir -p "${BUILDDIR}" && mkdir -p "$BUILDDIR/deps"

Expand Down
11 changes: 3 additions & 8 deletions scripts/ci/docker_upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,12 @@ docker build "scripts/docker/${IMAGE_NAME}" --file "scripts/docker/${IMAGE_NAME}

echo "-- test_docker @ '${PWD}'"

# NOTE: Since /root/project/ is a dir from outside the container and the owner of the files is different,
# git show in the script refuses to work. It must be marked as safe to use first.
# See https://github.blog/2022-04-12-git-security-vulnerability-announced/
docker run \
--rm \
--volume "${PWD}:/root/project" \
--volume "${PWD}:/project" \
-u "$(id -u "${USER}"):$(id -g "${USER}")" \
"${IMAGE_NAME}" \
bash -c "
git config --global --add safe.directory /root/project &&
/root/project/scripts/ci/${IMAGE_NAME}_test_${IMAGE_VARIANT}.sh
"
bash -c "/project/scripts/ci/${IMAGE_NAME}_test_${IMAGE_VARIANT}.sh"

echo "-- push_docker"

Expand Down

0 comments on commit 125b2f0

Please sign in to comment.