-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile
More file actions
112 lines (91 loc) · 4.42 KB
/
Copy pathMakefile
File metadata and controls
112 lines (91 loc) · 4.42 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
.PHONY: verify check_upgrade plan apply extract_hcl2json
# Phases 1+2 of #352: extract the hcl2json Go binary from the vendored container once at
# setup time and place it at HCL2JSON_BIN. `scripts/installer/utils/extractors.py:hcl_to_json`
# execs the binary directly on supported hosts (linux/amd64 + linux/arm64), avoiding ~1-2s of
# per-call Docker startup. Unsupported hosts (Darwin until Phase 3) keep the runtime
# `docker run` fallback, so this recipe is a no-op for them.
#
# HCL2JSON_DIR is a project-namespaced subdirectory under /tmp so that hosts running a
# bwrap sandbox can mount it into the jail (the default sandbox configuration isolates
# /tmp itself, which would hide the binary from pytest running inside the sandbox).
HCL2JSON_DIR := /tmp/cx-installer
HCL2JSON_BIN := $(HCL2JSON_DIR)/hcl2json
HCL2JSON_IMAGE := ghcr.io/seqeralabs/cx-field-tools-installer/hcl2json:0.6-vendored-multiarch@sha256:ef5c94eddaf8c364c171f50de7ff22477d68ab787d080e9c43d5c6e0be01af3c
extract_hcl2json:
@arch="$$(uname -m)"; \
if [ "$$(uname -s)" = "Linux" ] && { [ "$$arch" = "x86_64" ] || [ "$$arch" = "aarch64" ] || [ "$$arch" = "arm64" ]; }; then \
if docker info >/dev/null 2>&1; then \
echo "Extracting hcl2json binary to $(HCL2JSON_BIN)."; \
mkdir -p $(HCL2JSON_DIR); \
cid=$$(docker create $(HCL2JSON_IMAGE)); \
docker cp $$cid:/hcl2json $(HCL2JSON_BIN) 2>/dev/null || docker cp $$cid:/usr/local/bin/hcl2json $(HCL2JSON_BIN); \
docker rm $$cid > /dev/null; \
chmod +x $(HCL2JSON_BIN); \
elif [ -x "$(HCL2JSON_BIN)" ]; then \
echo "extract_hcl2json: Docker unavailable; using existing binary at $(HCL2JSON_BIN)."; \
else \
echo "extract_hcl2json: Docker unavailable and no binary at $(HCL2JSON_BIN). Run 'make extract_hcl2json' from a host with Docker access first (the binary path can then be mounted into a sandbox)." >&2; \
exit 1; \
fi; \
else \
echo "extract_hcl2json: host $$(uname -s)/$$arch not covered by Phases 1-2; skipping (docker fallback will run at call time)."; \
fi
verify: extract_hcl2json
@echo "Verifying 'terraform.tfvars'."
@python3 scripts/installer/validation/check_configuration.py
verify-full: verify
@echo "Verifying with tfsec."
@tfsec
check_upgrade: extract_hcl2json
@echo "Checking 'terraform.tfvars' completeness against 'variables.tf'."
@python3 scripts/installer/validation/check_upgrade.py
plan: verify
@echo "Invoking 'terraform plan'"
@terraform plan
apply: verify
@echo "Invoking 'terraform apply'"
@terraform apply
destroy:
@python3 .githooks/check_destroy.py
@terraform destroy
## =============================================================================================================
## TESTING
## =============================================================================================================
# If this stage fails with exit status 2, renew AWS SSO credentials.
# MAKE_TF_QUALIFIER is used to pass a qualifier to the plan command (eg. target specific resource or variable)
generate_json_plan:
@echo "\nGenerating JSON representation of plan."
@rm -f tfplan
@rm -f tfplan.json
@terraform plan ${MAKE_TF_QUALIFIER} -out=tfplan > /dev/null 2>&1
@terraform show -json tfplan | jq . > tfplan.json
test_cleanse:
@rm tests/datafiles/base-overrides.auto.tfvars
@rm tests/datafiles/terraform.tfvars
@rm tests/datafiles/secrets/*.json
generate_test_data:
@echo "Generating test data."
@cp templates/TEMPLATE_terraform.tfvars tests/datafiles/terraform.tfvars
@cd tests/datafiles && ./generate_core_data.sh
run_tests_all: extract_hcl2json
@pytest -c tests/pytest.ini tests/
run_tests_core_only: extract_hcl2json
@pytest -c tests/pytest.ini tests/ -m "not testcontainer and not variable_validation and not logger"
run_tests_containers_only: extract_hcl2json
@pytest -c tests/pytest.ini tests/ -m "testcontainer"
run_tests_variables_only: extract_hcl2json
@pytest -c tests/pytest.ini tests/ -m "variable_validation"
run_tests_logger_only: extract_hcl2json
@pytest -c tests/pytest.ini tests/unit/logger -m "logger"
run_tests_core_and_containers: extract_hcl2json
@pytest -c tests/pytest.ini tests/ -m "not variable_validation and not logger"
run_tests_core_and_variables: extract_hcl2json
@pytest -c tests/pytest.ini tests/ -m "not testcontainer and not logger"
purge_cached_plans:
@cd tests/ && rm -rf .plan_cache
purge_cached_scenarios:
@cd tests/ && rm -rf .scenario_cache
purge_cache:
@echo "Purging testing caches"
@$(MAKE) purge_cached_scenarios
@$(MAKE) purge_cached_plans