-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
71 lines (57 loc) · 2.19 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
APP_NAME ?= nationguessr
.PHONY: clean
# Remove all processing artifacts, build files and cache files
clean:
rm -rf .ruff_cache/ .pytest_cache/
find . -type d -name '__pycache__' -exec rm -rf {} +
.PHONY: ci
# Full continuous integration pipeline
ci: lint test
.PHONY: lint
# Verify proper formatting for Python files
lint:
black --diff --check src/ tests/ scripts/ -q
ruff check .
.PHONY: format
# Automatic fix linting errors for all Python files
format:
black src/ tests/ scripts/ -q
ruff check --fix .
.PHONY: test
# Run all project test suites
test:
pytest tests/
.PHONY: requirements
# Export project dependencies for production container
requirements:
poetry export -f requirements.txt --only main --without-hashes --without-urls --output ./src/requirements.txt
.PHONY: serve
# Run Telegram bot script in polling mode
# Used solely for manual testing in a local environment
serve:
cd src && python main.py
.PHONY: check-docker
# Checks if Docker is installed on the machine, otherwise returns error code
check-docker:
@which docker >/dev/null || (echo "❌ Docker is not found on this machine" && exit 1)
.PHONY: check-aws
# Checks if AWS CLI is installed on the machine, otherwise returns error code
check-aws:
@which aws >/dev/null || (echo "❌ AWS CLI is not found on this machine" && exit 1)
.PHONY: image
# Build a Docker image for serverless deployment
image: check-docker
docker build -t $(APP_NAME) .
.PHONY: deploy
# Push production Docker image to the private ECR registry
deploy: check-docker check-aws image
@if [ -z "${VAR_AWS_REGION}" ]; then \
echo "❌ ECR region is not specified. Set it in the 'VAR_AWS_REGION' environment variable" && exit 1; \
fi
@if [ -z "${VAR_AWS_ACCOUNT_ID}" ]; then \
echo "❌ AWS account ID is not specified. Set it in the 'VAR_AWS_ACCOUNT_ID' environment variable" && exit 1; \
fi
@aws ecr get-login-password --region ${VAR_AWS_REGION} | \
docker login --username AWS --password-stdin ${VAR_AWS_ACCOUNT_ID}.dkr.ecr.${VAR_AWS_REGION}.amazonaws.com
@docker tag $(APP_NAME):latest ${VAR_AWS_ACCOUNT_ID}.dkr.ecr.${VAR_AWS_REGION}.amazonaws.com/$(APP_NAME):latest
@docker push ${VAR_AWS_ACCOUNT_ID}.dkr.ecr.${VAR_AWS_REGION}.amazonaws.com/$(APP_NAME):latest