forked from bdr08349/ladder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
149 lines (115 loc) · 4.84 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
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
# The following are targers that do not exist in the filesystem as real files and should be always executed by make
.PHONY: default deps base build dev shell start stop image test publish_coverage vet gogen build_release dep_install dep_update docs_build docs_shell serve_docs publish_docs gh-release
# Name of this service/application
SERVICE_NAME := ladder
# Docker image name for this project
IMAGE_NAME := themotion/$(SERVICE_NAME)
# Shell to use for running scripts
SHELL := $(shell which bash)
# Get docker path or an empty string
DOCKER := $(shell command -v docker)
# Get docker-compose path or an empty string
DOCKER_COMPOSE := $(shell command -v docker-compose)
# Get the main unix group for the user running make (to be used by docker-compose later)
GID := $(shell id -g)
# Get the unix user id for the user running make (to be used by docker-compose later)
UID := $(shell id -u)
# Get the username of theuser running make. On the devbox, we give priority to /etc/username
USERNAME ?= $(shell ( [ -f /etc/username ] && cat /etc/username ) || whoami)
# Bash history file for container shell
HISTORY_FILE := ~/.bash_history.$(SERVICE_NAME)
DOCS_HISTORY_FILE := ~/.bash_history.$(SERVICE_NAME)-docs
# Try to detect current branch if not provided from environment
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
# Commit hash from git
COMMIT=$(shell git rev-parse --short HEAD)
# Tag on this commit
TAG ?= $(shell git describe --tags --exact-match)
# The default action of this Makefile is to build the development docker image
default: build
# Test if the dependencies we need to run this Makefile are installed
deps:
ifndef DOCKER
@echo "Docker is not available. Please install docker"
@exit 1
endif
ifndef DOCKER_COMPOSE
@echo "docker-compose is not available. Please install docker-compose"
@exit 1
endif
# Build the base docker image which is shared between the development and production images
base: deps
docker build -t $(IMAGE_NAME)_base:latest .
# Build the development docker image
build: base
cd environment/dev && docker-compose build
# Run the development environment in non-daemonized mode (foreground)
dev: build
cd environment/dev && \
( docker-compose up; \
docker-compose stop; \
docker-compose rm -f; )
# Run a shell into the development docker image
shell: build
-touch $(HISTORY_FILE)
cd environment/dev && docker-compose run --service-ports --rm $(SERVICE_NAME) /bin/bash
# Run the development environment in the background
start: build
cd environment/dev && \
docker-compose up -d
# Stop the development environment (background and/or foreground)
stop:
cd environment/dev && ( \
docker-compose stop; \
docker-compose rm -f; \
)
# Build release, target on /bin
build_release:build
cd environment/dist && docker-compose run --rm $(SERVICE_NAME) /bin/bash -c "./build.sh"
# Update project dependencies to tle latest version
dep_update:build
cd environment/dev && docker-compose run --rm $(SERVICE_NAME) /bin/bash -c 'glide up --strip-vcs --update-vendored'
# Install new dependency make dep_install args="github.com/Sirupsen/logrus"
dep_install:build
cd environment/dev && docker-compose run --rm $(SERVICE_NAME) /bin/bash -c 'glide get --strip-vcs $(args)'
# Pass the golang vet check
vet: build
cd environment/dev && docker-compose run --rm $(SERVICE_NAME) /bin/bash -c 'go vet `glide nv`'
# Execute unit tests
test: build
cd environment/dev && docker-compose run --rm $(SERVICE_NAME) /bin/bash -c './test.sh'
# Generate required code (mocks...)
gogen: build
cd environment/dev && docker-compose run --rm $(SERVICE_NAME) /bin/bash -c 'go generate `glide nv`'
# Build the production themotion image based on the public one
image: build_release
docker build \
-t $(IMAGE_NAME) \
-t $(IMAGE_NAME):latest \
-f environment/prod/Dockerfile .
# Will build the image and tag with a release if available
image-release: image
ifneq ($(TAG),)
docker tag $(IMAGE_NAME):latest $(IMAGE_NAME):$(TAG)
endif
push: image-release
@docker login -u ${DOCKER_HUB_USERNAME} -p ${DOCKER_HUB_PASSWORD} && \
docker push $(IMAGE_NAME) && \
rm -rf ${HOME}/.docker
gh-release: build
cd environment/dist && docker-compose run --rm $(SERVICE_NAME) /bin/bash -c './gh-release.sh'
# Docs command
docs_build:
cd environment/docs && docker-compose build
docs_shell: docs_build
-touch $(DOCS_HISTORY_FILE)
cd environment/docs && docker-compose run --service-ports --rm hugo /bin/bash
serve_docs: docs_build
cd environment/docs && docker-compose run --service-ports --rm hugo /bin/bash -c 'hugo serve -s ./docs --bind=0.0.0.0'
publish_docs: docs_build
rm -rf public
git worktree prune
-git worktree add -B gh-pages public origin/gh-pages # No problem if already checked
cd environment/docs && docker-compose run --rm hugo /bin/bash -c "hugo -s ./docs/ -d ../public"
cd public && git add --all && git commit -m "Publishing to gh-pages" && cd ..
git push origin gh-pages