-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
116 lines (106 loc) · 3.59 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
# ==============================================================================
# Ubuntu 20.04 (LTS) x64.
#================ enable root ssh login
# sudo su root
# passwd root
# nano /etc/ssh/sshd_config
# ## change “PermitRootLogin” to “yes”
# service sshd restart
#================ install rsync ===ubuntu 20.04 includes
# apt-get install rsync
#.envrc contains all the variable
include .envrc
# ==============================================================================
#SSH to remote
# ssh -i C:\\Users\\defiance\\.ssh\\gc\\id_rsa root@34.64.236.119
# apt-get install rsync
.PHONY:ssh-root
ssh-root:
ssh -i ${SSHKEYLOCATION} root@${REMOTE_IP}
.PHONY:ssh-user
ssh-user:
ssh ${USER}@${REMOTE_IP}
# ==============================================================================
# from scratch to deployed
#Upload script to Remote
#Exectue script
#Saving script as unix first
#Gaining permission to execute
#Execute script
.PHONY:deploy-script
deploy-script:
rsync -rP --delete ./remote/setup -e "ssh -i ${SSHKEYLOCATION}" root@${REMOTE_IP}:/root
ssh -i ${SSHKEYLOCATION} -t root@${REMOTE_IP} '\
vim /root/setup/01.sh +"set ff=unix" +wq \
chmod +x /root/setup/01.sh \
&& bash /root/setup/01.sh \
'
.PHONY:deploy-app
deploy-app:
@echo "deploy-backend"
make deploy-backend
@echo "deploy-frontend"
make deploy-frontend
@echo "deploy-api.service"
make deploy-api.service
@echo "deploy-caddyfile"
make deploy-caddyfile
@echo "deployment completed"
# ==============================================================================
#Deploy Go api to remote
.PHONY:deploy-backend
deploy-backend:
@echo "building Go binary "
make build-backend
@echo "make remote folder"
ssh -i ${SSHKEYLOCATION} root@${REMOTE_IP} mkdir -p /etc/www/backend/
@echo "copying Go from local to server"
rsync -rP --delete ./backend/app/bin/api -e "ssh -i ${SSHKEYLOCATION}" root@${REMOTE_IP}:/etc/www/backend/
@echo "gaining permission to api binary"
ssh -i ${SSHKEYLOCATION} -t root@${REMOTE_IP} '\
chmod u+x /etc/www/backend/api \
'
#Deploy React frontend to remote
.PHONY:deploy-frontend
deploy-frontend:
@echo "building frontend"
make build-frontend
@echo "make remote folder"
ssh -i ${SSHKEYLOCATION} root@${REMOTE_IP} mkdir -p /etc/www/frontend
@echo "copying React from local to server"
rsync -rP --delete ./frontend/build -e "ssh -i ${SSHKEYLOCATION}" root@${REMOTE_IP}:/etc/www/frontend
#Upload api.service and make it run in background
.PHONY:deploy-api.service
deploy-api.service:
rsync -P ./remote/production/api.service -e "ssh -i ${SSHKEYLOCATION}" root@${REMOTE_IP}:~
ssh -i ${SSHKEYLOCATION} -t root@${REMOTE_IP} '\
sudo mv ~/api.service /etc/systemd/system/ \
&& sudo systemctl enable api \
&& sudo systemctl restart api \
'
## production/configure/caddyfile: configure the production Caddyfile
.PHONY:deploy-caddyfile
deploy-caddyfile:
rsync -P ./remote/production/Caddyfile -e "ssh -i ${SSHKEYLOCATION}" root@${REMOTE_IP}:~
ssh -i ${SSHKEYLOCATION} -t root@${REMOTE_IP} '\
sudo mv ~/Caddyfile /etc/caddy/ \
&& sudo systemctl reload caddy \
&& reboot \
'
# ==============================================================================
# Building system
##backend Golang tidy
.PHONY:tidy
tidy:
(cd backend; go mod tidy)
(cd backend; go mod vendor)
## build-backend: build the Go backend binary and output to /bin/api
.PHONY: build-backend
build-backend:
@echo 'Building Go Binary...'
(cd backend/app; GOOS=linux GOARCH=amd64 go build -o=./bin/api . )
## build-frontend: build the React frontend
.PHONY: build-frontend
build-frontend:
@echo 'Building React File ...'
(cd frontend; npm install; npm run build)