-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
62 lines (53 loc) · 1.85 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
.DEFAULT_GOAL := run
SHELL := /bin/bash
APP ?= $(shell basename $$(pwd) | tr '[:upper:]' '[:lower:]')
COMMIT_SHA = $(shell git rev-parse HEAD)
.PHONY: help
## help: prints this help message
help:
@echo "Usage:"
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
.PHONY: build
## build: builds the application
build: clean
@echo "Building binary ..."
GOARCH=amd64 GOOS=linux go build -o ${APP}
.PHONY: clean
## clean: cleans up binary files
clean:
@echo "Cleaning up ..."
@go clean
.PHONY: test
## test: runs go test with the race detector
test:
@GOARCH=amd64 GOOS=linux go test -v -race ./...
.PHONY: init
## init: sets up go modules
init:
@echo "Setting up modules ..."
@go mod init 2>/dev/null; go mod tidy && go mod vendor
########################################################################################################################
####### docker/kubernetes related stuff ################################################################################
########################################################################################################################
.PHONY: image-login
## image-login: login to docker hub
image-login:
@export PATH="$$HOME/bin:$$PATH"
@echo $$DOCKER_PASS | docker login -u $$DOCKER_USER --password-stdin
.PHONY: image-build
## image-build: build docker image
image-build: build
@export PATH="$$HOME/bin:$$PATH"
docker build -t jamesclonk/${APP}:${COMMIT_SHA} .
.PHONY: image-publish
## image-publish: build and publish docker image
image-publish:
@export PATH="$$HOME/bin:$$PATH"
docker push jamesclonk/${APP}:${COMMIT_SHA}
docker tag jamesclonk/${APP}:${COMMIT_SHA} jamesclonk/${APP}:latest
docker push jamesclonk/${APP}:latest
.PHONY: image-run
## image-run: run docker image
image-run:
@export PATH="$$HOME/bin:$$PATH"
docker run --rm -p 3000:3000 jamesclonk/${APP}:${COMMIT_SHA}