forked from byuoitav/shipyard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
104 lines (74 loc) · 3.1 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
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
NAME := shipyard
OWNER := byuoitav
PKG := github.com/${OWNER}/${NAME}
BUILD_PKG := ${PKG}/cmd/server
DOCKER_URL := docker.pkg.github.com
# version:
# use the git tag, if this commit
# doesn't have a tag, use the git hash
COMMIT_HASH := $(shell git rev-parse --short HEAD)
TAG := $(shell git rev-parse --short HEAD)
ifneq ($(shell git describe --exact-match --tags HEAD 2> /dev/null),)
TAG = $(shell git describe --exact-match --tags HEAD)
endif
PRD_TAG_REGEX := "v[0-9]+\.[0-9]+\.[0-9]+"
DEV_TAG_REGEX := "v[0-9]+\.[0-9]+\.[0-9]+-.+"
# go stuff
PKG_LIST := $(shell go list ${PKG}/...)
.PHONY: all deps build test test-cov clean
all: clean build
test:
@go test -v ${PKG_LIST}
test-cov:
@go test -coverprofile=coverage.txt -covermode=atomic ${PKG_LIST}
lint:
@golangci-lint run --tests=false
deps:
@echo Downloading backend dependencies...
@go mod download
@echo Downloading frontend dependencies for builder ui...
@cd ui && npm install
build: deps
@mkdir -p dist
@echo
@echo Building backend for linux-amd64...
@env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -o ./dist/${NAME}-linux-amd64 ${BUILD_PKG}
@echo
@echo Building UI...
@cd ui && npm run-script build && mv ./dist/ui ../dist/ && rmdir ./dist
@echo
@echo Build output is located in ./dist/.
docker: clean build
ifeq (${COMMIT_HASH}, ${TAG})
@echo Building dev container with tag ${COMMIT_HASH}
@echo Building container ${DOCKER_URL}/${OWNER}/${NAME}/${NAME}-dev:${COMMIT_HASH}
@docker build -f dockerfile --build-arg NAME=${NAME}-linux-amd64 -t ${DOCKER_URL}/${OWNER}/${NAME}/${NAME}-dev:${COMMIT_HASH} dist
else ifneq ($(shell echo ${TAG} | grep -x -E ${DEV_TAG_REGEX}),)
@echo Building dev container with tag ${TAG}
@echo Building container ${DOCKER_URL}/${OWNER}/${NAME}/${NAME}-dev:${TAG}
@docker build -f dockerfile --build-arg NAME=${NAME}-linux-amd64 -t ${DOCKER_URL}/${OWNER}/${NAME}/${NAME}-dev:${TAG} dist
else ifneq ($(shell echo ${TAG} | grep -x -E ${PRD_TAG_REGEX}),)
@echo Building prd container with tag ${TAG}
@echo Building container ${DOCKER_URL}/${OWNER}/${NAME}/${NAME}:${TAG}
@docker build -f dockerfile --build-arg NAME=${NAME}-linux-amd64 -t ${DOCKER_URL}/${OWNER}/${NAME}/${NAME}:${TAG} dist
endif
deploy: docker
@echo Logging into Github Package Registry
@docker login ${DOCKER_URL} -u ${DOCKER_USERNAME} -p ${DOCKER_PASSWORD}
ifeq (${COMMIT_HASH}, ${TAG})
@echo Pushing dev container with tag ${COMMIT_HASH}
@echo Pushing container ${DOCKER_URL}/${OWNER}/${NAME}/${NAME}-dev:${COMMIT_HASH}
@docker push ${DOCKER_URL}/${OWNER}/${NAME}/${NAME}-dev:${COMMIT_HASH}
else ifneq ($(shell echo ${TAG} | grep -x -E ${DEV_TAG_REGEX}),)
@echo Pushing dev container with tag ${TAG}
@echo Pushing container ${DOCKER_URL}/${OWNER}/${NAME}/${NAME}-dev:${TAG}
@docker push ${DOCKER_URL}/${OWNER}/${NAME}/${NAME}-dev:${TAG}
else ifneq ($(shell echo ${TAG} | grep -x -E ${PRD_TAG_REGEX}),)
@echo Pushing prd container with tag ${TAG}
@echo Pushing container ${DOCKER_URL}/${OWNER}/${NAME}/${NAME}:${TAG}
@docker push ${DOCKER_URL}/${OWNER}/${NAME}/${NAME}:${TAG}
endif
clean:
@go clean
@cd ui && rm -rf dist node_modules
@rm -rf dist/