-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
123 lines (94 loc) · 3.55 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
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
113
114
115
116
117
118
119
120
121
122
123
# Define o diretório do ambiente virtual
VENV_DIR = .venv
# Define o nome do comando para o Python
PYTHON = python3
DOCKER_IMAGE_NAME = eml
REPO_NAME = $(DOCKER_IMAGE_NAME)
API_PORT = 8000
.PHONY: venv
venv:
@if [ ! -d "$(VENV_DIR)" ]; then \
echo "Criando o ambiente virtual..."; \
$(PYTHON) -m venv $(VENV_DIR); \
else \
echo "O ambiente virtual já existe."; \
fi
@if [ ! -d "artifacts" ]; then \
echo "Criando pasta para os artefatos (essa pasta não deve ser comitada!)..."; \
mkdir artifacts; \
else \
echo "A pasta de dados já existe."; \
fi
@if [ ! -d "/tmp/dvcstore" ]; then \
echo "Criando temporaria para dvc local (essa pasta não deve ser comitada!)..."; \
mkdir /tmp/dvcstore; \
else \
echo "A pasta temporaria do dvc já existe."; \
fi
## Atualiza as dependências no poetry, útil quando alterar bibliotecas em pyproject.toml
.PHONY: install-poetry
install-poetry: venv
@echo "Instalando o Poetry..."
$(VENV_DIR)/bin/pip install poetry
$(VENV_DIR)/bin/poetry config virtualenvs.in-project true
.PHONY: install-dependencies
install-dependencies: install-poetry
@echo "Instalando dependências com o Poetry..."
$(VENV_DIR)/bin/poetry install
.PHONY: install-pre-commit
install-pre-commit: install-dependencies
@echo "Instalando hooks de pre-commit"
$(VENV_DIR)/bin/poetry run pre-commit install --hook-type pre-push --hook-type post-checkout --hook-type pre-commit
## Prepara todo o repositório com o poetry e pre-commit
.PHONY: init
init: install-pre-commit
$(VENV_DIR)/bin/poetry run dvc remote add -f s3bucket s3://framework-eml-a3data/dvc/
$(VENV_DIR)/bin/poetry run dvc remote add -d -f myremote /tmp/dvcstore
## Remove todo o ambiente virtual e desconfigura o pre-commit
.PHONY: clean
clean:
@echo "Removendo pre-commit..."
$(VENV_DIR)/bin/poetry run pre-commit uninstall
$(VENV_DIR)/bin/poetry run pre-commit clean
@echo "Removendo poetry cache"
$(VENV_DIR)/bin/poetry cache clear --all -n .
@echo "Removendo o ambiente virtual..."
rm -rf $(VENV_DIR)
## Lint usando ruff (use `make format` para formatação)
.PHONY: lint
lint:
$(VENV_DIR)/bin/poetry run ruff check
## Formata o código fonte com ruff
.PHONY: format
format:
$(VENV_DIR)/bin/poetry run ruff format
.PHONY: build-batch-image
build-batch-image:
docker build -t $(DOCKER_IMAGE_NAME)-batch -f deployment/docker/Dockerfile.batch .
.PHONY: build-lambda-image
build-lambda-image:
docker build -t $(DOCKER_IMAGE_NAME)-lambda -f deployment/docker/Dockerfile.lambda .
## Inicia o batch localmente [Docker]
.PHONY: batch
batch: build-batch-image
@echo "Lançando o batch localmente..."
docker run $(DOCKER_IMAGE_NAME)-batch:latest
## Inicia o lambda localmente [Docker]
.PHONY: lambda
lambda: build-lambda-image
@echo "Lançando o lambda localmente..."
docker run -p 9000:8080 $(DOCKER_IMAGE_NAME)-lambda:latest
#################################################################################
# Self Documenting Commands #
#################################################################################
.DEFAULT_GOAL := help
define PRINT_HELP_PYSCRIPT
import re, sys; \
lines = '\n'.join([line for line in sys.stdin]); \
matches = re.findall(r'\n## (.*)\n[\s\S]+?\n([a-zA-Z_-]+):', lines); \
print('Comandos disponíveis:\n'); \
print('\n'.join(['{:25}{}'.format(*reversed(match)) for match in matches]))
endef
export PRINT_HELP_PYSCRIPT
help:
@$(PYTHON) -c "${PRINT_HELP_PYSCRIPT}" < $(MAKEFILE_LIST)