fix the uid and gid of the user in the docker container (#4610)

* fix the uid and gid of the user in the container

this fixes this error:
unsafe repository ('/src' is owned by someone else)
this caused the hash to go missing in the version number

* add --interactive option to .ci/docker.sh

* add --dir to .ci/compile.sh

* fix up the comments on the ci scripts

* add extra comment to docker.sh
This commit is contained in:
ebbit1q 2022-04-19 01:04:49 +02:00 committed by GitHub
parent 64c6611ea5
commit 79501a4af7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 8 deletions

View file

@ -1,6 +1,19 @@
#!/bin/bash #!/bin/bash
# This script is to be used by the ci environment from the project root directory, do not use it from somewhere else. # This script is to be used by the ci environment from the project root directory, do not use it from somewhere else.
# Compiles cockatrice inside of a ci environment
# --format runs the clang-format script first
# --install runs make install
# --package [<package type>] runs make package, optionally force the type
# --suffix <suffix> renames package with this suffix, requires arg
# --server compiles servatrice
# --test runs tests
# --debug or --release or <arg> sets the build type ie CMAKE_BUILD_TYPE
# --ccache uses ccache and shows stats
# --dir <dir> sets the name of the build dir, default is "build"
# uses env: BUILDTYPE CHECK_FORMAT MAKE_INSTALL MAKE_PACKAGE PACKAGE_TYPE PACKAGE_SUFFIX MAKE_SERVER MAKE_TEST USE_CCACHE BUILD_DIR (correspond to args: <buildtype>/--debug/--release --format --install --package <package type> --suffix <suffix> --server --test --ccache --dir <dir>)
# exitcode: 1 for failure, 3 for invalid arguments
LINT_SCRIPT=".ci/lint_cpp.sh" LINT_SCRIPT=".ci/lint_cpp.sh"
# Read arguments # Read arguments
@ -29,7 +42,7 @@ while [[ $# != 0 ]]; do
shift shift
if [[ $# == 0 ]]; then if [[ $# == 0 ]]; then
echo "::error file=$0::--suffix expects an argument" echo "::error file=$0::--suffix expects an argument"
exit 1 exit 3
fi fi
PACKAGE_SUFFIX="$1" PACKAGE_SUFFIX="$1"
shift shift
@ -54,6 +67,15 @@ while [[ $# != 0 ]]; do
USE_CCACHE=1 USE_CCACHE=1
shift shift
;; ;;
'--dir')
shift
if [[ $# == 0 ]]; then
echo "::error file=$0::--dir expects an argument"
exit 3
fi
BUILD_DIR="$1"
shift
;;
*) *)
if [[ $1 == -* ]]; then if [[ $1 == -* ]]; then
echo "::error file=$0::unrecognized option: $1" echo "::error file=$0::unrecognized option: $1"
@ -76,8 +98,11 @@ set -e
# Setup # Setup
./servatrice/check_schema_version.sh ./servatrice/check_schema_version.sh
mkdir -p build if [[ ! $BUILD_DIR ]]; then
cd build BUILD_DIR="build"
fi
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
if [[ ! $CMAKE_BUILD_PARALLEL_LEVEL ]]; then if [[ ! $CMAKE_BUILD_PARALLEL_LEVEL ]]; then
CMAKE_BUILD_PARALLEL_LEVEL=2 # default machines have 2 cores CMAKE_BUILD_PARALLEL_LEVEL=2 # default machines have 2 cores

View file

@ -3,11 +3,14 @@
# This script is to be used by the ci environment from the project root directory, do not use it from somewhere else. # This script is to be used by the ci environment from the project root directory, do not use it from somewhere else.
# Creates or loads docker images to use in compilation, creates RUN function to start compilation on the docker image. # Creates or loads docker images to use in compilation, creates RUN function to start compilation on the docker image.
# <arg> sets the name of the docker image, these correspond to directories in .ci
# --get loads the image from a previously saved image cache, will build if no image is found # --get loads the image from a previously saved image cache, will build if no image is found
# --build builds the image from the Dockerfile in .ci/$NAME # --build builds the image from the Dockerfile in .ci/$NAME
# --save stores the image, if an image was loaded it will not be stored # --save stores the image, if an image was loaded it will not be stored
# --interactive immediately starts the image interactively for debugging
# --set-cache <location> sets the location to cache the image or for ccache
# requires: docker # requires: docker
# uses env: NAME CACHE BUILD GET SAVE (correspond to args: <name> --set-cache <cache> --build --get --save) # uses env: NAME CACHE BUILD GET SAVE INTERACTIVE (correspond to args: <name> --set-cache <cache> --build --get --save --interactive)
# sets env: RUN CCACHE_DIR IMAGE_NAME RUN_ARGS RUN_OPTS BUILD_SCRIPT # sets env: RUN CCACHE_DIR IMAGE_NAME RUN_ARGS RUN_OPTS BUILD_SCRIPT
# exitcode: 1 for failure, 2 for missing dockerfile, 3 for invalid arguments # exitcode: 1 for failure, 2 for missing dockerfile, 3 for invalid arguments
export BUILD_SCRIPT=".ci/compile.sh" export BUILD_SCRIPT=".ci/compile.sh"
@ -28,6 +31,10 @@ while [[ $# != 0 ]]; do
GET=1 GET=1
shift shift
;; ;;
'--interactive')
INTERACTIVE=1
shift
;;
'--save') '--save')
SAVE=1 SAVE=1
shift shift
@ -36,7 +43,7 @@ while [[ $# != 0 ]]; do
CACHE=$2 CACHE=$2
if ! [[ -d $CACHE ]]; then if ! [[ -d $CACHE ]]; then
echo "could not find cache path: $CACHE" >&2 echo "could not find cache path: $CACHE" >&2
exit 3 return 3
fi fi
shift 2 shift 2
;; ;;
@ -88,7 +95,6 @@ else
fi fi
fi fi
# Get the docker image from previously stored save # Get the docker image from previously stored save
if [[ $GET ]]; then if [[ $GET ]]; then
if [[ $img_save ]] && docker load --input "$img_save"; then if [[ $img_save ]] && docker load --input "$img_save"; then
@ -133,9 +139,12 @@ function RUN ()
{ {
echo "running image:" echo "running image:"
if docker images | grep "$IMAGE_NAME"; then if docker images | grep "$IMAGE_NAME"; then
args=(--mount "type=bind,source=$PWD,target=/src" -w="/src") local args=(--mount "type=bind,source=$PWD,target=/src")
args+=(--workdir "/src")
args+=(--user "$(id -u):$(id -g)")
if [[ $CCACHE_DIR ]]; then if [[ $CCACHE_DIR ]]; then
args+=(--mount "type=bind,source=$CCACHE_DIR,target=/.ccache" -e "CCACHE_DIR=/.ccache") args+=(--mount "type=bind,source=$CCACHE_DIR,target=/.ccache")
args+=(--env "CCACHE_DIR=/.ccache")
fi fi
docker run "${args[@]}" $RUN_ARGS "$IMAGE_NAME" bash "$BUILD_SCRIPT" $RUN_OPTS "$@" docker run "${args[@]}" $RUN_ARGS "$IMAGE_NAME" bash "$BUILD_SCRIPT" $RUN_OPTS "$@"
return $? return $?
@ -144,3 +153,11 @@ function RUN ()
return 3 return 3
fi fi
} }
# for debugging, start the docker image interactively instead of building
# starts immediately, does not require sourcing or RUN
if [[ $INTERACTIVE ]]; then
export BUILD_SCRIPT="-i"
export RUN_ARGS="$RUN_ARGS -it"
RUN
fi