Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dockerbuild.sh - github.com/dotnet/aspnetcore.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6ba130fa449418ca6f2ce0b6a4b1e44a35f93968 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/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="aspnetcore-build-$image"

# Use a location for .dotnet/ that's not under repo root in the container and don't reuse host's folder.
mkdir "$(dirname $DIR)/.dotnet-$image"

docker build "$(dirname "$dockerfile")" \
    --build-arg "USER=$(whoami)" \
    --build-arg "USER_ID=$(id -u)" \
    --build-arg "GROUP_ID=$(id -g)" \
    --tag $tagname \
    -f "$dockerfile"

docker run \
    --rm \
    -t \
    -e CI \
    -e TEAMCITY_VERSION \
    -e DOTNET_CLI_TELEMETRY_OPTOUT \
    -e Configuration \
    -e PB_RESTORESOURCE \
    -e PB_PUBLISHBLOBFEEDURL \
    -e PB_PUBLISHTYPE \
    -e PB_SKIPTESTS \
    -e PB_ISFINALBUILD \
    -e PB_ACCESSTOKENSUFFIX \
    -e PB_PACKAGEVERSIONPROPSURL\
    -e PB_ASSETROOTURL \
    -e PRODUCTBUILDID \
    -v "$DIR:/code/build" \
    -v "$(dirname $DIR)/.dotnet-$image:/code/.dotnet" \
    ${docker_args[@]+"${docker_args[@]}"} \
    $tagname \
    ./build.sh \
    ${build_args[@]+"${build_args[@]}"} \
    "-p:HostMachineRepositoryRoot=$DIR"