-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathMakefile
More file actions
164 lines (126 loc) · 5.63 KB
/
Copy pathMakefile
File metadata and controls
164 lines (126 loc) · 5.63 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
PWD := $(shell pwd)
#
# Day-to-day usage commands
#
# Run server for local development
devserver: gobuild
GODEBUG=gctrace=1 COSR_DEBUG=1 ./build/cosr-front.bin
# Run server for production
runserver: gobuild
./build/cosr-front.bin
# Save all Go dependencies to the vendor/ directory
godep_save:
GO15VENDOREXPERIMENT=1 godep save -v ./server
# Checks if the container is out of date
docker_check:
@bash -c 'docker run -v "$(PWD):/go/src/github.com/commonsearch/cosr-front:ro" -t commonsearch/local-front sh -c "if diff -q /.cosr-front-dockerhash /go/src/github.com/commonsearch/cosr-front/.dockerhash > /dev/null; then echo \"Docker image is up to date\"; else echo \"\nWARNING: Your Docker image seems to be out of date! Please exit and do \\\"make docker_build\\\" again to avoid any issues.\n\"; fi"'
# Logins into the container
docker_shell: docker_check
docker run -e DOCKER_HOST --rm -v "$(PWD):/go/src/github.com/commonsearch/cosr-front:rw" -w /go/src/github.com/commonsearch/cosr-front -p 9700:9700 -i -t commonsearch/local-front bash
# Run server for local development in a container
docker_devserver: docker_check
docker run -e DOCKER_HOST --rm -v "$(PWD):/go/src/github.com/commonsearch/cosr-front:rw" -w /go/src/github.com/commonsearch/cosr-front -p 9700:9700 -i -t commonsearch/local-front make devserver
# Starts the local services needed by cosr-front
start_services:
docker run -e DOCKER_HOST -d -p 39200:9200 -p 39300:9300 commonsearch/local-elasticsearch
# Starts the local services needed by cosr-front with the devindex
start_services_devindex:
docker run -e DOCKER_HOST -d -p 39200:9200 -p 39300:9300 commonsearch/local-elasticsearch-devindex
# Stops local services
stop_services:
bash -c 'docker ps | tail -n +2 | grep -E "((commonsearch/local-elasticsearch))" | cut -d " " -f 1 | xargs docker stop -t=0'
#
# Tests & linting
#
# Lint everything
lint: jslint golint
# Lint and test everything
test: lint gotest
# Lint and test everything inside Docker
docker_test:
docker run -e DOCKER_HOST --rm -v "$(PWD):/go/src/github.com/commonsearch/cosr-front:rw" -w /go/src/github.com/commonsearch/cosr-front -i -t commonsearch/local-front make test
# Perform static checks on the Go code
# These dependencies are installed in the Dockerfile
# See new ideas at https://github.com/alecthomas/gometalinter
golint:
go fmt -n ./server/ | sed -e "s/gofmt -l/gofmt -s -l/g" | sh
golint ./server
test -z "$$(golint ./server)"
go tool vet -all -shadow ./server
aligncheck ./server
structcheck ./server
varcheck ./server
errcheck -ignoretests ./server
ineffassign ./server/
unconvert ./server/
gosimple ./server/
staticcheck ./server/
# Run Go tests
gotest:
COSR_TESTDATA=1 COSR_PATHFRONT="${PWD}" go test ./server
# Run Go benchmarks
gobench:
COSR_PATHFRONT="${PWD}" go test ./server -bench=. -benchtime=5s
# Static linting on the JS code
jslint:
jshint static/js/*.js
eslint static/js/index.js
java -jar tools/closure-compiler/compiler.jar --warning_level VERBOSE --summary_detail_level 3 --compilation_level ADVANCED --use_types_for_optimization --language_in ECMASCRIPT5_STRICT --js static/js/index.js > /dev/null
# Run local UI tests with PhantomJS
uitest:
wdio tests/wdio.conf.local.js
docker_uitest:
docker run -e DOCKER_HOST --rm -v "$(PWD):/go/src/github.com/commonsearch/cosr-front:rw" -w /go/src/github.com/commonsearch/cosr-front -i -t commonsearch/local-front make uitest
# Run UI tests on Sauce Labs
uitest_sauce:
wdio tests/wdio.conf.sauce.js
docker_uitest_sauce:
docker run -e DOCKER_HOST -e SAUCE_USERNAME -e SAUCE_ACCESS_KEY -e TRAVIS_BUILD_NUMBER --rm -v "$(PWD):/go/src/github.com/commonsearch/cosr-front:rw" -w /go/src/github.com/commonsearch/cosr-front -i -t commonsearch/local-front make uitest_sauce
#
# Build commands
#
# Lint then build everything
build: lint build_static
# Build static content, including images
build_static: minify
mkdir -p build/static/img
cp -R static/img build/static/
cp static/*.png static/*.ico build/static/
# Minify everything
minify: minify_js minify_css
# Minify the JavaScript code (will also do some more linting)
minify_js:
mkdir -p build/static/js/
# v20150315 is the last version that doesn't crash. TODO, report it!
# https://github.com/google/closure-compiler/wiki/Binary-Downloads
java -jar tools/closure-compiler/compiler.jar --warning_level VERBOSE --summary_detail_level 3 --compilation_level ADVANCED --use_types_for_optimization --language_in ECMASCRIPT5_STRICT --js_output_file build/static/js/index.js --js static/js/index.js
ls -la build/static/js/index.js
# Minify the CSS code
minify_css:
mkdir -p build/static/css/
cat static/css/global.css > build/static/css/index.scss
cat static/css/header.css >> build/static/css/index.scss
cat static/css/footer.css >> build/static/css/index.scss
cat static/css/hits.css >> build/static/css/index.scss
cat static/css/responsive.css >> build/static/css/index.scss
sass --scss build/static/css/index.scss build/static/css/index.css --style compressed --sourcemap=none --no-cache
rm build/static/css/index.scss
ls -la build/static/css/index.css
# Build the Go server code
gobuild:
mkdir -p build
go build -i -o build/cosr-front.bin ./server
# Build local Docker images
docker_build:
make docker_hash > .dockerhash
docker build -t commonsearch/local-front .
# Build a unique hash to indicate that a docker_build may be necessary again
docker_hash:
@sh -c 'cat Dockerfile tests/package.json | grep -vE "^\s*\#" | grep -vE "^\s*$$" | openssl md5'
# Pull Docker images from the registry
docker_pull:
docker version
docker info
docker pull commonsearch/local-front
docker pull commonsearch/local-elasticsearch
docker pull commonsearch/local-elasticsearch-devindex