-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
165 lines (133 loc) · 4.17 KB
/
Makefile
File metadata and controls
165 lines (133 loc) · 4.17 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# kudzu - GROW server
# The binary to build (just the basename)
BIN := kudzu
# The projects root import path (under GOPATH)
PKG := github.com/thingful/kudzu
# Docker Hub ID to which docker images should be pushed
REGISTRY ?= thingful
# Version string - to be added to the binary
VERSION := $(shell git describe --tags --always --dirty)
# Build date - to be added to the binary
BUILD_DATE := $(shell date -u "+%FT%H:%M:%S%Z")
# Do not change the following variables
PWD := $(shell pwd)
SRC_DIRS := cmd pkg
BASE_IMAGE ?= alpine
BUILD_IMAGE ?= golang:1.12-alpine
IMAGE := $(REGISTRY)/$(BIN)
BUILD_DIRS := bin \
.go/src/$(PKG) \
.go/pkg \
.go/bin/linux_amd64 \
.go/std/linux_amd64 \
.go/cache \
.coverage
all: build
build: bin/$(BIN) ## Build our binary inside a container
bin/$(BIN): $(BUILD_DIRS) .compose
@echo "--> Building in the containerized environment"
@docker-compose -f .docker-compose.yml build
@docker-compose -f .docker-compose.yml \
run \
--rm \
-u $$(id -u):$$(id -g) \
--no-deps \
app \
/bin/sh -c " \
VERSION=$(VERSION) \
PKG=$(PKG) \
BUILD_DATE=$(BUILD_DATE) \
BINARY_NAME=$(BIN) \
./build/build.sh \
"
shell: .shell ## Open shell in containerized environment
.shell: $(BUILD_DIRS) .compose
@echo "--> Launching shell in the containerized environment"
@docker-compose -f .docker-compose.yml \
run \
--rm \
-u "$$(id -u):$$(id -g)" \
app \
/bin/sh
.PHONY: test
test: $(BUILD_DIRS) .compose ## Run tests in the containerized environment
@echo "--> Running tests in the containerized environment"
@docker-compose -f .docker-compose.yml \
run \
--rm \
-u $$(id -u):$$(id -g) \
-e "KUDZU_DATABASE_URL=postgres://kudzu:password@postgres/kudzu_test?sslmode=disable" \
app \
/bin/sh -c " \
./build/test.sh $(SRC_DIRS) \
"
.PHONY: test-shell
test-shell: .test-shell ## Open shell in test containerized environment
.test-shell: $(BUILD_DIRS) .compose
@echo "--> Launching shell in the containerized environment"
@docker-compose -f .docker-compose.yml \
run \
--rm \
-u "$$(id -u):$$(id -g)" \
-e "KUDZU_DATABASE_URL=postgres://kudzu:password@postgres/kudzu_test?sslmode=disable" \
app \
/bin/sh
DOTFILE_IMAGE = $(subst :,_,$(subst /,_,$(IMAGE))-$(VERSION))
container: .container-$(DOTFILE_IMAGE) container-name ## Create delivery container image
.container-$(DOTFILE_IMAGE): bin/$(BIN) Dockerfile.in
@sed \
-e 's|ARG_BIN|$(BIN)|g' \
-e 's|ARG_FROM|$(BASE_IMAGE)|g' \
Dockerfile.in > .dockerfile-in
@docker build -t $(IMAGE):$(VERSION) -f .dockerfile-in .
@docker images -q $(IMAGE):$(VERSION) > $@
.PHONY: container-name
container-name: ## Show the name of the delivery container
@echo " container: $(IMAGE):$(VERSION)"
.PHONY: .compose
.compose: ## Create environment specific compose file
@sed \
-e 's|ARG_FROM|$(BUILD_IMAGE)|g' \
-e 's|ARG_WORKDIR|/go/src/$(PKG)|g' \
Dockerfile.dev > .dockerfile-dev
@sed \
-e 's|ARG_DOCKERFILE|.dockerfile-dev|g' \
-e 's|ARG_IMAGE|$(IMAGE)-dev:$(VERSION)|g' \
-e 's|ARG_PWD|$(PWD)|g' \
-e 's|ARG_PKG|$(PKG)|g' \
-e 's|ARG_BIN|$(BIN)|g' \
docker-compose.yml > .docker-compose.yml
$(BUILD_DIRS): ## creates build directories
@mkdir -p $@
.PHONY: version
version: ## returns the current version
@echo Version: $(VERSION) - $(BUILD_DATE) $(IMAGE)
.PHONY: push
push: .push-$(DOTFILE_IMAGE) push-name
.push-$(DOTFILE_IMAGE):
@docker push $(IMAGE):$(VERSION)
@docker images -q $(IMAGE):$(VERSION) > $@
.PHONY: push-name
push-name:
@echo " pushed $(IMAGE):$(VERSION)"
.PHONY: start
start: .compose ## start compose services
@docker-compose -f .docker-compose.yml \
up
.PHONY: teardown
teardown: .compose ## teardown compose services
@docker-compose -f .docker-compose.yml \
down -v
.PHONY: clean
clean: container-clean bin-clean ## remove all artefacts
.PHONY: container-clean
container-clean: ## clean container artefacts
rm -rf .container-* .dockerfile-* .docker-compose-* .push-*
.PHONY: bin-clean
bin-clean: ## remove generated build artefacts
rm -rf .go bin .coverage
.PHONY: psql
psql: .compose
@docker-compose -f .docker-compose.yml start postgres
@sleep 1
@docker exec -it kudzu_postgres_1 psql -U kudzu kudzu_development