This repository has been archived by the owner on Sep 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
70 lines (56 loc) · 3.75 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
MAKEFILE_PATH = $(dir $(realpath -s $(firstword $(MAKEFILE_LIST))))
BUILD_DIR_PATH = ${MAKEFILE_PATH}/build
TEMPLATES_DIR_PATH = ${MAKEFILE_PATH}/pkg/templates
SCRIPTS_DIR_PATH = ${MAKEFILE_PATH}/scripts
CLI_BINARY_NAME=ec2-instance-qualifier
AGENT_BINARY_NAME=agent
APP_BINARY_NAME=ec2-instance-qualifier-app
GOOS ?= $(uname | tr '[:upper:]' '[:lower:]')
GOARCH ?= amd64
MASTER_TEMPLATE_VAR=github.com/awslabs/amazon-ec2-instance-qualifier/pkg/template.encodedMasterTemplate
LAUNCH_TEMPLATE_TEMPLATE_VAR=github.com/awslabs/amazon-ec2-instance-qualifier/pkg/template.encodedLaunchTemplateTemplate
AUTO_SCALING_GROUP_TEMPLATE_VAR=github.com/awslabs/amazon-ec2-instance-qualifier/pkg/template.encodedAutoScalingGroupTemplate
INSTANCE_TEMPLATE_VAR=github.com/awslabs/amazon-ec2-instance-qualifier/pkg/template.encodedInstanceTemplate
USER_DATA_TEMPLATE_VAR=github.com/awslabs/amazon-ec2-instance-qualifier/pkg/template.encodedUserData
CLOUDWATCH_AGENT_CONFIG_VAR=github.com/awslabs/amazon-ec2-instance-qualifier/pkg/setup.encodedCloudWatchAgentConfig
ENCODED_MASTER_TEMPLATE=$(shell cat ${TEMPLATES_DIR_PATH}/master.template | base64 | tr -d '\040\011\012\015')
ENCODED_LAUNCH_TEMPLATE_TEMPLATE=$(shell cat ${TEMPLATES_DIR_PATH}/launch-template.template | base64 | tr -d '\040\011\012\015')
ENCODED_AUTO_SCALING_GROUP_TEMPLATE=$(shell cat ${TEMPLATES_DIR_PATH}/auto-scaling-group.template | base64 | tr -d '\040\011\012\015')
ENCODED_INSTANCE_TEMPLATE=$(shell cat ${TEMPLATES_DIR_PATH}/instance.template | base64 | tr -d '\040\011\012\015')
ENCODED_USER_DATA_TEMPLATE=$(shell cat ${TEMPLATES_DIR_PATH}/user-data.template | base64 | tr -d '\040\011\012\015')
ENCODED_CLOUDWATCH_AGENT_CONFIG=$(shell cat ${TEMPLATES_DIR_PATH}/cloudwatch-agent-config.json | base64 | tr -d '\040\011\012\015')
$(shell mkdir -p ${BUILD_DIR_PATH} && touch ${BUILD_DIR_PATH}/_go.mod)
clean:
rm -rf ${BUILD_DIR_PATH}
rm -f ${MAKEFILE_PATH}/${AGENT_BINARY_NAME}
rm -f ${MAKEFILE_PATH}/test/e2e/testdata/*.tar.gz
rm -f ${MAKEFILE_PATH}/instance-qualifier-*.config
rm -rf ${MAKEFILE_PATH}/test/e2e/tmp
compile:
@echo ${MAKEFILE_PATH}
go build -tags="aeiq${GOOS}" -a -ldflags '-X "${MASTER_TEMPLATE_VAR}=${ENCODED_MASTER_TEMPLATE}" -X "${LAUNCH_TEMPLATE_TEMPLATE_VAR}=${ENCODED_LAUNCH_TEMPLATE_TEMPLATE}" -X "${AUTO_SCALING_GROUP_TEMPLATE_VAR}=${ENCODED_AUTO_SCALING_GROUP_TEMPLATE}" -X "${INSTANCE_TEMPLATE_VAR}=${ENCODED_INSTANCE_TEMPLATE}" -X "${USER_DATA_TEMPLATE_VAR}=${ENCODED_USER_DATA_TEMPLATE}" -X "${CLOUDWATCH_AGENT_CONFIG_VAR}=${ENCODED_CLOUDWATCH_AGENT_CONFIG}"' -o ${BUILD_DIR_PATH}/${CLI_BINARY_NAME} ${MAKEFILE_PATH}/cmd/cli/ec2-instance-qualifier.go
env GOOS=linux GOARCH=amd64 go build -o ${BUILD_DIR_PATH}/${AGENT_BINARY_NAME} ${MAKEFILE_PATH}/cmd/agent/agent.go
cp -p ${BUILD_DIR_PATH}/${AGENT_BINARY_NAME} ${MAKEFILE_PATH}/${AGENT_BINARY_NAME}
build: compile
app:
cd ${MAKEFILE_PATH}/test/app-for-e2e/cmd; \
env GOOS=linux GOARCH=amd64 go build -a -o ${BUILD_DIR_PATH}/${APP_BINARY_NAME} ec2-instance-qualifier-app.go
unit-test:
go test -bench=. ${MAKEFILE_PATH}/... -v -coverprofile=coverage_aeiq.out -covermode=atomic -outputdir=${BUILD_DIR_PATH}
cd ${MAKEFILE_PATH}/test/app-for-e2e; \
go test -bench=. ./... -v -coverprofile=coverage_app.out -covermode=atomic -outputdir=${BUILD_DIR_PATH}
e2e-test: build app
${MAKEFILE_PATH}/test/e2e/run-tests
readme-test:
${MAKEFILE_PATH}/test/readme-test/run-readme-spellcheck
license-test:
${MAKEFILE_PATH}/test/license-test/run-license-test.sh
go-report-card-test:
${MAKEFILE_PATH}/test/go-report-card-test/run-report-card-test.sh
shellcheck:
${MAKEFILE_PATH}/test/shellcheck/run-shellcheck
test: unit-test shellcheck readme-test license-test go-report-card-test e2e-test
fmt:
goimports -w ./ && gofmt -s -w ./
help:
@grep -E '^[a-zA-Z_-]+:.*$$' $(MAKEFILE_LIST) | sort