-
Notifications
You must be signed in to change notification settings - Fork 6
/
build-linux.sh
executable file
·268 lines (240 loc) · 10 KB
/
build-linux.sh
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#!/bin/bash
# Copyright (c) Microsoft Corporation
# SPDX-License-Identifier: MIT
echo ======= Get the directory of the script
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
out_path=$root_path"/out"
echo "Set out_path to: $out_path"
build_target="x86_64-unknown-linux-musl"
echo ======= Set Build Configuration
Configuration=$1
if [ "$Configuration" != "release" ]
then
Configuration="debug"
fi
out_dir=$out_path/$build_target/$Configuration
echo "The out_dir is: $out_dir"
release_flag=""
if [ "$Configuration" = "release" ]
then
release_flag="--release"
fi
CleanBuild=$2
if [ "$CleanBuild" = "clean" ]
then
echo ======= delete old files
echo rm -rf $out_dir
rm -rf $out_dir
fi
echo ======= rustup component add rust-std-x86_64-unknown-linux-musl
rustup component add rust-std-x86_64-unknown-linux-musl
rustup update stable
cargo install cargo-deb
echo ======= cargo fmt & clippy
cargo fmt --all
cargo clippy -- -D warnings
error_code=$?
if [ $error_code -ne 0 ]
then
echo "cargo clippy with exit-code: $error_code"
exit $error_code
fi
echo ======= build proxy_agent_shared
cargo_toml=$root_path/proxy_agent_shared/Cargo.toml
echo cargo_toml=$cargo_toml
echo invoking cargo build $release_flag --manifest-path $cargo_toml --target-dir $out_path --target $build_target
cargo build $release_flag --manifest-path $cargo_toml --target-dir $out_path --target $build_target
error_code=$?
if [ $error_code -ne 0 ]
then
echo "cargo build proxy_agent_shared failed with exit-code: $error_code"
exit $error_code
fi
echo ======= run rust proxy_agent_shared tests
echo invoking cargo test --all-features $release_flag --target $build_target --manifest-path $cargo_toml --target-dir $out_path -- --test-threads=1
cargo test --all-features $release_flag --target $build_target --manifest-path $cargo_toml --target-dir $out_path -- --test-threads=1
error_code=$?
if [ $error_code -ne 0 ]
then
echo "cargo test proxy_agent_shared with exit-code: $error_code"
exit $error_code
fi
echo ======= build ebpf program after the proxy_agent_shared is built to let $out_dir created.
echo ======= build ebpf program for x64_x86 platform
ebpf_path=$root_path/linux-ebpf
echo invoking clang -g -target bpf -Werror -O2 -D__TARGET_ARCH_x86 -c $ebpf_path/ebpf_cgroup.c -o $out_dir/ebpf_cgroup.o
clang -g -target bpf -Werror -O2 -D__TARGET_ARCH_x86 -c $ebpf_path/ebpf_cgroup.c -o $out_dir/ebpf_cgroup.o
error_code=$?
if [ $error_code -ne 0 ]
then
echo "call clang failed with exit-code: $error_code"
exit $error_code
fi
llvm-objdump -h $out_dir/ebpf_cgroup.o
ls -l $out_dir/ebpf_cgroup.o
echo ======= build proxy_agent
cargo_toml=$root_path/proxy_agent/Cargo.toml
echo cargo_toml=$cargo_toml
echo invoking cargo build $release_flag --manifest-path $cargo_toml --target-dir $out_path --target $build_target
cargo build $release_flag --manifest-path $cargo_toml --target-dir $out_path --target $build_target
error_code=$?
if [ $error_code -ne 0 ]
then
echo "cargo build proxy_agent failed with exit-code: $error_code"
exit $error_code
fi
echo ======= copy config file for Linux platform
cp -f -T $root_path/proxy_agent/config/GuestProxyAgent.linux.json $out_dir/proxy-agent.json
echo ======= copy files for run/debug proxy_agent Unit test
echo cp -f $out_dir/* $out_dir/deps/
cp -f $out_dir/* $out_dir/deps/
echo cp -f -r $out_dir/* $root_path/proxy_agent/target/$Configuration/
cp -f -r $out_dir/* $root_path/proxy_agent/target/$Configuration/
echo ======= run rust proxy_agent tests
echo invoking cargo test --all-features $release_flag --target $build_target --manifest-path $cargo_toml --target-dir $out_path -- --test-threads=1
cargo test --all-features $release_flag --target $build_target --manifest-path $cargo_toml --target-dir $out_path -- --test-threads=1
error_code=$?
if [ $error_code -ne 0 ]
then
echo "cargo test proxy_agent with exit-code: $error_code"
exit $error_code
fi
echo ======= build proxy_agent_extension
cargo_toml=$root_path/proxy_agent_extension/Cargo.toml
extension_src_path=$root_path/proxy_agent_extension/src/linux
echo cargo_toml=$cargo_toml
echo invoking cargo build $release_flag --manifest-path $cargo_toml --target-dir $out_path --target $build_target
cargo build $release_flag --manifest-path $cargo_toml --target-dir $out_path --target $build_target
error_code=$?
if [ $error_code -ne 0 ]
then
echo "cargo build proxy_agent_extension failed with exit-code: $error_code"
exit $error_code
fi
echo ======= copy files for run/debug proxy_agent_extension Unit test
echo cp -f $out_dir/* $out_dir/deps/
cp -f $out_dir/* $out_dir/deps/
echo cp -f -r $out_dir/* $root_path/proxy_agent_extension/target/$Configuration/
cp -f -r $out_dir/* $root_path/proxy_agent_extension/target/$Configuration/
echo ======= run rust proxy_agent_extension tests
echo invoking cargo test --all-features $release_flag --target $build_target --manifest-path $cargo_toml --target-dir $out_path -- --test-threads=1
cargo test --all-features $release_flag --target $build_target --manifest-path $cargo_toml --target-dir $out_path -- --test-threads=1
error_code=$?
if [ $error_code -ne 0 ]
then
echo "cargo test proxy_agent_extension with exit-code: $error_code"
exit $error_code
fi
echo ======= copy config file for Linux platform
cp -f -r $root_path/proxy_agent_setup/src/linux/* $out_dir/
echo ======= build proxy_agent_setup
cargo_toml=$root_path/proxy_agent_setup/Cargo.toml
echo cargo_toml=$cargo_toml
echo invoking cargo build $release_flag --manifest-path $cargo_toml --target-dir $out_path --target $build_target
cargo build $release_flag --manifest-path $cargo_toml --target-dir $out_path --target $build_target
error_code=$?
if [ $error_code -ne 0 ]
then
echo "cargo build proxy_agent_setup failed with exit-code: $error_code"
exit $error_code
fi
echo ======= copy files for run/debug proxy_agent_setup Unit test
echo cp -f $out_dir/* $out_dir/deps/
cp -f $out_dir/* $out_dir/deps/
echo cp -f -r $out_dir/* $root_path/proxy_agent_setup/target/$Configuration/
cp -f -r $out_dir/* $root_path/proxy_agent_setup/target/$Configuration/
echo ======= build e2e test solution
echo dotnet build $root_path/e2etest/GuestProxyAgentTest.sln --configuration $Configuration -o $out_dir/e2etest
dotnet build $root_path/e2etest/GuestProxyAgentTest.sln --configuration $Configuration -o $out_dir/e2etest
error_code=$?
if [ $error_code -ne 0 ]
then
echo "dotnet build failed with exit-code: $error_code"
exit $error_code
fi
echo ======= prepare out-package folder structure
out_package_dir=$out_dir/package
if [ ! -d $out_package_dir ]; then
mkdir $out_package_dir
fi
echo ======= copy to package folder
cp -f $out_dir/proxy_agent_setup $out_package_dir/
cp -f $out_dir/azure-proxy-agent.service $out_package_dir/
out_package_proxyagent_dir=$out_package_dir/ProxyAgent
if [ ! -d $out_package_proxyagent_dir ]; then
mkdir $out_package_proxyagent_dir
fi
echo ======= copy to proxyagent folder
cp -f $out_dir/azure-proxy-agent $out_package_proxyagent_dir/
cp -f $out_dir/proxy-agent.json $out_package_proxyagent_dir/
cp -f $out_dir/ebpf_cgroup.o $out_package_proxyagent_dir/
echo ======= generate rpm package
echo "Generating rpm package -------------- "
pkgversion=$($out_dir/azure-proxy-agent --version)
echo "Package version: '$pkgversion'"
rootdir=$(pwd)
rm -rf build
mkdir build
pushd build
mkdir azure-proxy-agent
pushd azure-proxy-agent
cp -rf $out_package_dir/ ./
popd
mv azure-proxy-agent azure-proxy-agent_${pkgversion}
tar -czf azure-proxy-agent_${pkgversion}.tar.gz azure-proxy-agent_${pkgversion}
popd
pushd rpmbuild
mkdir SOURCES BUILD RPMS SRPMS
cp ../build/azure-proxy-agent_${pkgversion}.tar.gz SOURCES/
rpmbuild --define "_topdir ${rootdir}/rpmbuild" --define "pkgversion ${pkgversion}" -ba SPECS/azure-proxy-agent.spec
error_code=$?
if [ $error_code -ne 0 ]
then
echo "rpmbuild failed with exit-code: $error_code"
exit $error_code
fi
popd
rm -rf build
echo ======= copy rpm package file to Package folder
cp -f $rootdir/rpmbuild/RPMS/x86_64/azure-proxy-agent-${pkgversion}-0.x86_64.rpm $out_package_dir/
echo ======= generate deb package
echo "Generating deb package -------------- "
rm -rf debbuild
mkdir debbuild
pushd debbuild
mkdir -p DEBIAN src
cp -rf $rootdir/debian/* ./DEBIAN/
cp -rf $rootdir/proxy_agent/Cargo.toml ./Cargo.toml
cp -rf $rootdir/proxy_agent/src/* ./src/ # cargo deb --no-build command still requires ./src/main.rs
cp -f $out_package_proxyagent_dir/azure-proxy-agent ./
cp -f $out_package_proxyagent_dir/proxy-agent.json ./
cp -f $out_package_proxyagent_dir/ebpf_cgroup.o ./
cp -f $out_package_dir/azure-proxy-agent.service ./DEBIAN/
sed -i "s/pkgversion/${pkgversion}/g" DEBIAN/control # replace pkgversion with actual version
sed -i "s/pkgversion/${pkgversion}/g" DEBIAN/postinst # replace pkgversion with actual version
sed -i "s/pkgversion/${pkgversion}/g" Cargo.toml # replace pkgversion with actual version
echo cargo deb -v --manifest-path $rootdir/debbuild/Cargo.toml --no-build -o $out_package_dir --target $build_target
cargo deb -v --manifest-path $rootdir/debbuild/Cargo.toml --no-build -o $out_package_dir --target $build_target
error_code=$?
if [ $error_code -ne 0 ]
then
echo "cargo deb: failed with exit-code: $error_code"
exit $error_code
fi
popd
rm -rf debbuild
echo ======= copy to proxyagent extension folder
out_package_proxyagent_extension_dir=$out_package_dir/ProxyAgent_Extension
if [ ! -d $out_package_proxyagent_extension_dir ]; then
mkdir $out_package_proxyagent_extension_dir
fi
cp -f $extension_src_path/HandlerManifest.json $out_package_proxyagent_extension_dir/
for f in $extension_src_path/*.sh; do
cp -f $f $out_package_proxyagent_extension_dir/
done
cp -f $out_dir/ProxyAgentExt $out_package_proxyagent_extension_dir/
echo ======= copy e2e test project to Package folder
cp -rf $out_dir/e2etest/ $out_package_dir/e2etest/
echo ======= Generate build-configuration-linux-amd64.zip file with relative path within the zip file
cd $out_package_dir
zip -r $out_dir/build-$Configuration-linux-amd64.zip .