Skip to content

Commit

Permalink
Add binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
labkode committed Jan 16, 2017
1 parent c2eb195 commit 5131e82
Show file tree
Hide file tree
Showing 4 changed files with 707 additions and 2 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ _testmain.go
# cover profiles
out

clawiod.conf
clawiod
*.pem
*.bak
releases
Expand Down
77 changes: 77 additions & 0 deletions cmd/clawiod/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env bash
#
# ClawIO build script. Add build variables to compiled binary.
#
# Usage:
#
# $ ./build.bash [output_filename] [git_repo]
#
# Outputs compiled program in current directory.
# Default file name is 'clawiod'.
# Default git repo is current directory.
# Builds always take place from current directory.

set -euo pipefail

: ${output_filename:="${1:-}"}
: ${output_filename:="clawiod"}

: ${git_repo:="${2:-}"}
: ${git_repo:="."}

pkg=main
ldflags=()

# Timestamp of build
ts_name="${pkg}.buildDate"
ts_value=$(date -u +"%a %b %d %H:%M:%S %Z %Y")
ldflags+=("-X" "\"${ts_name}=${ts_value}\"")

# Current tag, if HEAD is on a tag
# This value is used to determine if the current build is a dev build or a release build
# If this value is empty means we are not on an tag, thus is a dev build
current_tag_name="${pkg}.gitTag"
set +e
current_tag_value="$(git -C "${git_repo}" describe --exact-match HEAD 2>/dev/null)"
set -e
ldflags+=("-X" "\"${current_tag_name}=${current_tag_value}\"")

# Nearest tag on branch
tag_name="${pkg}.gitNearestTag"
tag_value="$(git -C "${git_repo}" describe --abbrev=0 --tags HEAD)"
ldflags+=("-X" "\"${tag_name}=${tag_value}\"")

# Commit SHA
commit_name="${pkg}.gitCommit"
commit_value="$(git -C "${git_repo}" rev-parse --short HEAD)"
ldflags+=("-X" "\"${commit_name}=${commit_value}\"")


releases_dir=${git_repo}/releases
rm -rf ${releases_dir}
mkdir -p ${releases_dir}

os=( "linux" "darwin" "windows" )
arch=( "amd64")

if [[ -z "${current_tag_value}" ]]; then
# dev build
current_date=$(date +"%Y%m%d%H%M%S")
for i in "${os[@]}"; do
for j in "${arch[@]}"; do
GOOS=$i GOARCH=$j go build -ldflags "${ldflags[*]}" -o ${releases_dir}/"${output_filename}"-${tag_value}-$i-$j-${current_date}-${commit_value}
done;
done;
else
# release build
for i in "${os[@]}"; do
for j in "${arch[@]}"; do
artifact_folder=${releases_dir}/"${output_filename}"-${tag_value}-$i-$j
mkdir ${artifact_folder}
GOOS=$i GOARCH=$j go build -ldflags "${ldflags[*]}" -o ${artifact_folder}/"${output_filename}"
cp ../../LICENSE ${artifact_folder}
cp ../../etc/monolithic.conf ${artifact_folder}/clawiod.conf
tar -cvzf "${artifact_folder}".tar.gz "${artifact_folder}"
done;
done;
fi
Loading

0 comments on commit 5131e82

Please sign in to comment.