2018-02-08 16:12:08 +00:00
|
|
|
BIN = $(GOPATH)/bin
|
|
|
|
BASE = $(GOPATH)/src/$(PACKAGE)
|
|
|
|
PKGS = go list ./... | grep -v "^vendor/"
|
|
|
|
|
2019-01-24 12:17:41 +00:00
|
|
|
# Tools
|
|
|
|
## Dependency management
|
2018-02-08 16:12:08 +00:00
|
|
|
DEP = $(BIN)/dep
|
|
|
|
$(BIN)/dep:
|
|
|
|
go get -u github.com/golang/dep/cmd/dep
|
|
|
|
|
2019-01-24 12:17:41 +00:00
|
|
|
## Testing library
|
2018-02-08 16:12:08 +00:00
|
|
|
GINKGO = $(BIN)/ginkgo
|
|
|
|
$(BIN)/ginkgo:
|
|
|
|
go get -u github.com/onsi/ginkgo/ginkgo
|
2018-01-25 19:21:55 +00:00
|
|
|
|
2019-01-24 12:17:41 +00:00
|
|
|
## Migration tool
|
2019-01-24 10:54:25 +00:00
|
|
|
GOOSE = $(BIN)/goose
|
|
|
|
$(BIN)/goose:
|
|
|
|
go get -u -d github.com/pressly/goose/cmd/goose
|
2019-01-24 13:28:09 +00:00
|
|
|
go build -tags='no_mysql no_sqlite' -o $(BIN)/goose github.com/pressly/goose/cmd/goose
|
2018-01-25 19:21:55 +00:00
|
|
|
|
2019-01-24 12:17:41 +00:00
|
|
|
## Source linter
|
2018-02-08 16:12:08 +00:00
|
|
|
LINT = $(BIN)/golint
|
|
|
|
$(BIN)/golint:
|
2018-03-27 21:06:12 +00:00
|
|
|
go get -u golang.org/x/lint/golint
|
2018-02-08 16:12:08 +00:00
|
|
|
|
2019-01-24 12:17:41 +00:00
|
|
|
## Combination linter
|
2018-02-08 16:12:08 +00:00
|
|
|
METALINT = $(BIN)/gometalinter.v2
|
|
|
|
$(BIN)/gometalinter.v2:
|
|
|
|
go get -u gopkg.in/alecthomas/gometalinter.v2
|
|
|
|
$(METALINT) --install
|
|
|
|
|
2019-01-24 12:17:41 +00:00
|
|
|
|
2018-02-08 16:12:08 +00:00
|
|
|
.PHONY: installtools
|
2019-01-24 11:03:44 +00:00
|
|
|
installtools: | $(LINT) $(GOOSE) $(GINKGO) $(DEP)
|
2018-02-08 16:12:08 +00:00
|
|
|
echo "Installing tools"
|
|
|
|
|
|
|
|
.PHONY: metalint
|
|
|
|
metalint: | $(METALINT)
|
|
|
|
$(METALINT) ./... --vendor \
|
|
|
|
--fast \
|
|
|
|
--exclude="exported (function)|(var)|(method)|(type).*should have comment or be unexported" \
|
|
|
|
--format="{{.Path.Abs}}:{{.Line}}:{{if .Col}}{{.Col}}{{end}}:{{.Severity}}: {{.Message}} ({{.Linter}})"
|
|
|
|
|
|
|
|
.PHONY: lint
|
|
|
|
lint:
|
|
|
|
$(LINT) $$($(PKGS)) | grep -v -E "exported (function)|(var)|(method)|(type).*should have comment or be unexported"
|
|
|
|
|
|
|
|
.PHONY: test
|
|
|
|
test: | $(GINKGO) $(LINT)
|
|
|
|
go vet ./...
|
|
|
|
go fmt ./...
|
2019-02-13 19:04:07 +00:00
|
|
|
$(GINKGO) -r --skipPackage=integration_tests,integration
|
2018-10-17 18:04:55 +00:00
|
|
|
|
|
|
|
.PHONY: integrationtest
|
|
|
|
integrationtest: | $(GINKGO) $(LINT)
|
|
|
|
go vet ./...
|
|
|
|
go fmt ./...
|
2019-01-31 23:14:42 +00:00
|
|
|
$(GINKGO) -r integration_test/
|
2018-01-25 19:21:55 +00:00
|
|
|
|
2018-02-08 16:12:08 +00:00
|
|
|
.PHONY: dep
|
|
|
|
dep: | $(DEP)
|
|
|
|
$(DEP) ensure
|
2018-01-25 19:21:55 +00:00
|
|
|
|
2018-02-08 16:12:08 +00:00
|
|
|
build: dep
|
|
|
|
go fmt ./...
|
|
|
|
go build
|
|
|
|
|
|
|
|
#Database
|
|
|
|
HOST_NAME = localhost
|
|
|
|
PORT = 5432
|
|
|
|
NAME =
|
|
|
|
CONNECT_STRING=postgresql://$(HOST_NAME):$(PORT)/$(NAME)?sslmode=disable
|
|
|
|
|
2019-01-24 12:17:41 +00:00
|
|
|
# Parameter checks
|
|
|
|
## Check that DB variables are provided
|
2018-02-08 16:12:08 +00:00
|
|
|
.PHONY: checkdbvars
|
2018-01-25 19:21:55 +00:00
|
|
|
checkdbvars:
|
2019-01-24 12:17:41 +00:00
|
|
|
test -n "$(HOST_NAME)" # $$HOST_NAME
|
2018-01-25 19:21:55 +00:00
|
|
|
test -n "$(PORT)" # $$PORT
|
|
|
|
test -n "$(NAME)" # $$NAME
|
2018-02-13 16:31:57 +00:00
|
|
|
@echo $(CONNECT_STRING)
|
|
|
|
|
2019-01-24 12:17:41 +00:00
|
|
|
## Check that the migration variable (id/timestamp) is provided
|
|
|
|
.PHONY: checkmigration
|
|
|
|
checkmigration:
|
|
|
|
test -n "$(MIGRATION)" # $$MIGRATION
|
2018-01-25 19:21:55 +00:00
|
|
|
|
2019-01-24 12:17:41 +00:00
|
|
|
# Check that the migration name is provided
|
|
|
|
.PHONY: checkmigname
|
|
|
|
checkmigname:
|
|
|
|
test -n "$(NAME)" # $$NAME
|
|
|
|
|
|
|
|
# Migration operations
|
|
|
|
## Rollback the last migration
|
2018-02-08 16:12:08 +00:00
|
|
|
.PHONY: rollback
|
2019-01-24 10:54:25 +00:00
|
|
|
rollback: $(GOOSE) checkdbvars
|
|
|
|
cd db/migrations;\
|
|
|
|
$(GOOSE) postgres "$(CONNECT_STRING)" down
|
2018-01-25 19:21:55 +00:00
|
|
|
pg_dump -O -s $(CONNECT_STRING) > db/schema.sql
|
|
|
|
|
2019-01-24 10:54:25 +00:00
|
|
|
|
2019-01-24 12:17:41 +00:00
|
|
|
## Rollbackt to a select migration (id/timestamp)
|
2019-01-24 10:54:25 +00:00
|
|
|
.PHONY: rollback_to
|
|
|
|
rollback_to: $(GOOSE) checkmigration checkdbvars
|
|
|
|
cd db/migrations;\
|
|
|
|
$(GOOSE) postgres "$(CONNECT_STRING)" down-to "$(MIGRATION)"
|
|
|
|
|
2019-01-24 12:17:41 +00:00
|
|
|
## Apply all migrations not already run
|
2018-02-08 16:12:08 +00:00
|
|
|
.PHONY: migrate
|
2019-01-24 10:54:25 +00:00
|
|
|
migrate: $(GOOSE) checkdbvars
|
|
|
|
cd db/migrations;\
|
|
|
|
$(GOOSE) postgres "$(CONNECT_STRING)" up
|
2018-01-25 19:21:55 +00:00
|
|
|
pg_dump -O -s $(CONNECT_STRING) > db/schema.sql
|
|
|
|
|
2019-01-24 12:17:41 +00:00
|
|
|
## Create a new migration file
|
2019-01-24 10:54:25 +00:00
|
|
|
.PHONY: new_migration
|
|
|
|
new_migration: $(GOOSE) checkmigname
|
|
|
|
cd db/migrations;\
|
|
|
|
$(GOOSE) create $(NAME) sql
|
|
|
|
|
2019-01-24 12:17:41 +00:00
|
|
|
## Check which migrations are applied at the moment
|
2019-01-24 10:54:25 +00:00
|
|
|
.PHONY: migration_status
|
|
|
|
migration_status: $(GOOSE) checkdbvars
|
|
|
|
cd db/migrations;\
|
|
|
|
$(GOOSE) postgres "$(CONNECT_STRING)" status
|
|
|
|
|
2019-01-24 12:17:41 +00:00
|
|
|
# Convert timestamped migrations to versioned (to be run in CI);
|
|
|
|
# merge timestamped files to prevent conflict
|
|
|
|
.PHONY: version_migrations
|
|
|
|
version_migrations:
|
2019-01-24 13:28:09 +00:00
|
|
|
cd db/migrations; $(GOOSE) fix
|
2019-01-24 12:17:41 +00:00
|
|
|
|
|
|
|
# Import a psql schema to the database
|
2018-02-08 16:12:08 +00:00
|
|
|
.PHONY: import
|
2018-01-25 21:46:55 +00:00
|
|
|
import:
|
|
|
|
test -n "$(NAME)" # $$NAME
|
|
|
|
psql $(NAME) < db/schema.sql
|
2018-06-21 16:10:56 +00:00
|
|
|
|
2019-01-24 12:17:41 +00:00
|
|
|
|
|
|
|
# Docker actions
|
|
|
|
## Rinkeby docker environment
|
2018-06-21 19:21:34 +00:00
|
|
|
RINKEBY_COMPOSE_FILE=dockerfiles/rinkeby/docker-compose.yml
|
2018-06-21 16:10:56 +00:00
|
|
|
|
2018-06-21 19:21:34 +00:00
|
|
|
.PHONY: rinkeby_env_up
|
|
|
|
rinkeby_env_up:
|
|
|
|
docker-compose -f $(RINKEBY_COMPOSE_FILE) up -d geth
|
|
|
|
docker-compose -f $(RINKEBY_COMPOSE_FILE) up --build migrations
|
|
|
|
docker-compose -f $(RINKEBY_COMPOSE_FILE) up -d --build vulcanizedb
|
2018-06-21 16:10:56 +00:00
|
|
|
|
2018-06-21 19:21:34 +00:00
|
|
|
.PHONY: rinkeby_env_deploy
|
|
|
|
rinkeby_env_deploy:
|
|
|
|
docker-compose -f $(RINKEBY_COMPOSE_FILE) up -d --build vulcanizedb
|
2018-06-21 16:10:56 +00:00
|
|
|
|
|
|
|
.PHONY: dev_env_migrate
|
2018-06-21 19:21:34 +00:00
|
|
|
rinkeby_env_migrate:
|
|
|
|
docker-compose -f $(RINKEBY_COMPOSE_FILE) up --build migrations
|
2018-06-21 16:10:56 +00:00
|
|
|
|
2018-06-21 19:21:34 +00:00
|
|
|
.PHONY: rinkeby_env_down
|
|
|
|
rinkeby_env_down:
|
|
|
|
docker-compose -f $(RINKEBY_COMPOSE_FILE) down
|