Skip to content

Commit

Permalink
Merge pull request #10 from A3Data/feature/ajustes-pre-v0
Browse files Browse the repository at this point in the history
Feature/ajustes pre v0
  • Loading branch information
henrique-tostes-a3 authored Oct 14, 2024
2 parents f4a4e92 + 6ffe145 commit c02e2b2
Show file tree
Hide file tree
Showing 4 changed files with 306 additions and 164 deletions.
65 changes: 24 additions & 41 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ VENV_DIR = .venv

# Define o nome do comando para o Python
PYTHON = python3
DOCKER_IMAGE_NAME = eml-api
DOCKER_IMAGE_NAME = eml
REPO_NAME = $(DOCKER_IMAGE_NAME)
AWS_REGION = us-east-1
ACCOUNT_ID = $(shell aws sts get-caller-identity --query Account --output text)
REPO_URI = $(ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/$(REPO_NAME)
API_PORT = 8000
TERRAFORM_BUCKET = eml-terraform-bucket-$(ACCOUNT_ID)


.PHONY: venv
venv:
Expand All @@ -32,29 +29,34 @@ venv:
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:
Expand All @@ -66,61 +68,42 @@ clean:
@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

## Builda a imagem docker da API
.PHONY: build-image
build-image:
docker build -t $(DOCKER_IMAGE_NAME) -f deployment/docker/Dockerfile .

.PHONY: build-api-image
build-api-image:
docker build -t $(DOCKER_IMAGE_NAME)-api -f deployment/docker/Dockerfile.api .


.PHONY: create-ecr
create-ecr:
chmod +x deployment/scripts/create_ecr.sh
./deployment/scripts/create_ecr.sh $(REPO_NAME) $(AWS_REGION)
.PHONY: build-batch-image
build-batch-image:
docker build -t $(DOCKER_IMAGE_NAME)-batch -f deployment/docker/Dockerfile.batch .

## Faz o push da última versão da imagem para o repositório ECR
.PHONY: push-image
push-image: create-ecr
docker tag "$(DOCKER_IMAGE_NAME):latest" "$(REPO_URI):latest"
aws ecr get-login-password --region "$(AWS_REGION)" | docker login --username AWS --password-stdin "$(REPO_URI)"
docker push "$(REPO_URI):latest"

## Inicia a API localmente
## Inicia a API localmente [Docker]
.PHONY: api
api: build-image
api: build-api-image
@echo "Lançando a API localmente..."
docker run -p $(API_PORT):$(API_PORT) $(DOCKER_IMAGE_NAME):latest


.PHONY: create-bucket
create-bucket:
@aws s3api head-bucket --bucket $(TERRAFORM_BUCKET) 2>/dev/null || \
(aws s3api create-bucket --bucket $(TERRAFORM_BUCKET) --region $(AWS_REGION); \
echo "Bucket $(TERRAFORM_BUCKET) criado.")
docker run -p $(API_PORT):$(API_PORT) $(DOCKER_IMAGE_NAME)-api:latest

## Cria toda a infraestrutura do deploy da API, desconsiderando a parte do Docker
.PHONY: create-infra
create-infra: create-bucket
terraform -chdir="deployment/infrastructure/terraform" init -backend-config="bucket=$(TERRAFORM_BUCKET)" -backend-config="region=$(AWS_REGION)"
terraform -chdir="deployment/infrastructure/terraform" apply -auto-approve

## Faz todo o deploy, desde de construir a imagem docker até provisionar toda infraestrutura
.PHONY: deploy
deploy: build-image push-image create-infra
## Inicia o batch localmente [Docker]
.PHONY: batch
batch: build-batch-image
@echo "Lançando o batch localmente..."
docker run $(DOCKER_IMAGE_NAME)-batch:latest

## Deleta toda infraestrutura provisionada anteriormente
.PHONY: destroy
destroy:
terraform -chdir="deployment/infrastructure/terraform" destroy -auto-approve

#################################################################################
# Self Documenting Commands #
Expand Down
Loading

0 comments on commit c02e2b2

Please sign in to comment.