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:
parent
64c6611ea5
commit
79501a4af7
2 changed files with 50 additions and 8 deletions
|
@ -1,6 +1,19 @@
|
|||
#!/bin/bash
|
||||
|
||||
# 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"
|
||||
|
||||
# Read arguments
|
||||
|
@ -29,7 +42,7 @@ while [[ $# != 0 ]]; do
|
|||
shift
|
||||
if [[ $# == 0 ]]; then
|
||||
echo "::error file=$0::--suffix expects an argument"
|
||||
exit 1
|
||||
exit 3
|
||||
fi
|
||||
PACKAGE_SUFFIX="$1"
|
||||
shift
|
||||
|
@ -54,6 +67,15 @@ while [[ $# != 0 ]]; do
|
|||
USE_CCACHE=1
|
||||
shift
|
||||
;;
|
||||
'--dir')
|
||||
shift
|
||||
if [[ $# == 0 ]]; then
|
||||
echo "::error file=$0::--dir expects an argument"
|
||||
exit 3
|
||||
fi
|
||||
BUILD_DIR="$1"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
if [[ $1 == -* ]]; then
|
||||
echo "::error file=$0::unrecognized option: $1"
|
||||
|
@ -76,8 +98,11 @@ set -e
|
|||
|
||||
# Setup
|
||||
./servatrice/check_schema_version.sh
|
||||
mkdir -p build
|
||||
cd build
|
||||
if [[ ! $BUILD_DIR ]]; then
|
||||
BUILD_DIR="build"
|
||||
fi
|
||||
mkdir -p "$BUILD_DIR"
|
||||
cd "$BUILD_DIR"
|
||||
|
||||
if [[ ! $CMAKE_BUILD_PARALLEL_LEVEL ]]; then
|
||||
CMAKE_BUILD_PARALLEL_LEVEL=2 # default machines have 2 cores
|
||||
|
|
|
@ -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.
|
||||
|
||||
# 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
|
||||
# --build builds the image from the Dockerfile in .ci/$NAME
|
||||
# --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
|
||||
# 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
|
||||
# exitcode: 1 for failure, 2 for missing dockerfile, 3 for invalid arguments
|
||||
export BUILD_SCRIPT=".ci/compile.sh"
|
||||
|
@ -28,6 +31,10 @@ while [[ $# != 0 ]]; do
|
|||
GET=1
|
||||
shift
|
||||
;;
|
||||
'--interactive')
|
||||
INTERACTIVE=1
|
||||
shift
|
||||
;;
|
||||
'--save')
|
||||
SAVE=1
|
||||
shift
|
||||
|
@ -36,7 +43,7 @@ while [[ $# != 0 ]]; do
|
|||
CACHE=$2
|
||||
if ! [[ -d $CACHE ]]; then
|
||||
echo "could not find cache path: $CACHE" >&2
|
||||
exit 3
|
||||
return 3
|
||||
fi
|
||||
shift 2
|
||||
;;
|
||||
|
@ -88,7 +95,6 @@ else
|
|||
fi
|
||||
fi
|
||||
|
||||
|
||||
# Get the docker image from previously stored save
|
||||
if [[ $GET ]]; then
|
||||
if [[ $img_save ]] && docker load --input "$img_save"; then
|
||||
|
@ -133,9 +139,12 @@ function RUN ()
|
|||
{
|
||||
echo "running image:"
|
||||
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
|
||||
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
|
||||
docker run "${args[@]}" $RUN_ARGS "$IMAGE_NAME" bash "$BUILD_SCRIPT" $RUN_OPTS "$@"
|
||||
return $?
|
||||
|
@ -144,3 +153,11 @@ function RUN ()
|
|||
return 3
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue