forked from slok/ecs-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
105 lines (80 loc) · 3.27 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
# 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 push test build_release dep_update dep_install vet test gogen
# Name of this service/application
SERVICE_NAME := awslogs-exporter
# Docker image name for this project
IMAGE_NAME := houserater/$(SERVICE_NAME)
# 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)
# 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 release
default: build_release
# Build the base docker image which is shared between the development and production images
base:
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/dev && docker-compose run --rm $(SERVICE_NAME) /bin/bash -c "./build.sh"
# ensure dependencies.
dep_ensure:build
cd environment/dev && docker-compose run --rm $(SERVICE_NAME) /bin/bash -c 'dep ensure -v'
# Pass the golang vet check
vet: build
cd environment/dev && docker-compose run --rm $(SERVICE_NAME) /bin/bash -c 'go vet `go list ./... | grep -v vendor`'
# Execute unit tests
test:build
cd environment/dev && docker-compose run --rm $(SERVICE_NAME) /bin/bash -c 'go test `go list ./... | grep -v vendor` --tags="integration" -v'
# Generate required code (mocks...)
gogen: build
cd environment/dev && docker-compose run --rm $(SERVICE_NAME) /bin/bash -c 'go generate `go list ./... | grep -v vendor`'
# Build the production image
image: base
docker build \
--label revision=$(COMMIT) \
--label branch=$(BRANCH) \
-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