Implement script to run build inside a local docker container (#950)
This commit is contained in:
parent
5599a963e4
commit
1c7f4142aa
|
|
@ -0,0 +1,33 @@
|
||||||
|
FROM microsoft/dotnet:2.1-runtime-deps-alpine
|
||||||
|
WORKDIR /code/build
|
||||||
|
|
||||||
|
RUN apk add --no-cache \
|
||||||
|
bash \
|
||||||
|
wget \
|
||||||
|
git \
|
||||||
|
jq \
|
||||||
|
curl \
|
||||||
|
icu-libs \
|
||||||
|
openssl
|
||||||
|
|
||||||
|
# Disable the invariant mode (set in base image)
|
||||||
|
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT false
|
||||||
|
ENV LC_ALL en_US.UTF-8
|
||||||
|
ENV LANG en_US.UTF-8
|
||||||
|
|
||||||
|
# Skip package initilization
|
||||||
|
ENV DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
|
||||||
|
|
||||||
|
# Workarounds https://github.com/dotnet/cli/issues/8738
|
||||||
|
ENV DOTNET_INSTALL_SKIP_PREREQS=1
|
||||||
|
ENV KOREBUILD_SKIP_RUNTIME_INSTALL=1
|
||||||
|
|
||||||
|
COPY global.json /tmp/global.json
|
||||||
|
RUN DOTNET_SDK_VERSION="$(jq -r '.sdk.version' /tmp/global.json)" \
|
||||||
|
&& echo "Installing SDK ${DOTNET_SDK_VERSION}" \
|
||||||
|
&& curl -fsSL -o /tmp/dotnet.tar.gz https://dotnetcli.blob.core.windows.net/dotnet/Sdk/$DOTNET_SDK_VERSION/dotnet-sdk-$DOTNET_SDK_VERSION-alpine.3.6-x64.tar.gz \
|
||||||
|
&& mkdir -p /usr/share/dotnet \
|
||||||
|
&& tar xzf /tmp/dotnet.tar.gz -C /usr/share/dotnet \
|
||||||
|
&& ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet
|
||||||
|
|
||||||
|
ENTRYPOINT [ './build.sh', '/p:IsAlpineSupported=true' ]
|
||||||
|
|
@ -0,0 +1,110 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
#
|
||||||
|
# variables
|
||||||
|
#
|
||||||
|
|
||||||
|
RESET="\033[0m"
|
||||||
|
RED="\033[0;31m"
|
||||||
|
YELLOW="\033[0;33m"
|
||||||
|
MAGENTA="\033[0;95m"
|
||||||
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
build_args=()
|
||||||
|
docker_args=()
|
||||||
|
|
||||||
|
#
|
||||||
|
# Functions
|
||||||
|
#
|
||||||
|
__usage() {
|
||||||
|
echo "Usage: $(basename "${BASH_SOURCE[0]}") <image> [options] [[--] <Arguments>...]"
|
||||||
|
echo ""
|
||||||
|
echo "Arguments:"
|
||||||
|
echo " image The docker image to use."
|
||||||
|
echo " <Arguments>... Arguments passed to the command. Variable number of arguments allowed."
|
||||||
|
echo ""
|
||||||
|
echo "Options:"
|
||||||
|
echo " -v, --volume <VOLUME> An additional volume mount to add to the build container"
|
||||||
|
echo ""
|
||||||
|
echo "Description:"
|
||||||
|
echo " This will run build.sh inside the dockerfile as defined in build/docker/\$image.Dockerfile."
|
||||||
|
|
||||||
|
if [[ "${1:-}" != '--no-exit' ]]; then
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
__error() {
|
||||||
|
echo -e "${RED}error: $*${RESET}" 1>&2
|
||||||
|
}
|
||||||
|
|
||||||
|
__warn() {
|
||||||
|
echo -e "${YELLOW}warning: $*${RESET}"
|
||||||
|
}
|
||||||
|
|
||||||
|
__machine_has() {
|
||||||
|
hash "$1" > /dev/null 2>&1
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# main
|
||||||
|
#
|
||||||
|
|
||||||
|
image="${1:-}"
|
||||||
|
shift || True
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case $1 in
|
||||||
|
-\?|-h|--help)
|
||||||
|
__usage --no-exit
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
-v|--volume)
|
||||||
|
shift
|
||||||
|
volume_spec="${1:-}"
|
||||||
|
[ -z "$volume_spec" ] && __error "Missing value for parameter --volume" && __usage
|
||||||
|
docker_args[${#docker_args[*]}]="--volume"
|
||||||
|
docker_args[${#docker_args[*]}]="$volume_spec"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
build_args[${#build_args[*]}]="$1"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z "$image" ]; then
|
||||||
|
__usage --no-exit
|
||||||
|
__error 'Missing required argument: image'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! __machine_has docker; then
|
||||||
|
__error 'Missing required command: docker'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
dockerfile="$DIR/build/docker/$image.Dockerfile"
|
||||||
|
tagname="universe-build-$image"
|
||||||
|
|
||||||
|
# Workaround for https://github.com/dotnet/cli/issues/8738 and https://github.com/Microsoft/msbuild/issues/3066
|
||||||
|
# Run noop target because we need to generate the global.json file so we can install the matching
|
||||||
|
# .NET Core SDK inside the Docker container.
|
||||||
|
"$DIR/build.sh" /t:Noop
|
||||||
|
cp "$DIR/global.json" "$(dirname "$dockerfile")"
|
||||||
|
#endworkaround
|
||||||
|
|
||||||
|
docker build "$(dirname "$dockerfile")" -f "$dockerfile" --tag $tagname
|
||||||
|
|
||||||
|
docker run \
|
||||||
|
--rm -it \
|
||||||
|
-e CI \
|
||||||
|
-e DOTNET_CLI_TELEMETRY_OPTOUT \
|
||||||
|
-e Configuration \
|
||||||
|
-v "$DIR:/code/build" \
|
||||||
|
${docker_args[@]+"${docker_args[@]}"} \
|
||||||
|
$tagname \
|
||||||
|
${build_args[@]+"${build_args[@]}"}
|
||||||
Loading…
Reference in New Issue