forked from chef/automate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
68 lines (50 loc) · 2.44 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
include ../../Makefile.common_go
PACKAGE_PATH = github.com/chef/automate/components/teams-service
BINS = ${PACKAGE_PATH}/cmd/teams-service
MIGRATION_READMES = storage/postgres/migration/sql/README.md
GIT_SHA = $(shell git rev-parse HEAD)
BUILD_TIME ?= $(shell date -u '+%Y%m%d%H%M%S')
GO_LDFLAGS = --ldflags "-X ${LIBRARY_PATH}/version.Version=${BUILD_TIME} -X ${LIBRARY_PATH}/version.GitSHA=${GIT_SHA} -X ${LIBRARY_PATH}/version.BuildTime=${BUILD_TIME}"
packages:=${PACKAGE_PATH}/...
ifdef CI
verbose?="-v"
endif
all: lint build test
static: lint ${MIGRATION_READMES}
unit: build test
.PHONY: ${MIGRATION_READMES}
${MIGRATION_READMES}:
../../scripts/generate_and_check_migration_files.sh $@
${BINS}: bin
@echo "GO $@"
@cd bin; go build ${GO_LDFLAGS} $@
bin:
mkdir -p bin
build: ${BINS}
# Regenerate all *.pb.go files
proto:
cd ../../ && hab studio run 'source .studiorc; compile_go_protobuf_component teams-service'
# This will use memstore for server tests and skip other PG tests
# by default unless in ciMode or PG_URL is set.
test:
@go test $(verbose) $(packages) -p 1 --parallel 1 -cover
PG_URL ?= "postgresql://[email protected]:5432/teams_test?sslmode=disable&password=docker"
test_with_db: db_container
@docker ps | grep teams-postgres || (echo "Docker postgres not up. Run make setup_docker_pg and try this command again."; exit 1)
@PGTZ=UTC PG_URL=$(PG_URL) go test $(packages) -p 1 --parallel 1 -cover
@echo "Docker containers still up, run 'make kill_docker_pg' to bring them down or test again with make test_with_db."
.PHONY: db_container
db_container:
@docker ps | grep teams-postgres || (echo "Docker postgres not up. Run make setup_docker_pg and try this command again."; exit 1)
psql -d $(PG_URL) -c "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\""
setup_docker_pg:
docker run --name teams-postgres -e POSTGRES_USER=postgres -e POSTGRES_DB=teams_test -e POSTGRES_PASSWORD=docker -p 5432:5432 -d postgres:9
sleep 5 # let docker come up
kill_docker_pg:
docker rm -f teams-postgres || true
# this command lists all the changes since master, and looks for modifications
# to the migration files -- if there's any of (M)odify, (R)ename, or (D)elete,
# it will trigger an error
migrations-append-only-check:
@git diff --name-status master... | awk '/[RMD][0-9]*\tcomponents\/teams-service\/postgres\/migration\/sql\//{ print "modified/deleted/renamed: " $$2; ec=1 } END{ exit ec }'
.PHONY: all static unit build compile proto test dep-ensure have-dep lint