#!/bin/bash
set -e
CUR_DIR=$(dirname $(readlink -f $0))
TOP_DIR=$(realpath "${CUR_DIR}"/..)
export GO111MODULE="on"
VER_FILE="${TOP_DIR}"/service_config.ini
build_version="v7.3.0"
if [ -f "$VER_FILE" ]; then
line=$(sed -n '1p' "$VER_FILE" 2>&1)
build_version="v"${line#*=}
fi
arch=$(arch 2>&1)
echo "Build Architecture is" "${arch}"
output_name="container-manager"
script_name="deploy.sh"
os_type=$(arch)
function clean() {
rm -rf "${TOP_DIR}"/output
mkdir -p "${TOP_DIR}"/output
}
function build() {
cd "${TOP_DIR}"
export CGO_ENABLED=1
export CGO_CFLAGS="-fstack-protector-strong -D_FORTIFY_SOURCE=2 -O2 -fPIC -ftrapv"
export CGO_CPPFLAGS="-fstack-protector-strong -D_FORTIFY_SOURCE=2 -O2 -fPIC -ftrapv"
go build -mod=mod -buildmode=pie -ldflags "-X main.BuildName=${output_name} \
-X main.BuildVersion=${build_version}_linux-${os_type} \
-buildid none \
-s \
-extldflags=-Wl,-z,relro,-z,now,-z,noexecstack" \
-o "${output_name}" \
-trimpath
chmod 0500 "${output_name}"
if [ $? -ne 0 ]; then
echo "failed to find component container-manager"
exit 1
fi
}
function mv_file() {
mv "${TOP_DIR}/${output_name}" "${TOP_DIR}"/output
mv "${CUR_DIR}/${script_name}" "${TOP_DIR}"/output && chmod 0500 "${TOP_DIR}"/output/"${script_name}"
}
function main() {
clean
build
mv_file
}
main