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
|
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:
|
2021-02-19 20:23:45 +00:00
|
|
|
go get -u 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
|
2022-06-02 11:59:44 +00:00
|
|
|
installtools: | $(LINT) $(GOOSE)
|
2018-02-08 16:12:08 +00:00
|
|
|
echo "Installing tools"
|
2022-06-02 11:59:44 +00:00
|
|
|
go mod download
|
2018-02-08 16:12:08 +00:00
|
|
|
|
|
|
|
.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"
|
|
|
|
|
2019-10-31 18:05:19 +00:00
|
|
|
#Database
|
|
|
|
HOST_NAME = localhost
|
|
|
|
PORT = 5432
|
|
|
|
NAME =
|
|
|
|
USER = postgres
|
2021-02-19 20:23:45 +00:00
|
|
|
PASSWORD = password
|
|
|
|
CONNECT_STRING=postgresql://$(USER):$(PASSWORD)@$(HOST_NAME):$(PORT)/$(NAME)?sslmode=disable
|
2019-10-31 18:05:19 +00:00
|
|
|
|
2019-09-19 23:48:38 +00:00
|
|
|
#Test
|
|
|
|
TEST_DB = vulcanize_testing
|
2021-02-19 20:23:45 +00:00
|
|
|
TEST_CONNECT_STRING = postgresql://$(DATABASE_USER):$(DATABASE_PASSWORD)@$(DATABASE_HOSTNAME):$(DATABASE_PORT)/$(TEST_DB)?sslmode=disable
|
2021-02-24 17:13:31 +00:00
|
|
|
TEST_CONNECT_STRING_LOCAL = postgresql://$(USER)@$(HOST_NAME):$(PORT)/$(TEST_DB)?sslmode=disable
|
2019-09-19 23:48:38 +00:00
|
|
|
|
2018-02-08 16:12:08 +00:00
|
|
|
.PHONY: test
|
2022-09-21 10:58:19 +00:00
|
|
|
test:
|
2018-02-08 16:12:08 +00:00
|
|
|
go vet ./...
|
|
|
|
go fmt ./...
|
2022-10-04 11:06:23 +00:00
|
|
|
go run github.com/onsi/ginkgo/ginkgo -r --skipPackage=test
|
2018-10-17 18:04:55 +00:00
|
|
|
|
|
|
|
.PHONY: integrationtest
|
2022-09-21 10:58:19 +00:00
|
|
|
integrationtest:
|
2018-10-17 18:04:55 +00:00
|
|
|
go vet ./...
|
|
|
|
go fmt ./...
|
2022-06-02 11:59:44 +00:00
|
|
|
go run github.com/onsi/ginkgo/ginkgo -r test/ -v
|
2021-02-24 17:13:31 +00:00
|
|
|
|
|
|
|
.PHONY: test_local
|
2022-09-21 10:58:19 +00:00
|
|
|
test_local:
|
2021-02-24 17:13:31 +00:00
|
|
|
go vet ./...
|
|
|
|
go fmt ./...
|
2021-06-14 04:56:10 +00:00
|
|
|
./scripts/run_unit_test.sh
|
2021-02-24 17:13:31 +00:00
|
|
|
|
2019-07-17 18:22:14 +00:00
|
|
|
build:
|
2018-02-08 16:12:08 +00:00
|
|
|
go fmt ./...
|
2020-08-08 04:09:44 +00:00
|
|
|
GO111MODULE=on go build
|
2018-02-08 16:12:08 +00:00
|
|
|
|
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
|
2019-10-30 04:26:25 +00:00
|
|
|
$(GOOSE) -dir db/migrations 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
|
|
|
|
2020-08-05 16:02:39 +00:00
|
|
|
## Rollback to a select migration (id/timestamp)
|
2019-01-24 10:54:25 +00:00
|
|
|
.PHONY: rollback_to
|
|
|
|
rollback_to: $(GOOSE) checkmigration checkdbvars
|
2019-10-30 04:26:25 +00:00
|
|
|
$(GOOSE) -dir db/migrations postgres "$(CONNECT_STRING)" down-to "$(MIGRATION)"
|
2019-01-24 10:54:25 +00:00
|
|
|
|
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
|
2019-10-30 04:26:25 +00:00
|
|
|
$(GOOSE) -dir db/migrations 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
|
2019-10-30 04:26:25 +00:00
|
|
|
$(GOOSE) -dir db/migrations create $(NAME) sql
|
2019-01-24 10:54:25 +00:00
|
|
|
|
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
|
2019-10-30 04:26:25 +00:00
|
|
|
$(GOOSE) -dir db/migrations postgres "$(CONNECT_STRING)" status
|
2019-01-24 10:54:25 +00:00
|
|
|
|
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-10-30 04:26:25 +00:00
|
|
|
$(GOOSE) -dir db/migrations 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
|
2020-09-06 09:32:11 +00:00
|
|
|
|
|
|
|
## Build docker image
|
|
|
|
.PHONY: docker-build
|
|
|
|
docker-build:
|
2022-09-20 15:52:06 +00:00
|
|
|
docker build -t cerc-io/ipld-eth-server .
|