initial work towards automated builds and CI
This commit is contained in:
parent
90a38b05c2
commit
02c9b97388
16
script/bootstrap
Executable file
16
script/bootstrap
Executable file
@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Make sure we have the version of Go we want to depend on, either from the
|
||||
# system or one we grab ourselves.
|
||||
. script/ensure-go-installed
|
||||
|
||||
# Since we want to be able to build this outside of GOPATH, we set it
|
||||
# up so it points back to us and go is none the wiser
|
||||
|
||||
set -x
|
||||
rm -rf .gopath
|
||||
mkdir -p .gopath/src/github.com/github
|
||||
ln -s "$PWD" .gopath/src/github.com/github/gh-ost
|
||||
export GOPATH=$PWD/.gopath:$GOPATH
|
21
script/build
Executable file
21
script/build
Executable file
@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
. script/bootstrap
|
||||
|
||||
mkdir -p bin
|
||||
bindir="$PWD"/bin
|
||||
libexecdir="$PWD"/libexec
|
||||
scriptdir="$PWD"/script
|
||||
|
||||
# We have a few binaries that we want to build, so let's put them into bin/
|
||||
|
||||
version=$(git rev-parse HEAD)
|
||||
describe=$(git describe --tags --always --dirty)
|
||||
|
||||
export GOPATH="$PWD/.gopath"
|
||||
cd .gopath/src/github.com/github/gh-ost
|
||||
|
||||
# We put the binaries into libexec/ and then put the shim with the appropriate name into bin/
|
||||
go build -o "$libexecdir/gh-ost" -ldflags "-X main.AppVersion=${version} -X main.BuildDescribe=${describe}" ./go/cmd/gh-ost/main.go
|
12
script/cibuild
Executable file
12
script/cibuild
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
. script/bootstrap
|
||||
|
||||
script/build
|
||||
|
||||
export GITBACKUPS_ENV=test
|
||||
|
||||
cd .gopath/src/github.com/github/gh-ost
|
||||
go test ./go/...
|
29
script/cibuild-gh-ost-build-deploy-tarball
Executable file
29
script/cibuild-gh-ost-build-deploy-tarball
Executable file
@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
script/cibuild
|
||||
|
||||
# Get a fresh directory and make sure to delete it afterwards
|
||||
build_dir=tmp/build
|
||||
rm -rf $build_dir
|
||||
mkdir -p $build_dir
|
||||
trap "rm -rf $build_dir" EXIT
|
||||
|
||||
commit_sha=$(git rev-parse HEAD)
|
||||
|
||||
if [ $(uname -s) = "Darwin" ]; then
|
||||
build_arch="$(uname -sr | tr -d ' ' | tr '[:upper:]' '[:lower:]')-$(uname -m)"
|
||||
else
|
||||
build_arch="$(lsb_release -sc | tr -d ' ' | tr '[:upper:]' '[:lower:]')-$(uname -m)"
|
||||
fi
|
||||
|
||||
tarball=$build_dir/${commit_sha}-${build_arch}.tar
|
||||
|
||||
# Create the tarball
|
||||
tar cvf $tarball --mode="ugo=rx" libexec/ bin/
|
||||
|
||||
# Compress it and copy it to the directory for the CI to upload it
|
||||
gzip $tarball
|
||||
mkdir -p "$BUILD_ARTIFACT_DIR"/gh-ost
|
||||
cp ${tarball}.gz "$BUILD_ARTIFACT_DIR"/gh-ost/
|
51
script/ensure-go-installed
Executable file
51
script/ensure-go-installed
Executable file
@ -0,0 +1,51 @@
|
||||
#!/bin/bash
|
||||
|
||||
GO_VERSION=go1.7
|
||||
|
||||
GO_PKG_DARWIN=${GO_VERSION}.darwin-amd64.pkg
|
||||
GO_PKG_DARWIN_SHA=e7089843bc7148ffcc147759985b213604d22bb9fd19bd930b515aa981bf1b22
|
||||
|
||||
GO_PKG_LINUX=${GO_VERSION}.linux-amd64.tar.gz
|
||||
GO_PKG_LINUX_SHA=702ad90f705365227e902b42d91dd1a40e48ca7f67a2f4b2fd052aaa4295cd95
|
||||
|
||||
export ROOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
|
||||
cd $ROOTDIR
|
||||
|
||||
# If Go isn't installed globally, setup environment variables for local install.
|
||||
if [ -z "$(which go)" ] || [ -z "$(go version | grep $GO_VERSION)" ]; then
|
||||
GODIR="$ROOTDIR/.vendor/go17"
|
||||
|
||||
if [ $(uname -s) = "Darwin" ]; then
|
||||
export GOROOT="$GODIR/usr/local/go"
|
||||
else
|
||||
export GOROOT="$GODIR/go"
|
||||
fi
|
||||
|
||||
export PATH="$GOROOT/bin:$PATH"
|
||||
fi
|
||||
|
||||
# Check if local install exists, and install otherwise.
|
||||
if [ -z "$(which go)" ] || [ -z "$(go version | grep $GO_VERSION)" ]; then
|
||||
[ -d "$GODIR" ] && rm -rf $GODIR
|
||||
mkdir -p "$GODIR"
|
||||
cd "$GODIR";
|
||||
|
||||
if [ $(uname -s) = "Darwin" ]; then
|
||||
curl -L -O https://storage.googleapis.com/golang/$GO_PKG_DARWIN
|
||||
shasum -a256 $GO_PKG_DARWIN | grep $GO_PKG_DARWIN_SHA
|
||||
xar -xf $GO_PKG_DARWIN
|
||||
cpio -i < com.googlecode.go.pkg/Payload
|
||||
else
|
||||
curl -L -O https://storage.googleapis.com/golang/$GO_PKG_LINUX
|
||||
shasum -a256 $GO_PKG_LINUX | grep $GO_PKG_LINUX_SHA
|
||||
tar xf $GO_PKG_LINUX
|
||||
fi
|
||||
|
||||
# Prove we did something right
|
||||
echo "$GO_VERSION installed in $GODIR: Go Binary: $(which go)"
|
||||
fi
|
||||
|
||||
cd $ROOTDIR
|
||||
|
||||
# Configure the new go to be the first go found
|
||||
export GOPATH=$ROOTDIR/.vendor
|
11
script/go
Executable file
11
script/go
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
. script/bootstrap
|
||||
|
||||
mkdir -p bin
|
||||
bindir="$PWD"/bin
|
||||
|
||||
cd .gopath/src/github.com/github/gh-ost
|
||||
go "$@"
|
18
script/godep
Executable file
18
script/godep
Executable file
@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
PREVGOPATH=$GOPATH
|
||||
|
||||
. script/bootstrap
|
||||
|
||||
mkdir -p bin
|
||||
bindir="$PWD"/bin
|
||||
|
||||
# Put the GOPATH for the user before our fake one so we can run `godep save ./...`
|
||||
if [ -n "$PREVGOPATH" ]; then
|
||||
export GOPATH=$PREVGOPATH:$GOPATH
|
||||
fi
|
||||
|
||||
cd .gopath/src/github.com/github/gh-ost
|
||||
godep "$@"
|
22
script/shim
Executable file
22
script/shim
Executable file
@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# This is a shim to sit in front of the binaries and load the appropriate
|
||||
# environment variables for the environment set in GITBACKUPS_ENV
|
||||
|
||||
# Default to staging for now
|
||||
GITBACKUPS_ENV=${GITBACKUPS_ENV:-"staging"}
|
||||
|
||||
# The base directory, which includes bin/ and whatever else once deployed
|
||||
base=$(cd $(dirname $(dirname ${BASH_SOURCE[0]})) && pwd)
|
||||
|
||||
if [ -f "${base}/.app-config/${GITBACKUPS_ENV}.sh" ]; then
|
||||
source "${base}/.app-config/${GITBACKUPS_ENV}.sh"
|
||||
fi
|
||||
|
||||
# Now that we have the env variables to let the binary know where to put the
|
||||
# data, switch into it
|
||||
myname=$(basename "$0")
|
||||
|
||||
exec "${base}/libexec/${myname}" "$@"
|
Loading…
Reference in New Issue
Block a user