Skip to content

Commit

Permalink
Refactor repository and build scripts
Browse files Browse the repository at this point in the history
This commit includes updates that affects the build, testing, and
deployment of Tile38.

- The root level build.sh has been broken up into multiple scripts
  and placed in the "scripts" directory.

- The vendor directory has been updated to follow the Go modules
  rules, thus `make` should work on isolated environments. Also
  some vendored packages may have been updated to a later
  version, if needed.

- The Makefile has been updated to allow for making single
  binaries such as `make tile38-server`. There is some scaffolding
  during the build process, so from now on all binaries should be
  made using make. For example, to run a development version of
  the tile38-cli binary, do this:
     make tile38-cli && ./tile38-cli
  not this:
     go run cmd/tile38-cli/main.go

- Travis.CI docker push script has been updated to address a
  change to Docker's JSON repo meta output, which in turn fixes
  a bug where new Tile38 versions were not being properly pushed
  to Docker
  • Loading branch information
tidwall committed Nov 18, 2019
1 parent 4b17a1b commit cfc65a1
Show file tree
Hide file tree
Showing 1,013 changed files with 323,746 additions and 192 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ script:
- make test

after_success:
- ./build.sh travis-docker-push
- scripts/travis-docker-push.sh
49 changes: 37 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,46 @@
all:
@./build.sh
clean:
rm -f tile38-server
rm -f tile38-cli
rm -f tile38-benchmark
rm -f tile38-luamemtest
all: tile38-server tile38-cli tile38-benchmark tile38-luamemtest

.PHONY: tile38-server
tile38-server:
@./scripts/build.sh tile38-server

.PHONY: tile38-cli
tile38-cli:
@./scripts/build.sh tile38-cli

.PHONY: tile38-benchmark
tile38-benchmark:
@./scripts/build.sh tile38-benchmark

.PHONY: tile38-luamemtest
tile38-luamemtest:
@./scripts/build.sh tile38-luamemtest

test:
@./build.sh test
cover:
@./build.sh cover
@./scripts/test.sh

package:
@rm -rf packages/
@scripts/package.sh Windows windows amd64
@scripts/package.sh Mac darwin amd64
@scripts/package.sh Linux linux amd64
@scripts/package.sh FreeBSD freebsd amd64
@scripts/package.sh ARM linux arm
@scripts/package.sh ARM64 linux arm64

clean:
rm -rf tile38-server tile38-cli tile38-benchmark tile38-luamemtest

distclean: clean
rm -rf packages/

install: all
cp tile38-server /usr/local/bin
cp tile38-cli /usr/local/bin
cp tile38-benchmark /usr/local/bin

uninstall:
rm -f /usr/local/bin/tile38-server
rm -f /usr/local/bin/tile38-cli
rm -f /usr/local/bin/tile38-benchmark
package:
@./build.sh package

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
</p>
<p align="center">
<a href="https://tile38.com/slack"><img src="https://img.shields.io/badge/slack-channel-orange.svg" alt="Slack Channel"></a>
<a href="https://github.com/tidwall/tile38/releases"><img src="https://img.shields.io/badge/version-1.19.0-green.svg?" alt="Version"></a>
<a href="https://travis-ci.org/tidwall/tile38"><img src="https://travis-ci.org/tidwall/tile38.svg?branch=master" alt="Build Status"></a>
<a href="https://hub.docker.com/r/tile38/tile38"><img src="https://img.shields.io/badge/docker-ready-blue.svg" alt="Docker Ready"></a>
</p>
Expand Down
178 changes: 0 additions & 178 deletions build.sh

This file was deleted.

37 changes: 37 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

set -e
cd $(dirname "${BASH_SOURCE[0]}")/..

if [ "$1" == "" ]; then
echo "error: missing argument (binary name)"
exit 1
fi

# Check the Go installation
if [ "$(which go)" == "" ]; then
echo "error: Go is not installed. Please download and follow installation"\
"instructions at https://golang.org/dl to continue."
exit 1
fi

# Hardcode some values to the core package.
if [ -d ".git" ]; then
VERSION=$(git describe --tags --abbrev=0)
GITSHA=$(git rev-parse --short HEAD)
LDFLAGS="$LDFLAGS -X github.com/tidwall/tile38/core.Version=${VERSION}"
LDFLAGS="$LDFLAGS -X github.com/tidwall/tile38/core.GitSHA=${GITSHA}"
fi
LDFLAGS="$LDFLAGS -X github.com/tidwall/tile38/core.BuildTime=$(date +%FT%T%z)"

# Generate the core package
core/gen.sh

# Set final Go environment options
LDFLAGS="$LDFLAGS -extldflags '-static'"
export CGO_ENABLED=0
export GO111MODULE=on
export GOFLAGS=-mod=vendor

# Build and store objects into original directory.
go build -ldflags "$LDFLAGS" -o $1 cmd/$1/*.go
46 changes: 46 additions & 0 deletions scripts/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

set -e
cd $(dirname "${BASH_SOURCE[0]}")/..

PLATFORM="$1"
GOOS="$2"
GOARCH="$3"
VERSION=$(git describe --tags --abbrev=0)

echo Packaging $PLATFORM Binary

# Remove previous build directory, if needed.
bdir=tile38-$VERSION-$GOOS-$GOARCH
rm -rf packages/$bdir && mkdir -p packages/$bdir

# Make the binaries.
GOOS=$GOOS GOARCH=$GOARCH make all
rm -f tile38-luamemtest # not needed

# Copy the executable binaries.
if [ "$GOOS" == "windows" ]; then
mv tile38-server packages/$bdir/tile38-server.exe
mv tile38-cli packages/$bdir/tile38-cli.exe
mv tile38-benchmark packages/$bdir/tile38-benchmark.exe
else
mv tile38-server packages/$bdir
mv tile38-cli packages/$bdir
mv tile38-benchmark packages/$bdir
fi

# Copy documention and license.
cp README.md packages/$bdir
cp CHANGELOG.md packages/$bdir
cp LICENSE packages/$bdir

# Compress the package.
cd packages
if [ "$GOOS" == "linux" ]; then
tar -zcf $bdir.tar.gz $bdir
else
zip -r -q $bdir.zip $bdir
fi

# Remove build directory.
rm -rf $bdir
7 changes: 7 additions & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -e
cd $(dirname "${BASH_SOURCE[0]}")/..

cd tests && go test && cd ..
go test $(go list ./... | grep -v /vendor/ | grep -v /tests)
35 changes: 35 additions & 0 deletions scripts/travis-docker-push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

set -e
cd $(dirname "${BASH_SOURCE[0]}")/..

# GIT_VERSION - always the last verison number, like 1.12.1.
export GIT_VERSION=$(git describe --tags --abbrev=0)
# GIT_COMMIT_SHORT - the short git commit number, like a718ef0.
export GIT_COMMIT_SHORT=$(git rev-parse --short HEAD)
# DOCKER_REPO - the base repository name to push the docker build to.
export DOCKER_REPO=$DOCKER_USER/tile38

if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
# never push from a pull request
echo "Not pushing, on a PR or not running in Travis CI"
elif [ "$TRAVIS_BRANCH" != "master" ]; then
# only the master branch will work
echo "Not pushing, not on master"
else
push(){
docker tag $DOCKER_REPO:$GIT_COMMIT_SHORT $DOCKER_REPO:$1
docker push $DOCKER_REPO:$1
echo "Pushed $DOCKER_REPO:$1"
}
# docker login
echo $DOCKER_PASSWORD | docker login -u $DOCKER_LOGIN --password-stdin
# build the docker image
docker build -f Dockerfile -t $DOCKER_REPO:$GIT_COMMIT_SHORT .
if [ "$(curl -s https://hub.docker.com/v2/repositories/$DOCKER_REPO/tags/$GIT_VERSION/ | grep "digest")" == "" ]; then
# push the newest tag
push "$GIT_VERSION"
push "latest"
fi
push "edge"
fi
Loading

0 comments on commit cfc65a1

Please sign in to comment.