Makefile Golang Deployment

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
.DEFAULT_GOAL := all

hello:
	@echo "_________________"
	@echo "| | ___________ |o|"
	@echo "| | ___________ | |"
	@echo "| | ___________ | |"
	@echo "| | ___________ | |"
	@echo "| |_____________| |"
	@echo "|     _______     |"
	@echo "|    |       |   ||"
	@echo "| DD |       |   V|"
	@echo "|____|_______|____|"
	@echo "         Your App"
	@echo "\r\n"

build:
	go build -o bin/app1 cmd/app1/app.go
	go build -o bin/app2 cmd/app2/app.go

clean:
	rm -f bin/app1
	rm -f bin/app2

run:
	nohup bin/app1 ENV=dev >> logs/app1.log 2>> logs/app1.err.log &
	nohup bin/app2 ENV=dev >> logs/app2.log 2>> logs/app2.err.log &

run_prod:
	nohup bin/app1 ENV=prod >> logs/app1.log 2>> logs/app1.err.log &
	nohup bin/app2 ENV=prod >> logs/app2.log 2>> logs/app2.err.log &

stop:
	pkill -SIGINT app1 &
	pkill -SIGINT app2 &

prod: hello clean build stop run_prod

all: hello clean build stop run

add to ~.zprofile

1
alias deploy_your_app='time ssh <ssh_server> "cd ~/<app> && git pull && make prod"'