Skip to content

Commit b52da46

Browse files
authored
revamp the makefile target (#46)
1 parent 9757ea7 commit b52da46

File tree

1 file changed

+64
-25
lines changed

1 file changed

+64
-25
lines changed

Makefile

Lines changed: 64 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,77 @@
11
export AWS_ACCESS_KEY_ID ?= test
22
export AWS_SECRET_ACCESS_KEY ?= test
3+
export AWS_DEFAULT_REGION=us-east-1
34
SHELL := /bin/bash
45

5-
include .env
6+
## Show this help
7+
usage:
8+
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
69

7-
usage: ## Show this help
8-
@grep -F -h "##" $(MAKEFILE_LIST) | grep -F -v grep -F | sed -e 's/\\$$//' -e 's/##//'
10+
## Check if all required prerequisites are installed
11+
check:
12+
@command -v docker > /dev/null 2>&1 || { echo "Docker is not installed. Please install Docker and try again."; exit 1; }
13+
@command -v localstack > /dev/null 2>&1 || { echo "LocalStack is not installed. Please install LocalStack and try again."; exit 1; }
14+
@command -v aws > /dev/null 2>&1 || { echo "AWS CLI is not installed. Please install AWS CLI and try again."; exit 1; }
15+
@command -v awslocal > /dev/null 2>&1 || { echo "awslocal is not installed. Please install awslocal and try again."; exit 1; }
16+
@command -v python > /dev/null 2>&1 || { echo "Python is not installed. Please install Python and try again."; exit 1; }
17+
@command -v jq > /dev/null 2>&1 || { echo "jq is not installed. Please install jq and try again."; exit 1; }
18+
@echo "All required prerequisites are available."
19+
20+
## Install dependencies
21+
install:
22+
@echo "Installing dependencies..."
23+
pip install virtualenv
24+
virtualenv venv
25+
bash -c "source venv/bin/activate && pip install -r requirements-dev.txt"
26+
@echo "Dependencies installed successfully."
927

10-
install: ## Install dependencies
11-
@pip install -r requirements-dev.txt
28+
## Build the Lambda functions
29+
build-lambdas:
30+
@echo "Building the Lambda functions..."
31+
bash -c "source venv/bin/activate && bin/build_lambdas.sh"
32+
@echo "Lambda functions built successfully."
1233

13-
build: ## Build lambdas in the lambdas folder
14-
bin/build_lambdas.sh;
34+
## Deploy the application locally using `awslocal`, a wrapper for the AWS CLI
35+
deploy:
36+
@echo "Deploying the application..."
37+
@make build-lambdas
38+
deployment/awslocal/deploy.sh
39+
@echo "Application deployed successfully."
1540

16-
awslocal-setup: ## Deploy the application locally using `awslocal`, a wrapper for the AWS CLI
17-
$(MAKE) build
18-
deployment/awslocal/deploy.sh
41+
## Deploy the application locally using `tflocal`, a wrapper for the Terraform CLI
42+
deploy-terraform:
43+
@command -v terraform > /dev/null 2>&1 || { echo "Terraform is not installed. Please install Terraform and try again."; exit 1; }
44+
@which tflocal || pip install terraform-local
45+
@echo "Deploying the application..."
46+
@make build-lambdas
47+
deployment/tflocal/deploy.sh
48+
@echo "Application deployed successfully."
1949

20-
terraform-setup: ## Deploy the application locally using `tflocal`, a wrapper for Terraform CLI
21-
$(MAKE) build
22-
cd deployment/terraform; \
23-
tflocal init; \
24-
echo "Deploying Terraform configuration 🚀"; \
25-
tflocal apply --auto-approve; \
26-
echo "Paste the function URLs above to the WebApp 🎉";
50+
## Run tests locally
51+
test:
52+
@echo "Running tests..."
53+
bash -c "source venv/bin/activate && pytest tests"
54+
@echo "Tests completed successfully."
2755

28-
terraform-destroy: ## Destroy all resources created locally using terraform scripts
29-
cd deployment/terraform; \
30-
tflocal destroy --auto-approve;
56+
## Start LocalStack
57+
start:
58+
@echo "Starting LocalStack..."
59+
@LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) localstack start -d
60+
@echo "LocalStack started successfully."
3161

32-
start: ## Start the LocalStack Pro container in the detached mode
33-
@LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) localstack start -d
62+
## Stop LocalStack
63+
stop:
64+
@echo "Stopping LocalStack..."
65+
@localstack stop
66+
@echo "LocalStack stopped successfully."
3467

35-
stop: ## Stop the LocalStack Pro container
36-
localstack stop
68+
## Make sure the LocalStack container is up
69+
ready:
70+
@echo Waiting on the LocalStack container...
71+
@localstack wait -t 30 && echo LocalStack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1)
3772

38-
.PHONY: usage install build awslocal-setup terraform-setup terraform-destroy start stop
73+
## Save the logs in a separate file
74+
logs:
75+
@localstack logs > logs.txt
76+
77+
.PHONY: usage install start ready build-lambdas deploy test logs stop

0 commit comments

Comments
 (0)