-
Notifications
You must be signed in to change notification settings - Fork 17
/
package-build.sh
executable file
·68 lines (55 loc) · 2.49 KB
/
package-build.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
#!/usr/bin/env bash
##
# Adapted from sensu/sensu-go-bonsai-asset repo
##
set -e
# Hardwiring repo-name for now, untile the Dockerfile logic is abstracted/tested to use name as passed to docker as build arg
REPO_NAME="monitoring-plugins"
export PLUGINS="check_disk,check_dns,check_http,check_load,check_log,check_ntp,check_ntp_peer,check_ntp_time,check_ping,check_procs,check_smtp,check_snmp,check_ssh,check_swap,check_tcp,check_time,check_users,utils.sh"
[[ -z "$WDIR" ]] && { echo "WDIR is empty using bonsai/" ; WDIR="bonsai/"; }
##
# TravisCI specific asset build script.
# Uses several TravisCI specific environment variables
##
#[[ -z "$1" ]] && { echo "Parameter 1, REPO_NAME is empty" ; exit 1; }
[[ -z "$GITHUB_TOKEN" ]] && { echo "GITHUB_TOKEN is empty, upload disabled" ; }
[[ -z "$TRAVIS_REPO_SLUG" ]] && { echo "TRAVIS_REPO_SLUG is empty"; exit 1; }
if [[ -z "$1" ]]; then
echo "Parameter 1, PLATFORMS is empty, using default set" ; platforms=( alpine amazon2 amazon2023 debian10 debian11 centos7 centos8 rocky9 ubuntu1804 ubuntu2004 ubuntu2204 raspberrypi64 );
else
IFS=', ' read -r -a platforms <<< "$1"
fi
TAG=$TRAVIS_TAG
CURRENT_COMMIT=$(git rev-parse HEAD)
[[ -z "$TAG" ]] && { echo "TRAVIS_TAG is empty" ; TAG="0.0.1"; }
[[ -z "$TRAVIS_COMMIT" ]] && { echo "TRAVIS_COMMIT is empty, using current commit" ; TRAVIS_COMMIT=$CURRENT_COMMIT; }
echo $REPO_NAME $TRAVIS_REPO_SLUG $TAG $TRAVIS_COMMIT
mkdir dist
GIT_REPO="https://github.com/${TRAVIS_REPO_SLUG}.git"
GIT_REF=${TRAVIS_COMMIT}
echo "Platforms: ${platforms[@]}"
if [ -d dist ]; then
for platform in "${platforms[@]}"
do
if [ -f "Dockerfile.${platform}" ]; then
if [[ ${platform} == "raspberrypi64" ]]; then
export ARCH="arm64"
else
export ARCH="amd64"
fi;
export SENSU_GO_ASSET_FILENAME="${REPO_NAME}-${platform}_${TAG}_linux_${ARCH}.tar.gz"
echo "Building for Platform: $platform using Dockfile.${platform} ${SENSU_GO_ASSET_FILENAME}"
docker build --no-cache --rm --build-arg "PLUGINS=$PLUGINS" --build-arg "SENSU_GO_ASSET_VERSION=${TAG}" -t ${REPO_NAME}-${platform}:$TAG -f Dockerfile.${platform} .
docker cp -L $(docker create --rm ${REPO_NAME}-${platform}:${TAG} true):/$SENSU_GO_ASSET_FILENAME ./dist/
if [ -z ${FULL_PRUNE+x} ]; then
echo "FULL_PRUNE unset, skipping docker prune"
else
docker system prune -a -f
fi
else
echo "Skipping for Platform: $platform missing Dockfile.${platform}"
fi
done
else
echo "error dist directory is missing"
fi