-
Notifications
You must be signed in to change notification settings - Fork 113
/
Makefile
295 lines (236 loc) · 10.8 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
ifneq ("$(wildcard ../../Makefile.common_go)", "")
include ../../Makefile.common_go
endif
PACKAGE_PATH = github.com/chef/automate/components/automate-deployment
CHEF_AUTOMATE_PKG = github.com/chef/automate/components/automate-cli/cmd/chef-automate
AUTOMATE_CTL_PKG = ${PACKAGE_PATH}/cmd/automate-ctl
CS_CTL_PKG = ${PACKAGE_PATH}/cmd/chef-server-ctl
PGDUMP_PKG = ${PACKAGE_PATH}/cmd/pg_dump
BINS = ${CHEF_AUTOMATE_PKG} ${PACKAGE_PATH}/cmd/deployment-service
GIT_SHA = $(shell git rev-parse HEAD)
BUILD_TIME ?= $(shell date -u '+%Y%m%d%H%M%S')
VERSION = ${BUILD_TIME}
GO_LDFLAGS = --ldflags "-X ${LIBRARY_PATH}/version.Version=${BUILD_TIME} -X ${LIBRARY_PATH}/version.GitSHA=${GIT_SHA} -X ${LIBRARY_PATH}/version.BuildTime=${BUILD_TIME}"
LINTERARGS=--exclude-use-default -D lll ./...
LICENSE_TOKEN = $(shell cat ${REPOROOT}/dev/license.jwt)
RESULT_DIR = ${REPOROOT}/results
build: ${BINS}
proto:
cd ../../ && hab studio run 'source .studiorc; compile_go_protobuf_component automate-deployment'
package: habitat
mkdir -p results
cd ../.. && hab studio run "source .studiorc; build components/automate-deployment"
run: guard-HAB_ORIGIN
@echo "Starting deployment service with --hartifacts=${RESULT_DIR} and --override-origin=${HAB_ORIGIN}..."
./bin/linux/chef-automate deploy \
--hartifacts ${RESULT_DIR} \
--override-origin ${HAB_ORIGIN} \
--channel dev \
--upgrade-strategy none \
--admin-password chefautomate \
--accept-terms-and-mlsa
./bin/linux/chef-automate license apply ${LICENSE_TOKEN}
run-with-stress: guard-HAB_ORIGIN
@echo "Starting deployment service with --hartifacts=${RESULT_DIR} and --override-origin=${HAB_ORIGIN}..."
./bin/linux/chef-automate deploy \
--enable-deploy-order-stress-mode \
--hartifacts ./results \
--hartifacts ${RESULT_DIR} \
--channel dev \
--upgrade-strategy none \
--admin-password chefautomate \
--accept-terms-and-mlsa
./bin/linux/chef-automate license apply ${LICENSE_TOKEN}
run-with-cs: guard-HAB_ORIGIN
@echo "Starting deployment service with --enable-chef-server --hartifacts=${RESULT_DIR} and --override-origin=${HAB_ORIGIN}..."
./bin/linux/chef-automate deploy \
--enable-chef-server \
--hartifacts ${RESULT_DIR} \
--override-origin ${HAB_ORIGIN} \
--channel dev \
--upgrade-strategy none \
--admin-password chefautomate \
--accept-terms-and-mlsa
./bin/linux/chef-automate license apply ${LICENSE_TOKEN}
run-upgrade-self-test: guard-HAB_ORIGIN
@echo "Starting deployment service with --hartifacts=${RESULT_DIR} and --override-origin=${HAB_ORIGIN}..."
./bin/linux/chef-automate migrate-from-v1 \
--hartifacts ${RESULT_DIR} \
--override-origin ${HAB_ORIGIN} \
--channel dev \
--upgrade-strategy none \
--admin-password chefautomate \
--self-test \
--yes \
--enable-chef-server
./bin/linux/chef-automate license apply ${LICENSE_TOKEN}
ci: clean build unit lint fmt-check
${BINS}: bin echo-build-data
@echo "GO $@"
@cd bin; go build $@
echo-build-data:
@echo "build_time: ${BUILD_TIME}"
@echo " git_sha: ${GIT_SHA}"
@echo " version: ${VERSION}"
mocks:
@echo "Regenerating mocks..."
cd pkg/target && mockery -name=Target -case=underscore -inpkg -recursive
cd pkg/events && mockery -name=EventSender -case underscore -inpkg -recursive
cd ../../lib/platform/pg && mockery -name=DB -case underscore -inpkg -recursive
bin:
mkdir -p bin
clean:
rm -rf bin/*
# Old data file
rm -f ${RESULTS_DIR}/*deployment-service*.hart
rm -f cover/*.coverage.out
rm -f cover/cover.out
unit: golang_version_check
@go test ./...
cover: golang_version_check
@mkdir -p cover
@go test -coverprofile=cover/cover.out ./...
@echo "Coverage report written to cover/cover.out"
@echo "To view:"
@echo ""
@echo " go tool cover -html=cover/cover.out"
# https://stackoverflow.com/questions/4728810/makefile-variable-as-prerequisite
guard-%:
@ if [ "${${*}}" = "" ]; then \
echo "Environment variable $* not set"; \
exit 1; \
fi
HAVE_HABITAT := $(shell command -v hab 2> /dev/null)
habitat:
ifndef HAVE_HABITAT
$(error "habitat not found on PATH. Please install habitat")
endif
# cross compilation targets
cross: linux darwin windows
# NB: the automate-ctl and pg_dump we create here are mock implementations used for testing.
CTL_EXE = automate-ctl
CS_CTL_EXE = chef-server-ctl
PGDUMP_EXE = pg_dump
linux darwin windows: OPTS = GOOS=$@ GOARCH=amd64
linux darwin windows:
@make -f ../automate-cli/Makefile $@
@echo Building ${CTL_EXE} for $@
mkdir -p bin/$@
cd bin/$@; \
${OPTS} go build ${GO_LDFLAGS} ${AUTOMATE_CTL_PKG}
@echo Done: bin/$@/${AUTOMATE_CTL_PKG}
@echo Building ${PGDUMP_EXE} for $@
cd bin/$@; \
${OPTS} go build ${GO_LDFLAGS} ${PGDUMP_PKG}
@echo Done: bin/$@/${PGDUMP_PKG}
@echo Building ${CS_CTL_EXE} for $@
mkdir -p bin/$@
cd bin/$@; \
${OPTS} go build ${GO_LDFLAGS} ${CS_CTL_PKG}
@echo Done: bin/$@/${CS_CTL_PKG}
tools:
mkdir -p bin/linux && cd bin/linux && GOOS=linux GOARCH=amd64 go build ../../tools/upgrade-test-scaffold/upgrade-test-scaffold.go
generate: update-bindings do_generate fmt
do_generate:
go generate ./...
automate-ctl:
mkdir -p bin/automate-ctl
cd bin/automate-ctl; \
go build -o automate-ctl -i ../../cmd/automate-ctl
update-bindings:
bash ./scripts/agg_bindings.sh
check-bindings:
@bash ./scripts/agg_bindings.sh -n
destroy:
systemctl stop chef-automate
pkill chef-automate || true
rm -rf /hab/sup
rm -rf /hab/svc
rm -rf /hab/user
userdel hab || true
HAB_AUTH_TOKEN?=$(shell go env HAB_AUTH_TOKEN)
hab-auth-token:
ifeq (${HAB_AUTH_TOKEN},)
$(error "HAB_AUTH_TOKEN not set; do this: https://www.habitat.sh/docs/using-builder/#generate-an-access-token")
endif
# The a1-migration runs in a docker container. Unfortunately our
# preflight checks recommend sysctls that are not yet namespaced, so
# these commands must be run on the host:
a1-migration-host-setup:
sysctl -w fs.file-max=64000
sysctl -w vm.max_map_count=262144
sysctl -w vm.dirty_ratio=15
sysctl -w vm.dirty_expire_centisecs=20000
sysctl -w vm.dirty_background_ratio=35
a1-migration-hab-keys:
mkdir -p a1-migration/hab_keys
ifeq ("$(wildcard a1-migration/hab_keys/devchef*)","")
cp ~/.hab/cache/keys/devchef* a1-migration/hab_keys/
endif
a1-migration-build: guard-HAB_ORIGIN
docker build --build-arg AUTOMATE_CHANNEL=stable --build-arg AUTOMATE_VERSION=1.8.38 -m 4gb -t chef/a1-migration a1-migration
a1-migration-push:
docker push chef/a1-migration
a1-migration-up: guard-HAB_ORIGIN
cd a1-migration && docker-compose up -d && docker-compose exec a1-migration "a1-migration/run.sh"
a1-migration-down:
cd a1-migration && docker-compose down
a1-migration-shell:
cd a1-migration && docker-compose exec a1-migration /bin/bash
a1-migration-migrate: guard-HAB_ORIGIN
cd a1-migration && docker-compose exec a1-migration bash -c 'HAB_ORIGIN=${HAB_ORIGIN} HARTIFACT_DIR=${HARTIFACT_DIR} /a1-migration/run_migrate_from_a1.sh'
AUTOMATE_API_DEFAULT_PASSWORD?=$(shell awk '/Admin password:/{print $$3}' a1-migration/keys/enterprise-test-admin-login-creds)
A1_BUILDER_PASSWORD?=$(shell awk '/Builder Password:/{print $$3}' a1-migration/keys/enterprise-test-admin-login-creds)
a1-migration-test:
cd a1-migration && docker-compose exec a1-migration \
env HAB_LICENSE=accept-no-persist AUTOMATE_API_DEFAULT_PASSWORD=${AUTOMATE_API_DEFAULT_PASSWORD} \
A1_BUILDER_PASSWORD=${A1_BUILDER_PASSWORD} \
inspec exec /a2/inspec/a2-migrate-from-v1-integration/
a1-migration-gather-logs:
cd a1-migration && mkdir -p logs && docker-compose exec a1-migration bash -c "cd /a1-migration/logs && journalctl -u chef-automate > journal.log; chef-server-ctl gather-logs; automate-ctl gather-logs"
a1-migration-logs:
cd a1-migration && docker-compose logs -f --tail=20
a1-migration-load-sample-data:
cd a1-migration && docker-compose exec a1-migration /a1-migration/load-artifact
a1-migration-create-full-artifact: a1-migration-hab-keys
cd a1-migration && docker-compose exec a1-migration bash -c 'HAB_ORIGIN=devchef /a1-migration/create_artifact.sh full'
a1-migration-create-minimal-artifact: a1-migration-hab-keys
cd a1-migration && docker-compose exec a1-migration bash -c 'HAB_ORIGIN=devchef /a1-migration/create_artifact.sh minimal'
a1-migration-upload-artifact: hab-auth-token
cd a1-migration && docker-compose exec a1-migration bash -c 'HAB_ORIGIN=devchef HAB_AUTH_TOKEN=${HAB_AUTH_TOKEN} hab pkg upload /a1-migration/results/*.hart'
basic-a1-build: guard-HAB_ORIGIN
cp a1-migration/{delivery.license,internal_users.tsv,linux-patch-baseline-0.3.0.tar.gz} basic-a1/
docker build --build-arg AUTOMATE_CHANNEL=stable --build-arg AUTOMATE_VERSION=1.8.38 -m 4gb -t devchef/basic-a1 basic-a1
basic-a1-start-chef-server:
cd basic-a1 && docker-compose run --rm start_chef_server
basic-a1-up: guard-HAB_ORIGIN
cd basic-a1 && docker-compose up -d && docker-compose exec basic-a1 "basic-a1/run.sh"
basic-a1-reconfigure-chef-server:
cd basic-a1 && docker-compose exec chef-server chef-apply /volumes/keys/extra.rb
basic-a1-down: guard-HAB_ORIGIN
cd basic-a1 && docker-compose down
basic-a1-migrate: guard-HAB_ORIGIN
cd basic-a1 && docker-compose exec basic-a1 /basic-a1/chef-automate migrate-from-v1 --channel dev --upgrade-strategy none --yes --skip-backup-check --override-origin ${HAB_ORIGIN} --hartifacts /a2/results
basic-a1-diagnostics:
cd basic-a1 && docker-compose exec basic-a1 /basic-a1/chef-automate diagnostics run
basic-a1-do-all: guard-HAB_ORIGIN basic-a1-build basic-a1-start-chef-server basic-a1-up basic-a1-reconfigure-chef-server basic-a1-migrate basic-a1-diagnostics basic-a1-test
basic-a1-gather-logs:
cd basic-a1 && mkdir -p logs && docker-compose exec basic-a1 bash -c "cd /basic-a1/logs && journalctl -u chef-automate > journal.log; automate-ctl gather-logs"
basic_a1_automate_api_password?=$(shell awk '/Admin password:/{print $$3}' ./basic-a1/enterprise-test-admin-login-creds)
basic_a1_builder_password?=$(shell awk '/Builder Password:/{print $$3}' ./basic-a1/enterprise-test-admin-login-creds)
basic-a1-test:
cd basic-a1 && docker-compose exec basic-a1 \
env HAB_LICENSE=accept-no-persist AUTOMATE_API_DEFAULT_PASSWORD=${basic_a1_automate_api_password} \
A1_BUILDER_PASSWORD=${basic_a1_builder_password} \
NO_WORKFLOW_TEST=true \
inspec exec /a2/inspec/a2-migrate-from-v1-integration/
.DEFAULT_GOAL := build
.PHONY: ${BINS} build proto clean cover tools
.PHONY: debugger mocks automate-ctl
.PHONY: cross darwin linux windows
.PHONY: echo-build-data destroy
.PHONY: hab-auth-token a1-migration-hab-keys
.PHONY: a1-migration-build a1-migration-push a1-migration-up a1-migration-down a1-migration-shell
.PHONY: a1-migration-logs a1-migration-create-artifact a1-migration-upload-artifact
.PHONY: basic-a1-chef-server-build basic-a1-build basic-a1-start-chef-server basic-a1-up basic-a1-down
.PHONY: basic-a1-migrate basic-a1-do-all basic-a1-diagnostics basic-a1-gather-logs basic-a1-reconfigure-chef-server