forked from DataDog/datadog-agent
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlocal.sh
More file actions
executable file
·247 lines (191 loc) · 7.72 KB
/
local.sh
File metadata and controls
executable file
·247 lines (191 loc) · 7.72 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/bin/bash
set -e
# We want to produce a final binary on a branded path, but it is convenient to run unit tests and the like on
# the original unbranded paths. Hence we allow for both.
if [[ "${BRANDED}" = "false" ]]; then
SRC_PATH="/go/src/github.com/DataDog/datadog-agent"
export AGENT_GITHUB_ORG=DataDog
export AGENT_REPO_NAME=datadog-agent
else
SRC_PATH="/go/src/github.com/StackVista/stackstate-agent"
export AGENT_GITHUB_ORG=StackVista
export AGENT_REPO_NAME=stackstate-agent
fi
export PYTHON_RUNTIMES="3"
WHAT=$1
if [ -z "${WHAT}" ]; then
echo "Usage: $0 [shell | all | prep | deps_deb | build_binaries | build_cluster_agent | build_deb | copy_rtloader]"
exit 1
fi
WHAT=$(echo "${WHAT}" | tr '[:lower:]' '[:upper:]')
if [ "${WHAT}" = "SHELL" ]; then
docker run --rm -it -v ${PWD}:${PWD} \
-e MAJOR_VERSION="3" \
-e USER_ID="$(id -u)" -e GROUP_ID="$(id -g)" \
-e CI_PROJECT_DIR=${PWD} \
-e artifactory_user="${artifactory_user}" \
-e artifactory_password="${artifactory_password}" \
-e GITLAB_PACKAGE_REGISTRY_PYPI_SIMPLE_URL="${GITLAB_PACKAGE_REGISTRY_PYPI_SIMPLE_URL}" \
--workdir=${PWD} \
registry.tooling.stackstate.io/quay/stackstate/datadog_build_deb_x64:0d87e00f bash
fi
# Prepare a copy of the agent in the SRC_DIR to make sure that in a containerized environment the source directory
# does not get tainted, and all files have the proper user for within the container.
function prepare() {
. /usr/local/rvm/scripts/rvm
if ! type "rsync" > /dev/null; then
apt install rsync -y --no-install-recommends
fi
mkdir -p $SRC_PATH
echo "Syncing files to $SRC_PATH"
rsync -au "$CI_PROJECT_DIR"/. $SRC_PATH
chown -R root:root $SRC_PATH
rm -rf "$SRC_PATH/rtloader/build" || true
cd "$SRC_PATH" || exit
if [[ "${BRANDED}" != "false" ]]; then
echo "Fixing import paths"
./fix_package_paths.sh "$SRC_PATH"
echo "Running tidy after rewriting paths"
# TODO: Ideally we'd not need to run this, but because we update the package paths, we need to update go.mod/sum/vendor
# Alternative is to commit package renames, but that is also pretty messy
go mod tidy
# Vendor so we also rewrite dependencies
go mod vendor
fi
cd "$CI_PROJECT_DIR" || exit
}
if [ "${WHAT}" = "ALL" ]; then
prepare
fi
if [ "${WHAT}" = "ALL" ] || [ "${WHAT}" = "DEPS_DEB" ]; then
if [ "${WHAT}" = "DEPS_DEB" ]; then
prepare
fi
cd $SRC_PATH || exit
echo "Running debian dependencies in $SRC_PATH"
# shellcheck disable=SC2164
go clean -modcache
echo " --- ---"
echo " --- Getting dependencies ---"
echo " --- ---"
inv -e deps --verbose
go mod tidy
inv agent.version --major-version 3 -u > version.txt
echo " --- ---"
echo " --- Agent Version String ---"
echo " --- ---"
cat version.txt
cd "$CI_PROJECT_DIR" || exit
fi
if [ "${WHAT}" = "ALL" ] || [ "${WHAT}" = "BUILD_AGENT" ]; then
if [ "${WHAT}" = "BUILD_AGENT" ]; then
prepare
fi
cd $SRC_PATH || exit
echo " --- ---"
echo " --- Building agent ---"
echo " --- ---"
echo " ******** --- Building dogstatsd ---"
inv -e dogstatsd.build --static --major-version 3
echo " ******** --- Building rtloader ---"
inv -e rtloader.make
echo " ******** --- Installing rtloader ---"
inv -e rtloader.install
echo " ******** --- Building agent ---"
# shellcheck disable=SC2164
inv -e agent.build --major-version "3" --python-runtimes "3"
cd "$CI_PROJECT_DIR" || exit
fi
if [ "${WHAT}" = "ALL" ] || [ "${WHAT}" = "BUILD_CLUSTER_AGENT" ]; then
if [ "${WHAT}" = "BUILD_CLUSTER_AGENT" ]; then
prepare
fi
cd $SRC_PATH || exit
echo " --- ---"
echo " --- Building cluster agent ---"
echo " --- ---"
inv -e cluster-agent.build
cd "$CI_PROJECT_DIR" || exit
fi
if [ "${WHAT}" = "ALL" ] || [ "${WHAT}" = "BUILD_DEB" ]; then
if [ "${WHAT}" = "BUILD_DEB" ]; then
prepare
fi
cd $SRC_PATH || exit
echo " --- ---"
echo " --- Building deb package ---"
echo " --- ---"
mv "$SRC_PATH"/.omnibus /omnibus || mkdir -p /omnibus
inv agent.version --major-version 3
cat version.txt || true
source ./.gitlab-scripts/setup_artifactory.sh
export OMNIBUS_BASE_DIR="/.omnibus"
inv -e agent.omnibus-build --gem-path $SRC_PATH/.gems --base-dir $OMNIBUS_BASE_DIR --go-mod-cache $SRC_PATH/vendor --skip-deps --skip-sign --major-version 3 --python-runtimes 3
# Prepare outputs
mkdir -p $SRC_PATH/outcomes/pkg && mkdir -p $SRC_PATH/outcomes/dockerfiles && mkdir -p $SRC_PATH/outcomes/binary
cp -r $OMNIBUS_BASE_DIR/pkg $SRC_PATH/outcomes
cp -r $SRC_PATH/Dockerfiles $SRC_PATH/outcomes
# - cp -r /opt/stackstate-agent/embedded/bin/trace-agent $SRC_PATH/outcomes/binary/
ls -la $SRC_PATH/outcomes/Dockerfiles
# Prepare cache
# Drop packages for cache
rm -rf /omnibus/pkg
# Drop agent for cache (will be resynced anyway)
rm -rf /omnibus/src/datadog-agent
# Drop symlink because it will fail the build when coming from a cache
rm /omnibus/src/datadog-agent/src/github.com/StackVista/stackstate-agent/vendor/github.com/coreos/etcd/cmd/etcd || echo "Not found"
mv /omnibus $SRC_PATH/.omnibus
cd "$CI_PROJECT_DIR" || exit
fi
if [ "${WHAT}" = "ALL" ] || [ "${WHAT}" = "UNIT_TESTS" ]; then
if [ "${WHAT}" = "UNIT_TESTS" ]; then
prepare
fi
cd $SRC_PATH || exit
echo " --- ---"
echo " --- Running Unit Tests ---"
echo " --- ---"
inv -e agent.build --race --major-version $MAJOR_VERSION --python-runtimes $PYTHON_RUNTIMES
# TODO: check why formatting rules differ from previous step
# - gofmt -l -w -s ./pkg ./cmd
inv -e rtloader.test
invoke install-tools
echo "inv -e test --coverage --race --profile --cpus 4 --major-version $MAJOR_VERSION --python-runtimes $PYTHON_RUNTIMES"
inv -e test --coverage --race --profile --cpus 4 --major-version $MAJOR_VERSION --python-runtimes $PYTHON_RUNTIMES
cd "$CI_PROJECT_DIR" || exit
fi
if [ "${WHAT}" = "ALL" ] || [ "${WHAT}" = "COPY_RTLOADER" ]; then
if [ "${WHAT}" = "COPY_RTLOADER" ]; then
prepare
fi
rm -rf "$CI_PROJECT_DIR/rtloader/build" || true
rm -rf "$SRC_PATH/rtloader/build" || true
cd $SRC_PATH || exit
echo " --- ---"
echo " --- Copying Rtloader to source ---"
echo " --- ---"
inv -e rtloader.make
cp -a "$SRC_PATH"/rtloader/build "$CI_PROJECT_DIR"/rtloader/
chown "$USER_ID":"$GROUP_ID" -R "$CI_PROJECT_DIR"/rtloader/build
cd "$CI_PROJECT_DIR" || exit
fi
if [ "${WHAT}" = "ALL" ] || [ "${WHAT}" = "LINT" ]; then
if [ "${WHAT}" = "LINT" ]; then
prepare
fi
cd $SRC_PATH || exit
echo " --- ---"
echo " --- Running Lint ---"
echo " --- ---"
inv -e lint-go
cd "$CI_PROJECT_DIR" || exit
fi
if [ "${WHAT}" = "CMD" ]; then
prepare
cd $SRC_PATH || exit
echo " --- ---"
echo " --- Running command `$2`"
echo " --- ---"
$2
cd "$CI_PROJECT_DIR" || exit
fi