Repository navigation
Expand file tree
/
Copy pathci-builder
More file actions
executable file
·154 lines (135 loc) · 4.53 KB
/
Copy pathci-builder
File metadata and controls
executable file
·154 lines (135 loc) · 4.53 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env bash
# Copyright Materialize, Inc. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.
#
# ci-builder — builds and releases CI builder image.
set -euo pipefail
cd "$(dirname "$0")/.."
if [[ $# -lt 2 ]]
then
echo -n "usage: $0 <build|push|run> <stable|nightly> [<args>...]
Detailed documentation exists in ci/builder/README.md
Subcommands:
run run a command inside the ci-builder relative to the root
of the repo
push build the ci-builder image *and* push it to docker hub
build only build the ci-builder image
"
exit 1
fi
cmd=$1 && shift
channel=$1 && shift
rust_date=
case "$channel" in
stable) rust_version=$(<rust-toolchain) ;;
nightly) rust_version=nightly ;;
nightly-*)
rust_date=/${channel#nightly-}
rust_version=nightly
;;
*)
printf "unknown rust channel %q\n" "$channel"
exit 1
;;
esac
tag_file=ci/builder/${channel%%-*}.stamp
rust_components=rustc,cargo,rust-std-x86_64-unknown-linux-gnu
if [[ $rust_version = nightly ]]; then
rust_components+=,miri-preview
else
rust_components+=,clippy-preview,rustfmt-preview
fi
uid=$(id -u)
gid=$(id -g)
[[ "$uid" -lt 500 ]] && uid=501
[[ "$gid" -lt 500 ]] && gid=$uid
build() {
cp misc/python/requirements{,-dev}.txt ci/builder
docker build --pull \
--build-arg "RUST_VERSION=$rust_version" \
--build-arg "RUST_DATE=$rust_date" \
--build-arg "RUST_COMPONENTS=$rust_components" \
--tag materialize/ci-builder \
"$@" ci/builder
}
tag=$rust_version-$(date +%Y%m%d-%H%M%S)
case "$cmd" in
build)
build --tag materialize/ci-builder:"$tag"
echo "$tag" > "$tag_file"
;;
push)
build --tag materialize/ci-builder:"$tag"
docker push materialize/ci-builder:"$tag"
echo "$tag" > "$tag_file"
;;
run)
args=(
--rm --interactive
--init
--volume "$(pwd):$(pwd)"
--workdir "$(pwd)"
--env AWS_ACCESS_KEY_ID
--env AWS_SECRET_ACCESS_KEY
--env BINTRAY_API_KEY
--env BUILDKITE
--env BUILDKITE_AGENT_ACCESS_TOKEN
--env BUILDKITE_BRANCH
--env BUILDKITE_BUILD_ID
--env BUILDKITE_BUILD_NUMBER
--env BUILDKITE_COMMIT
--env BUILDKITE_JOB_ID
--env BUILDKITE_TAG
--env CI
)
if [[ -t 1 ]]; then
args+=(--tty)
fi
if [[ "$(uname -s)" = Linux ]]; then
# Allow Docker-in-Docker by mounting the Docker socket in the
# container. Host networking allows us to see ports created by
# containers that we launch.
args+=(
--volume "/var/run/docker.sock:/var/run/docker.sock"
--user "$(id -u):$(stat -c %g /var/run/docker.sock)"
--network host
)
# Forward Docker configuration too, if available.
if [[ -d ~/.docker ]]; then
args+=(
--volume "$HOME/.docker:/docker"
--env "DOCKER_CONFIG=/docker"
)
fi
# Forward the host's SSH agent, if available.
if [[ "${SSH_AUTH_SOCK:-}" ]]; then
args+=(
--volume "$SSH_AUTH_SOCK:/tmp/ssh-agent.sock"
--env "SSH_AUTH_SOCK=/tmp/ssh-agent.sock"
)
fi
# Forward the host's buildkite-agent binary, if available.
if command -v buildkite-agent > /dev/null 2>&1; then
args+=(--volume "$(command -v buildkite-agent)":/usr/local/bin/buildkite-agent)
fi
# Install a persistent volume to hold Cargo metadata. We can't
# forward the host's `~/.cargo` directly to the container, since
# that can forward binaries in `~/.cargo/bin` that override the
# version of Cargo installed in the container (!).
args+=(--volume "mz-ci-builder-cargo:/cargo")
else
args+=(--user "$(id -u):1001")
fi
docker run "${args[@]}" "materialize/ci-builder:$(<"$tag_file")" "$@"
;;
*)
printf "unknown command %q\n" "$cmd"
exit 1
;;
esac