-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
146 lines (120 loc) · 3.97 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
# This Makefile is an easy way to run common operations.
# Execute commands this:
# * make db-init
# * make api-dep
# * make api-dev
# * make nuxt-version
#
# Tip: Each command is run on its own line so you can't CD unless you
# connect commands together using operators. See examples:
# A; B # Run A and then B, regardless of success of A
# A && B # Run B if and only if A succeeded
# A || B # Run B if and only if A failed
# A & # Run A in background.
# Source: https://askubuntu.com/a/539293
#
# Tip: Use $(shell app param) syntax when expanding a shell return value.
# Load the shared environment variables (shared with docker-compose.yml).
include ${GOPATH}/.env
# Set local environment variables.
MYSQL_NAME=govueapp_db_1
GITHUB_USERNAME=josephspurrier
.PHONY: docker-build
docker-build:
# Build the docker images.
bash ${GOPATH}/bash/build-images.sh
.PHONY: ui-dep
ui-dep:
# Install the dependencies.
cd ${GOPATH}/src/app/ui && npm install
.PHONY: ui-dev
ui-dev:
# Start the UI.
cd ${GOPATH}/src/app/ui && npm run dev
.PHONY: ui-test
ui-test:
# Run the Jest UI tests.
cd ${GOPATH}/src/app/ui && npm test
.PHONY: api-dep
api-dep:
# Restore the dependencies. Get gvt if it's not found in $PATH.
which gvt || go get github.com/FiloSottile/gvt
cd ${GOPATH}/src/app/api && gvt restore
.PHONY: api-dev
api-dev:
# Start the API.
MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} go run ${GOPATH}/src/app/api/cmd/api/main.go
.PHONY: api-test
api-test:
# Run the Go tests.
cd ${GOPATH}/src/app/api && go test ./...
.PHONY: clean
clean:
# Remove binaries.
rm -rf ${GOPATH}/src/app/api/cmd/api/api
rm -rf ${GOPATH}/src/app/api/cmd/dbmigrate/dbmigrate
.PHONY: gvt-get
gvt-get:
# Download gvt.
go get github.com/FiloSottile/gvt
.PHONY: swagger-get
swagger-get:
# Download the Swagger generation tool.
go get github.com/go-swagger/go-swagger/cmd/swagger
.PHONY: swagger-gen
swagger-gen:
# Generate the swagger spec.
cd ${GOPATH}/src/app/api/cmd/api && \
swagger generate spec -o ${GOPATH}/src/app/api/static/swagger/swagger.json
# Replace 'example' with 'x-example' in the swagger spec.
## MacOS
sed -i '' -e 's/example/x\-example/' ${GOPATH}/src/app/api/static/swagger/swagger.json
## Linux
#sed -i'' -e 's/example/x\-example/' ${GOPATH}/src/app/api/static/swagger/swagger.json
# Validate the swagger spec.
swagger validate ${GOPATH}/src/app/api/static/swagger/swagger.json
# Serve the spec for the browser.
swagger serve -F=swagger ${GOPATH}/src/app/api/static/swagger/swagger.json
.PHONY: db-init
db-init:
# Launch database container.
docker run -d --name=${MYSQL_NAME} -p 3306:3306 -e MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} ${MYSQL_CONTAINER}
.PHONY: db-start
db-start:
# Start the stopped database container.
docker start ${MYSQL_NAME}
.PHONY: db-stop
db-stop:
# Stop the running database container.
docker stop ${MYSQL_NAME}
.PHONY: db-reset
db-reset:
# Drop the database, create the database, and perform the migrations.
docker exec ${MYSQL_NAME} sh -c "exec mysql -h 127.0.0.1 -uroot -p${MYSQL_ROOT_PASSWORD} -e 'DROP DATABASE IF EXISTS main;'"
docker exec ${MYSQL_NAME} sh -c "exec mysql -h 127.0.0.1 -uroot -p${MYSQL_ROOT_PASSWORD} -e 'CREATE DATABASE IF NOT EXISTS main DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;'"
go run ${GOPATH}/src/app/api/cmd/dbmigrate/main.go
.PHONY: db-rm
db-rm:
# Stop and remove the database container.
docker rm -f ${MYSQL_NAME}
.PHONY: nuxt-upgrade
nuxt-upgrade:
# Upgrade nuxt to the latest version.
cd ${GOPATH}/src/app/ui && npm upgrade nuxt
.PHONY: nuxt-version
nuxt-version:
# Output the version of nuxt.
${GOPATH}/src/app/ui/node_modules/.bin/nuxt --version
.PHONY: doc-dep
doc-dep:
# Install the doc dependencies.
cd ${GOPATH}/docs/website && npm install
.PHONY: doc-dev
doc-dev:
# Start the doc server.
cd ${GOPATH}/docs/website && npm start
.PHONY: doc-publish
doc-publish:
# Push the docs to GitHub pages.
cd ${GOPATH}/docs/website && \
GIT_USER=${GITHUB_USERNAME} CURRENT_BRANCH=master USE_SSH=true npm run publish-gh-pages