-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Benjamin Wang <wachao@vmware.com>
- Loading branch information
Showing
6 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.idea | ||
etcd-defrag | ||
/bin | ||
/release | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
GIT_SHA=$(git rev-parse --short HEAD || echo "GitNotFound") | ||
VERSION_SHA="main.GitSHA" | ||
|
||
# use go env if noset | ||
GOOS=${GOOS:-$(go env GOOS)} | ||
GOARCH=${GOARCH:-$(go env GOARCH)} | ||
|
||
GO_BUILD_FLAGS=${GO_BUILD_FLAGS:-} | ||
|
||
GO_LDFLAGS=(${GO_LDFLAGS:-} "-X=${VERSION_SHA}=${GIT_SHA}") | ||
GO_BUILD_ENV=("CGO_ENABLED=0" "GO_BUILD_FLAGS=${GO_BUILD_FLAGS}" "GOOS=${GOOS}" "GOARCH=${GOARCH}") | ||
|
||
rm -f ./bin/etcd-defrag | ||
|
||
env "${GO_BUILD_ENV[@]}" go build $GO_BUILD_FLAGS -trimpath -installsuffix=cgo "-ldflags=${GO_LDFLAGS[*]}" -o ./bin/etcd-defrag | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
VER=${1:-} | ||
REPOSITORY="${REPOSITORY:-https://github.com/ahrtr/etcd-defrag.git}" | ||
|
||
if [ -z "$VER" ]; then | ||
echo "Usage: ${0} VERSION" >> /dev/stderr | ||
exit 255 | ||
fi | ||
|
||
function setup_env { | ||
local ver=${1} | ||
local proj=${2} | ||
|
||
if [ ! -d "${proj}" ]; then | ||
git clone "${REPOSITORY}" | ||
fi | ||
|
||
pushd "${proj}" >/dev/null | ||
git fetch --all | ||
git checkout "${ver}" | ||
popd >/dev/null | ||
} | ||
|
||
function package { | ||
local target=${1} | ||
local srcdir="${2}/bin" | ||
|
||
local ccdir="${srcdir}/${GOOS}_${GOARCH}" | ||
if [ -d "${ccdir}" ]; then | ||
srcdir="${ccdir}" | ||
fi | ||
local ext="" | ||
if [ "${GOOS}" == "windows" ]; then | ||
ext=".exe" | ||
fi | ||
cp "${srcdir}/etcd-defrag" "${target}/etcd-defrag${ext}" | ||
|
||
cp etcd/README.md "${target}"/README.md | ||
} | ||
|
||
function main { | ||
local proj="etcd-defrag" | ||
|
||
mkdir -p release | ||
cd release | ||
setup_env "${VER}" "${proj}" | ||
|
||
local tarcmd=tar | ||
|
||
for os in darwin windows linux; do | ||
export GOOS=${os} | ||
TARGET_ARCHS=("amd64") | ||
|
||
if [ ${GOOS} == "linux" ]; then | ||
TARGET_ARCHS+=("arm64") | ||
TARGET_ARCHS+=("ppc64le") | ||
TARGET_ARCHS+=("s390x") | ||
fi | ||
|
||
if [ ${GOOS} == "darwin" ]; then | ||
TARGET_ARCHS+=("arm64") | ||
fi | ||
|
||
for TARGET_ARCH in "${TARGET_ARCHS[@]}"; do | ||
export GOARCH=${TARGET_ARCH} | ||
|
||
pushd ${proj} >/dev/null | ||
GO_LDFLAGS="-s -w" ./build.sh | ||
popd >/dev/null | ||
|
||
TARGET="${proj}-${VER}-${GOOS}-${GOARCH}" | ||
mkdir "${TARGET}" | ||
package "${TARGET}" "${proj}" | ||
|
||
if [ ${GOOS} == "linux" ]; then | ||
${tarcmd} cfz "${TARGET}.tar.gz" "${TARGET}" | ||
echo "Wrote release/${TARGET}.tar.gz" | ||
else | ||
zip -qr "${TARGET}.zip" "${TARGET}" | ||
echo "Wrote release/${TARGET}.zip" | ||
fi | ||
done | ||
done | ||
} | ||
|
||
main | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
var ( | ||
Version = "0.1.0" | ||
// GitSHA is the commit SHA value set during build | ||
GitSHA = "Not provided (use ./build.sh)" | ||
) |