From 922c5359bec233097f9dbc54a13b0ecd335c6279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Paiva?= Date: Sat, 24 Feb 2024 20:12:38 -0300 Subject: [PATCH] chore: Adiciona Docker e comandos via Makefile --- Dockerfile | 15 ++++++ Makefile | 50 +++++++++++++++++++ docker-compose.yml | 11 ++++ requirements-dev.txt => requirements.txt | 0 tests/{test_cnh.py => test_CNH.py} | 1 + tests/{test_cnpj.py => test_CNPJ.py} | 1 + tests/{test_cns.py => test_CNS.py} | 1 + tests/{test_cpf.py => test_CPF.py} | 1 + tests/{test_certidao.py => test_Certidao.py} | 1 + tests/{test_pis.py => test_PIS.py} | 1 + tests/{test_renavam.py => test_RENAVAM.py} | 1 + ...ulo_eleitor.py => test_TituloEleitoral.py} | 1 + 12 files changed, 84 insertions(+) create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 docker-compose.yml rename requirements-dev.txt => requirements.txt (100%) rename tests/{test_cnh.py => test_CNH.py} (99%) rename tests/{test_cnpj.py => test_CNPJ.py} (99%) rename tests/{test_cns.py => test_CNS.py} (99%) rename tests/{test_cpf.py => test_CPF.py} (99%) rename tests/{test_certidao.py => test_Certidao.py} (99%) rename tests/{test_pis.py => test_PIS.py} (99%) rename tests/{test_renavam.py => test_RENAVAM.py} (99%) rename tests/{test_titulo_eleitor.py => test_TituloEleitoral.py} (99%) diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..aef5dd5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM python:3.12.1-slim + +# Virtual environment +RUN python3 -m venv /opt/venv +ENV PATH="/opt/venv/bin:$PATH" + +# Install requirements +# hadolint ignore=DL3013 +RUN pip3 install --no-cache-dir --upgrade pip +COPY requirements.txt /tmp/requirements.txt +RUN pip3 install --no-cache-dir --requirement /tmp/requirements.txt + +# Set environment variables +ENV WORKDIR=/app +WORKDIR ${WORKDIR} diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0f66a90 --- /dev/null +++ b/Makefile @@ -0,0 +1,50 @@ +# Variables +APP_NAME=app +ROOT=$(shell pwd) + +## Lint +DOCKER_IMAGE_LINTER=alvarofpp/linter:latest +LINT_COMMIT_TARGET_BRANCH=origin/main + +## Test +TEST_CONTAINER_NAME=${APP_NAME}_test + +# Commands +.PHONY: install-hooks +install-hooks: + git config core.hooksPath .githooks + +.PHONY: build +build: install-hooks + @docker compose build --pull + +.PHONY: build-no-cache +build-no-cache: install-hooks + @docker compose build --no-cache --pull + +.PHONY: lint +lint: + @docker pull ${DOCKER_IMAGE_LINTER} + @docker run --rm -v ${ROOT}:/app ${DOCKER_IMAGE_LINTER} " \ + lint-commit ${LINT_COMMIT_TARGET_BRANCH} \ + && lint-markdown \ + && lint-dockerfile \ + && lint-yaml \ + && lint-shell-script \ + && lint-python" + +.PHONY: test +test: + @docker compose run --rm -v ${ROOT}:/app \ + --name ${TEST_CONTAINER_NAME} ${APP_NAME} \ + pytest + +.PHONY: test-coverage +test-coverage: + @docker compose run --rm -v ${ROOT}:/app \ + --name ${TEST_CONTAINER_NAME} ${APP_NAME} \ + /bin/bash -c "coverage run -m unittest discover tests && coverage report -m" + +.PHONY: shell +shell: + @docker compose run --rm ${APP_NAME} bash diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5812f30 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +--- +version: '3.8' + +services: + app: + build: + context: . + image: alvarofpp/validate-docbr + container_name: validate-docbr + volumes: + - .:/app diff --git a/requirements-dev.txt b/requirements.txt similarity index 100% rename from requirements-dev.txt rename to requirements.txt diff --git a/tests/test_cnh.py b/tests/test_CNH.py similarity index 99% rename from tests/test_cnh.py rename to tests/test_CNH.py index 2f7b6d0..c9d38a1 100644 --- a/tests/test_cnh.py +++ b/tests/test_CNH.py @@ -1,4 +1,5 @@ import unittest + import validate_docbr as docbr diff --git a/tests/test_cnpj.py b/tests/test_CNPJ.py similarity index 99% rename from tests/test_cnpj.py rename to tests/test_CNPJ.py index e7a9450..1eea631 100644 --- a/tests/test_cnpj.py +++ b/tests/test_CNPJ.py @@ -1,4 +1,5 @@ import unittest + import validate_docbr as docbr diff --git a/tests/test_cns.py b/tests/test_CNS.py similarity index 99% rename from tests/test_cns.py rename to tests/test_CNS.py index 0288f29..c55921b 100644 --- a/tests/test_cns.py +++ b/tests/test_CNS.py @@ -1,4 +1,5 @@ import unittest + import validate_docbr as docbr diff --git a/tests/test_cpf.py b/tests/test_CPF.py similarity index 99% rename from tests/test_cpf.py rename to tests/test_CPF.py index 83fb47b..ffd9455 100644 --- a/tests/test_cpf.py +++ b/tests/test_CPF.py @@ -1,4 +1,5 @@ import unittest + import validate_docbr as docbr diff --git a/tests/test_certidao.py b/tests/test_Certidao.py similarity index 99% rename from tests/test_certidao.py rename to tests/test_Certidao.py index c038a7f..48458bd 100644 --- a/tests/test_certidao.py +++ b/tests/test_Certidao.py @@ -1,4 +1,5 @@ import unittest + import validate_docbr as docbr diff --git a/tests/test_pis.py b/tests/test_PIS.py similarity index 99% rename from tests/test_pis.py rename to tests/test_PIS.py index 5128b27..b4904d5 100644 --- a/tests/test_pis.py +++ b/tests/test_PIS.py @@ -1,4 +1,5 @@ import unittest + import validate_docbr as docbr diff --git a/tests/test_renavam.py b/tests/test_RENAVAM.py similarity index 99% rename from tests/test_renavam.py rename to tests/test_RENAVAM.py index 75a29aa..5d76187 100644 --- a/tests/test_renavam.py +++ b/tests/test_RENAVAM.py @@ -1,4 +1,5 @@ import unittest + import validate_docbr as docbr diff --git a/tests/test_titulo_eleitor.py b/tests/test_TituloEleitoral.py similarity index 99% rename from tests/test_titulo_eleitor.py rename to tests/test_TituloEleitoral.py index 985e832..b7f1c83 100644 --- a/tests/test_titulo_eleitor.py +++ b/tests/test_TituloEleitoral.py @@ -1,4 +1,5 @@ import unittest + import validate_docbr as docbr