-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
105 lines (88 loc) · 3.22 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
VENV ?= ./.venv-gcp-av
DOCKER_OK := $(shell type -P docker)
PYTHON_EXE ?= python
PYTHON_OK := $(shell type -P ${PYTHON_EXE})
PYTHON_VERSION := $(shell python -V | cut -d' ' -f2)
PYTHON_REQUIRED := $(shell cat .python-version)
TERRAFORM_OK := $(shell type -P terraform)
TERRAFORM_REQUIRED := $(shell cat .terraform-version)
CORRECT_TERRAFORM_INSTALLED := $(shell terraform -v | grep ${TERRAFORM_REQUIRED})
AMZ_LINUX_VERSION := 2
CWD := $(shell pwd)
check_docker:
@echo '********** Checking for docker installation *********'
ifeq ('$(DOCKER_OK)','')
$(error package 'docker' not found!)
else
@echo Found docker!
endif
check_terraform:
@echo '********** Checking for terraform installation *********'
ifeq ('$(TERRAFORM_OK)','')
$(error package 'terraform' not found!)
else
@echo Found terraform!
endif
@echo '*********** Checking for terraform version ***********'
ifeq ('', '$(CORRECT_TERRAFORM_INSTALLED)')
$(error incorrect version of terraform found. Expected '${TERRAFORM_REQUIRED}'!)
else
@echo Found terraform ${TERRAFORM_REQUIRED}
endif
check_python:
@echo '*********** Checking for Python installation ***********'
ifeq ('$(PYTHON_OK)','')
$(error python interpreter: '${PYTHON_EXE}' not found!)
else
@echo Found Python
endif
@echo '*********** Checking for Python version ***********'
ifneq ('$(PYTHON_REQUIRED)','$(PYTHON_VERSION)')
$(error incorrect version of python found: '${PYTHON_VERSION}'. Expected '${PYTHON_REQUIRED}'!)
else
@echo Found Python ${PYTHON_REQUIRED}
endif
setup_venv: check_python
@echo '**************** Creating virtualenv *******************'
${PYTHON_EXE} -m venv $(VENV)
${VENV}/bin/pip install --upgrade pip
${VENV}/bin/pip install -r requirements/requirements-local.txt
@echo '*************** Installation Complete ******************'
setup_terraform: check_terraform
@echo '****** Setting up terraform ******'
terraform init ./terraform
setup_git_hooks:
@echo '****** Setting up git hooks ******'
pre-commit install
install: check_docker setup_venv setup_terraform setup_git_hooks
test: check_python
find . -type f -name '*.pyc' -delete
${VENV}/bin/pytest ./functions
build_clamscan: check_docker
rm -rf ./build/clamscan_function.zip
docker run --rm -ti \
-v ${CWD}:/opt/app \
amazonlinux:$(AMZ_LINUX_VERSION) \
/bin/bash -c "cd /opt/app && ./scripts/build_clamscan_function.sh"
build_freshclam: check_docker
rm -rf ./build/freshclam_function.zip
docker run --rm -ti \
-v ${CWD}:/opt/app \
amazonlinux:$(AMZ_LINUX_VERSION) \
/bin/bash -c "cd /opt/app && ./scripts/build_freshclam_function.sh"
clean:
rm -rf ./build
rm -rf ./.terraform
rm -rf ${VENV}
terraform_init: check_terraform
terraform init ./terraform
terraform_fmt: check_terraform
terraform fmt -recursive ./terraform
terraform_validate: check_terraform
terraform validate -var-file ./terraform/terraform.tfvars ./terraform
terraform_plan: check_terraform
terraform plan -var-file ./terraform/terraform.tfvars ./terraform
terraform_apply: check_terraform
terraform apply -var-file ./terraform/terraform.tfvars ./terraform
terraform_destroy: check_terraform
terraform destroy -var-file ./terraform/terraform.tfvars ./terraform