Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
80 lines (65 loc) · 2.97 KB
/
Copy pathMakefile
File metadata and controls
80 lines (65 loc) · 2.97 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
.PHONY: tf-init tf-plan tf-apply tf-destroy tf-fmt tf-validate tf-write-web-env \
tf-enable-public-db tf-disable-public-db \
type-check format test test-unit test-integration deploy-layer deploy-api deploy deployWebsite
TF_DIR ?= infra/terraform
TF_CMD = terraform -chdir=$(TF_DIR)
AWS_PROFILE ?= Personal
AWS_REGION ?= eu-north-1
PYTHON ?= python3
PYLINTHOME ?= $(CURDIR)/.cache/pylint
# Terraform helpers
tf-write-web-env:
@$(PYTHON) scripts/write_web_env.py \
--tf-dir "$(TF_DIR)" \
--env-path "apps/web/.env" \
--aws-region "$(AWS_REGION)" \
--aws-profile "$(AWS_PROFILE)"
tf-enable-public-db:
@set -e; \
ACCOUNT_ID=$$(aws sts get-caller-identity --profile "$(AWS_PROFILE)" --query Account --output text); \
echo "Using AWS account ID $$ACCOUNT_ID"; \
$(TF_CMD) apply -var 'enable_public_db_access=true' -var "account_id=$$ACCOUNT_ID"
tf-disable-public-db:
@set -e; \
ACCOUNT_ID=$$(aws sts get-caller-identity --profile "$(AWS_PROFILE)" --query Account --output text); \
echo "Using AWS account ID $$ACCOUNT_ID"; \
$(TF_CMD) apply -var 'enable_public_db_access=false' -var "account_id=$$ACCOUNT_ID"
# Quality gates
type-check:
black --check apps/api
isort --check-only apps/api
@mkdir -p "$(PYLINTHOME)"
PYLINTHOME="$(PYLINTHOME)" PYTHONPATH=. pylint apps/api
ruff check apps/api
pyright apps/api
mypy apps/api
PYTHONPATH=. $(PYTHON) scripts/check_integration_function_coverage.py
format:
isort apps/api
black apps/api
test:
PYTHONPATH=. $(PYTHON) -m pytest apps/api/tests
test-unit:
PYTHONPATH=. $(PYTHON) -m pytest apps/api/tests --ignore=apps/api/tests/integration --no-cov
test-integration:
AWS_PROFILE="$(AWS_PROFILE)" AWS_REGION="$(AWS_REGION)" PYTHONPATH=. $(PYTHON) -m pytest apps/api/tests/integration --no-cov
deploy-layer:
$(MAKE) -C infra/layers build
cd infra/layers && npx serverless deploy
deploy-api:
cd infra/serverless && npx serverless deploy
deploy: deploy-layer deploy-api
deployWebsite:
@set -e; \
ACCOUNT_ID="$$(aws sts get-caller-identity --profile "$(AWS_PROFILE)" --query Account --output text)"; \
STATIC_SITE_DOMAIN="finance-tracker.casperkristiansson.com"; \
STATIC_SITE_BUCKET="$$(printf '%s' "$$STATIC_SITE_DOMAIN" | tr '.' '-')-$$ACCOUNT_ID"; \
CLOUDFRONT_DISTRIBUTION_ID="$$(aws cloudfront list-distributions --profile "$(AWS_PROFILE)" --query "DistributionList.Items[?Aliases.Items && contains(Aliases.Items, '$$STATIC_SITE_DOMAIN')].Id | [0]" --output text)"; \
if [ -z "$$CLOUDFRONT_DISTRIBUTION_ID" ] || [ "$$CLOUDFRONT_DISTRIBUTION_ID" = "None" ]; then \
echo "ERROR: Unable to resolve CloudFront distribution for $$STATIC_SITE_DOMAIN."; \
exit 1; \
fi; \
echo "Deploying to s3://$$STATIC_SITE_BUCKET (CloudFront $$CLOUDFRONT_DISTRIBUTION_ID)"; \
npm run build -w apps/web; \
aws s3 sync apps/web/dist s3://$$STATIC_SITE_BUCKET --delete --profile "$(AWS_PROFILE)" --region "$(AWS_REGION)"; \
aws cloudfront create-invalidation --distribution-id "$$CLOUDFRONT_DISTRIBUTION_ID" --paths "/*" --profile "$(AWS_PROFILE)"