-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·128 lines (108 loc) · 4.15 KB
/
build.sh
File metadata and controls
executable file
·128 lines (108 loc) · 4.15 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
#!/bin/bash
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Build script that will get the module dependencies and build Linux and
# Windows binaries. The google_cloud_workload_agent binary will be built into
# the buildoutput/ dir.
#
#
# Use the following command to build the workload agent if there are outstanding protocol
# buffer changes in the protos directory:
#
# ./build.sh -c
#
set -exu
POSITIONAL_ARGS=()
COMPILE_PROTOS="FALSE"
while [[ $# -gt 0 ]]; do
case $1 in
-c|--compileprotos)
COMPILE_PROTOS="TRUE"
shift # past argument
;;
-*|--*)
echo "Unknown option $1"
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done
echo "Starting the build process for the Workload Agent..."
if [ "${COMPILE_PROTOS}" == "TRUE" ] && [ ! -d "workloadagentplatform" ]; then
echo "************** Adding the workloadagent submodule"
git submodule add https://github.com/GoogleCloudPlatform/workloadagentplatform
cd workloadagentplatform
# this is the hash of the workloadagentplatform submodule
# get the hash by running: go list -m -json github.com/GoogleCloudPlatform/workloadagentplatform@main
git checkout 4729a3b634b78f061c18e095585832c92701049b
cd ..
# replace the proto imports in the platform that reference the platform
find workloadagentplatform/sharedprotos -type f -exec sed -i 's|"sharedprotos|"workloadagentplatform/sharedprotos|g' {} +
fi
echo "************** Getting go 1.24.2"
curl -sLOS https://go.dev/dl/go1.24.2.linux-amd64.tar.gz
chmod -fR u+rwx /tmp/workloadagent || :
rm -fr /tmp/workloadagent
mkdir -p /tmp/workloadagent
tar -C /tmp/workloadagent -xzf go1.24.2.linux-amd64.tar.gz
export GOROOT=/tmp/workloadagent/go
export GOPATH=/tmp/workloadagent/gopath
mkdir -p "${GOPATH}"
mkdir -p $GOROOT/.cache
mkdir -p $GOROOT/pkg/mod
export GOMODCACHE=$GOROOT/pkg/mod
export GOCACHE=$GOROOT/.cache
export GOBIN=$GOROOT/bin
PATH=${GOBIN}:${GOROOT}/packages/bin:$PATH
if [ "${COMPILE_PROTOS}" == "TRUE" ]; then
echo "************** Getting unzip 5.51"
curl -sLOS https://oss.oracle.com/el4/unzip/unzip.tar
tar -C /tmp/workloadagent -xf unzip.tar
echo "************** Getting protoc 28.2"
pb_rel="https://github.com/protocolbuffers/protobuf/releases"
pb_dest="/tmp/workloadagent/protobuf"
curl -sLOS ${pb_rel}/download/v28.2/protoc-28.2-linux-x86_64.zip
rm -fr "${pb_dest}"
mkdir -p "${pb_dest}"
/tmp/workloadagent/unzip -q protoc-28.2-linux-x86_64.zip -d "${pb_dest}"
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
echo "************** Compiling protobufs"
protoc --go_opt=paths=source_relative protos/**/*.proto workloadagentplatform/sharedprotos/**/*.proto --go_out=.
fi
mkdir -p buildoutput
echo "************** Generating the latest go.mod and go.sum dependencies"
cp go.mod go.mod.orig
cp go.sum go.sum.orig
go clean -modcache
go mod tidy
mv go.mod buildoutput/go.mod.latest
mv go.sum buildoutput/go.sum.latest
mv go.mod.orig go.mod
mv go.sum.orig go.sum
echo "************** Getting the repo module dependencies using go mod vendor"
go clean -modcache
go mod vendor
echo "************** Running all tests"
go test ./...
pushd cmd
echo "************** Building Linux binary"
env GOOS=linux GOARCH=amd64 go build -mod=vendor -v -o ../buildoutput/google_cloud_workload_agent
echo "************** Building Windows binary"
env GOOS=windows GOARCH=amd64 go build -mod=vendor -v -o ../buildoutput/google_cloud_workload_agent.exe
popd
echo "************** Finished building the Workload Agent, the binaries and latest go.mod/go.sum are available in the buildoutput directory"