Set Docker Internal UID to Host UID, Remove Postbuild step
These changes will use docker's new Dockerfile Arguments to pass the Host User ID to the docker container at build time. This allows the docker container to set it's internal user to match that of the host. When using shared volumes between the host and container, this prevents files created in the container from being owned by root. This will solve our problem of needing a cleanup step after every ubuntu CI run.
This commit is contained in:
parent
9ce2063452
commit
b122190cd8
6 changed files with 23 additions and 82 deletions
11
netci.groovy
11
netci.groovy
|
@ -35,7 +35,6 @@ def static getBuildJobName(def configuration, def os) {
|
|||
}
|
||||
else {
|
||||
buildCommand = "./scripts/ci_build.sh ${lowerConfiguration}"
|
||||
postBuildCommand = "./scripts/ci_postbuild.sh ${lowerConfiguration}"
|
||||
}
|
||||
|
||||
// Create the new job
|
||||
|
@ -50,16 +49,6 @@ def static getBuildJobName(def configuration, def os) {
|
|||
else {
|
||||
// Shell
|
||||
shell(buildCommand)
|
||||
|
||||
// Post Build Cleanup
|
||||
publishers {
|
||||
postBuildScripts {
|
||||
steps {
|
||||
shell(postBuildCommand)
|
||||
}
|
||||
onlyIfBuildSucceeds(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
#Ensure running with superuser privileges
|
||||
current_user=$(whoami)
|
||||
if [ $current_user != "root" ]; then
|
||||
echo "test_package.sh requires superuser privileges to run"
|
||||
exit 1
|
||||
echo "WARNING: test_package.sh requires superuser privileges to run"
|
||||
SUDO_PREFIX="sudo"
|
||||
fi
|
||||
|
||||
setup(){
|
||||
|
@ -22,15 +22,15 @@ setup(){
|
|||
}
|
||||
|
||||
install_package(){
|
||||
dpkg -i $PACKAGE_PATH
|
||||
$SUDO_PREFIX dpkg -i $PACKAGE_PATH
|
||||
}
|
||||
|
||||
remove_package(){
|
||||
dpkg -r $PACKAGE_NAME
|
||||
$SUDO_PREFIX dpkg -r $PACKAGE_NAME
|
||||
}
|
||||
|
||||
purge_package(){
|
||||
dpkg -P $PACKAGE_NAME
|
||||
$SUDO_PREFIX dpkg -P $PACKAGE_NAME
|
||||
}
|
||||
|
||||
@test "package install + removal test" {
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
#
|
||||
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
if [[ "$(uname)" == "Linux" ]]; then
|
||||
# Set Docker Container name to be unique
|
||||
container_name=""
|
||||
|
||||
#Jenkins
|
||||
[ ! -z "$BUILD_TAG" ] && container_name="$BUILD_TAG"
|
||||
#VSO
|
||||
[ ! -z "$BUILD_BUILDID" ] && container_name="$BUILD_BUILDID"
|
||||
|
||||
export DOTNET_BUILD_CONTAINER_NAME="$container_name"
|
||||
|
||||
$SCRIPT_DIR/docker/dockerpostbuild.sh $@
|
||||
fi
|
||||
|
||||
ret_code=$?
|
||||
exit $ret_code
|
|
@ -11,8 +11,6 @@ FROM debian:jessie
|
|||
RUN apt-get update && \
|
||||
apt-get -qqy install unzip curl libicu-dev libunwind8 gettext libssl-dev libcurl3-gnutls zlib1g
|
||||
|
||||
# No longer need to install DNX since it is embedded (and soon will be gone!)
|
||||
|
||||
# Install Build Prereqs
|
||||
RUN echo "deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.6 main" | tee /etc/apt/sources.list.d/llvm.list && \
|
||||
curl http://llvm.org/apt/llvm-snapshot.gpg.key | apt-key add - && \
|
||||
|
@ -22,10 +20,26 @@ RUN echo "deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.6 main" | tee
|
|||
# Use clang as c++ compiler
|
||||
RUN update-alternatives --set c++ /usr/bin/clang++
|
||||
|
||||
# Install azure cli. We need this to publish atrifacts.
|
||||
# Install azure cli. We need this to publish artifacts.
|
||||
RUN apt-get -y install nodejs-legacy && \
|
||||
apt-get -y install npm && \
|
||||
npm install -g azure-cli
|
||||
|
||||
|
||||
RUN apt-get install -qqy sudo
|
||||
|
||||
# Setup User to match Host User, and give superuser permissions
|
||||
ARG USER_ID=0
|
||||
RUN useradd code_executor -u ${USER_ID} -g sudo
|
||||
RUN echo 'code_executor ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
|
||||
|
||||
# With the User Change, we need to change permssions on these directories
|
||||
RUN chmod -R a+rwx /usr/local
|
||||
RUN chmod -R a+rwx /home
|
||||
RUN chmod -R 755 /usr/lib/sudo
|
||||
|
||||
# Set user to the one we just created
|
||||
USER ${USER_ID}
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /opt/code
|
||||
|
|
|
@ -23,7 +23,7 @@ cd $DIR/../..
|
|||
|
||||
# Build the docker container (will be fast if it is already built)
|
||||
header "Building Docker Container"
|
||||
docker build -t $DOTNET_BUILD_CONTAINER_TAG scripts/docker/
|
||||
docker build --build-arg USER_ID=$(id -u) -t $DOTNET_BUILD_CONTAINER_TAG scripts/docker/
|
||||
|
||||
# Run the build in the container
|
||||
header "Launching build in Docker Container"
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
#
|
||||
|
||||
SOURCE="${BASH_SOURCE[0]}"
|
||||
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||
SOURCE="$(readlink "$SOURCE")"
|
||||
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
|
||||
done
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||
|
||||
source "$DIR/../_common.sh"
|
||||
|
||||
cd $DIR/../..
|
||||
|
||||
[ -z "$DOTNET_BUILD_CONTAINER_TAG" ] && DOTNET_BUILD_CONTAINER_TAG="dotnetcli-build"
|
||||
[ -z "$DOTNET_BUILD_CONTAINER_NAME" ] && DOTNET_BUILD_CONTAINER_NAME="dotnetcli-build-container"
|
||||
[ -z "$DOCKER_HOST_SHARE_DIR" ] && DOCKER_HOST_SHARE_DIR=$(pwd)
|
||||
|
||||
# Build the docker container (will be fast if it is already built)
|
||||
info "Building docker container"
|
||||
docker build -t $DOTNET_BUILD_CONTAINER_TAG scripts/docker/
|
||||
|
||||
# Remove the sticky bit on directories created by docker so we can delete them
|
||||
info "Cleaning directories created by docker build"
|
||||
docker run --rm \
|
||||
-v $DOCKER_HOST_SHARE_DIR:/opt/code \
|
||||
-e DOTNET_BUILD_VERSION=$DOTNET_BUILD_VERSION \
|
||||
$DOTNET_BUILD_CONTAINER_TAG chmod -R -t /opt/code
|
||||
|
||||
# And Actually make those directories accessible to be deleted
|
||||
docker run --rm \
|
||||
-v $DOCKER_HOST_SHARE_DIR:/opt/code \
|
||||
-e DOTNET_BUILD_VERSION=$DOTNET_BUILD_VERSION \
|
||||
$DOTNET_BUILD_CONTAINER_TAG chmod -R a+rwx /opt/code
|
Loading…
Reference in a new issue