diff --git a/.gitignore b/.gitignore index 32cda3d9e9fe1a96791e20a1b713a57dfacd6241..12be4236c891d5077c99a4a556c9813fc1b86284 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,9 @@ # do not vendor in dependencies vendor + +# build target +target + # Temporary / cached *.swp debug diff --git a/Dockerfile.deploy b/Dockerfile.deploy index c264cef4a2d67273b3140331791a9a6e78d84ef2..dfe3b3e8a632a1c8af4c5590592202b60f7edaa4 100644 --- a/Dockerfile.deploy +++ b/Dockerfile.deploy @@ -3,13 +3,8 @@ MAINTAINER Monax <support@monax.io> ENV TARGET eris-db -# runtime customization start here -COPY ./eris-client $INSTALL_BASE/eris-client -COPY ./bin/start_eris_db $INSTALL_BASE/erisdb-wrapper -# runtime customization end here - -# Get the binary from the artifact in pwd -COPY ./"$TARGET"_build_artifact $INSTALL_BASE/$TARGET +# Get the binary from the artefact in pwd/target/docker +COPY ./target/docker/"$TARGET".dockerartefact $INSTALL_BASE/$TARGET RUN chmod +x --recursive $INSTALL_BASE # Finalize diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..29bbd1a874f96fb7813e15138112d522399992d6 --- /dev/null +++ b/Makefile @@ -0,0 +1,156 @@ +# ---------------------------------------------------------- +# REQUIREMENTS + +# - go installed locally +# - for build_docker: docker installed locally + +# ---------------------------------------------------------- + +SHELL := /bin/bash +REPO := $(shell pwd) +GOFILES_NOVENDOR := $(shell find ${REPO} -type f -name '*.go' -not -path "${REPO}/vendor/*") +PACKAGES_NOVENDOR := $(shell go list github.com/eris-ltd/eris-db/... | grep -v /vendor/) +VERSION := $(shell cat ${REPO}/version/version.go | tail -n 1 | cut -d \ -f 4 | tr -d '"') +VERSION_MIN := $(shell echo ${VERSION} | cut -d . -f 1-2) +COMMIT_SHA := $(shell echo `git rev-parse --short --verify HEAD`) + +DOCKER_NAMESPACE := quay.io/eris + + +.PHONY: greet +greet: + @echo "Hi! I'm the marmot that will help you with eris-db v${VERSION}" + +### Formatting, linting and vetting + +# check the code for style standards; currently enforces go formatting. +# display output first, then check for success +.PHONY: check +check: + @echo "Checking code for formatting style compliance." + @gofmt -l -d ${GOFILES_NOVENDOR} + @gofmt -l ${GOFILES_NOVENDOR} | read && echo && echo "Your marmot has found a problem with the formatting style of the code." 1>&2 && exit 1 || true + +# fmt runs gofmt -w on the code, modifying any files that do not match +# the style guide. +.PHONY: fmt +fmt: + @echo "Correcting any formatting style corrections." + @gofmt -l -w ${GOFILES_NOVENDOR} + +# lint installs golint and prints recommendations for coding style. +lint: + @echo "Running lint checks." + go get -u github.com/golang/lint/golint + @for file in $(GOFILES_NOVENDOR); do \ + echo; \ + golint --set_exit_status $${file}; \ + done + +# vet runs extended compilation checks to find recommendations for +# suspicious code constructs. +.PHONY: vet +vet: + @echo "Running go vet." + @go vet ${PACKAGES_NOVENDOR} + +### Dependency management for github.com/eris-ltd/eris-db + +# erase vendor wipes the full vendor directory +.PHONY: erase_vendor +erase_vendor: + rm -rf ${REPO}/vendor/ + +# install vendor uses glide to install vendored dependencies +.PHONY: install_vendor +install_vendor: + go get github.com/Masterminds/glide + glide install + +# hell runs utility tool hell to selectively update glide dependencies +.PHONY: hell +hell: + go build -o ${REPO}/target/hell ./util/hell/cmd/hell/main.go + ./target/hell $(filter-out $@,$(MAKECMDGOALS)) + +### Building github.com/eris-ltd/eris-db + +# build all targets in github.com/eris-ltd/eris-db +.PHONY: build +build: check build_db build_client build_keys + +# build all targets in github.com/eris-ltd/eris-db with checks for race conditions +.PHONY: build_race +build_race: check build_race_db build_race_client build_race_keys + +# build eris-db +.PHONY: build_db +build_db: + go build -o ${REPO}/target/eris-db-${COMMIT_SHA} ./cmd/eris-db + +# build eris-client +.PHONY: build_client +build_client: + go build -o ${REPO}/target/eris-client-${COMMIT_SHA} ./client/cmd/eris-client + +# build eris-keys +.PHONY: build_keys +build_keys: + @echo "Marmots need to complete moving repository eris-keys into eris-db." + +# build eris-db with checks for race conditions +.PHONY: build_race_db +build_race_db: + go build -race -o ${REPO}/target/eris-db-${COMMIT_SHA} ./cmd/eris-db + +# build eris-client with checks for race conditions +.PHONY: build_race_client +build_race_client: + go build -race -o ${REPO}/target/eris-client-${COMMIT_SHA} ./client/cmd/eris-client + +# build eris-keys with checks for race conditions +.PHONY: build_race_keys +build_race_keys: + @echo "Marmots need to complete moving repository eris-keys into eris-db." + +### Testing github.com/eris-ltd/eris-db + +# test eris-db +.PHONY: test +test: build + @go test ${PACKAGES_NOVENDOR} -tags integration + +# test eris-db with checks for race conditions +.PHONY: test_race +test_race: build_race + @go test -race ${PACKAGES_NOVENDOR} + +### Build docker images for github.com/eris-ltd/eris-db + +# build docker image for eris-db +.PHONY: build_docker_db +build_docker_db: check + @mkdir -p ${REPO}/target/docker + docker build -t ${DOCKER_NAMESPACE}/db:build-${COMMIT_SHA} ${REPO} + docker run --rm --entrypoint cat ${DOCKER_NAMESPACE}/db:build-${COMMIT_SHA} /usr/local/bin/eris-db > ${REPO}/target/docker/eris-db.dockerartefact + docker run --rm --entrypoint cat ${DOCKER_NAMESPACE}/db:build-${COMMIT_SHA} /usr/local/bin/eris-client > ${REPO}/target/docker/eris-client.dockerartefact + docker build -t ${DOCKER_NAMESPACE}/db:${VERSION} -f Dockerfile.deploy ${REPO} + + @rm ${REPO}/target/docker/eris-db.dockerartefact + @rm ${REPO}/target/docker/eris-client.dockerartefact + docker rmi ${DOCKER_NAMESPACE}/db:build-${COMMIT_SHA} + +### Test docker images for github.com/eris-ltd/eris-db + +# test docker image for eris-db +.PHONY: test_docker_db +test_docker_db: check + docker build -t ${DOCKER_NAMESPACE}/db:build-${COMMIT_SHA} ${REPO} + docker run ${DOCKER_NAMESPACE}/db:build-${COMMIT_SHA} glide nv | xargs go test -tags integration + +### Clean up + +# clean removes the target folder containing build artefacts +.PHONY: clean +clean: + -rm -r ./target \ No newline at end of file diff --git a/hell b/hell deleted file mode 100644 index 392907b3a74800038d60cc899e866c97f0afc28d..0000000000000000000000000000000000000000 --- a/hell +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -go run ./util/hell/cmd/hell/main.go "$@" \ No newline at end of file diff --git a/tests/build_tool.sh b/tests/build_tool.sh index b32f941b823b28d3850858dbab7345c9b0e8f5ab..1f377e91eacd659791df20bef4dd87c5d311a215 100755 --- a/tests/build_tool.sh +++ b/tests/build_tool.sh @@ -35,14 +35,15 @@ release_min=$(cat $REPO/version/version.go | tail -n 1 | cut -d \ -f 4 | tr -d release_maj=$(echo $release_min | cut -d . -f 1-2) # Build +mkdir -p $REPO/target/docker docker build -t $IMAGE:build $REPO -docker run --rm --entrypoint cat $IMAGE:build /usr/local/bin/$TARGET > $REPO/"$TARGET"_build_artifact -docker run --rm --entrypoint cat $IMAGE:build /usr/local/bin/eris-client > $REPO/eris-client +docker run --rm --entrypoint cat $IMAGE:build /usr/local/bin/$TARGET > $REPO/target/docker/eris-db.dockerartefact +docker run --rm --entrypoint cat $IMAGE:build /usr/local/bin/eris-client > $REPO/target/docker/eris-client.dockerartefact docker build -t $IMAGE:$release_min -f Dockerfile.deploy $REPO # Cleanup -rm $REPO/"$TARGET"_build_artifact -rm $REPO/eris-client +rm $REPO/target/docker/eris-db.dockerartefact +rm $REPO/target/docker/eris-client.dockerartefact # Extra Tags if [[ "$branch" = "release" ]]