|
1 | 1 | export AWS_ACCESS_KEY_ID ?= test |
2 | 2 | export AWS_SECRET_ACCESS_KEY ?= test |
| 3 | +export AWS_DEFAULT_REGION=us-east-1 |
3 | 4 | SHELL := /bin/bash |
4 | 5 |
|
5 | | -include .env |
| 6 | +## Show this help |
| 7 | +usage: |
| 8 | + @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' |
6 | 9 |
|
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." |
9 | 27 |
|
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." |
12 | 33 |
|
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." |
15 | 40 |
|
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." |
19 | 49 |
|
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." |
27 | 55 |
|
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." |
31 | 61 |
|
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." |
34 | 67 |
|
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) |
37 | 72 |
|
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