diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 05bf6d7..4fb7146 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,29 +1,32 @@ workflow: name: 'CPF: $CPF' -image: selenium/standalone-chromium:126.0 - -# Change pip's cache directory to be inside the project directory since we can -# only cache local items. variables: PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" -# Pip's cache doesn't store the python packages -# https://pip.pypa.io/en/stable/reference/pip_install/#caching -# -# If you want to also cache the installed packages, you have to install -# them in a virtualenv and cache it as well. cache: paths: - .cache/pip + - .cache/pip3 - venv/ stages: + - build - coverage_report - relatorio +# Stage to build the Docker image +build: + stage: build + script: + - docker build -t chrome-with-selenium:latest . + artifacts: + paths: + - chrome-with-selenium.tar + when: always + before_script: - - python -V + - python3 -V - pip install virtualenv - virtualenv venv - source venv/bin/activate @@ -33,8 +36,9 @@ before_script: coverage_html: stage: coverage_report + image: chrome-with-selenium:latest script: - - python coverage_test.py + - python3 coverage_test.py - mkdir -p public/coverage_report - mv coverage_report public/coverage_report artifacts: @@ -47,8 +51,9 @@ coverage_html: relatorio: stage: relatorio + image: chrome-with-selenium:latest script: - - python ./ir.py --do check_environment_variables - # - python ./ir.py --do busca_trades_e_faz_merge_operacoes - - python ./ir.py --do calculo_ir --numero_de_meses 999 - retry: 2 + - python3 ./ir.py --do check_environment_variables + # - python3 ./ir.py --do busca_trades_e_faz_merge_operacoes + - python3 ./ir.py --do calculo_ir --numero_de_meses 999 + retry: 2 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f827074 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM python:3.10 + +# install google chrome +RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - +RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list' +RUN apt-get -y update +RUN apt-get install -y google-chrome-stable + +# install chromedriver +RUN apt-get install -yqq unzip +RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip +RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/ + +# set display port to avoid crash +ENV DISPLAY=:99 + +# upgrade pip +RUN pip install --upgrade pip + +# install selenium +RUN pip install selenium \ No newline at end of file diff --git a/Makefile b/Makefile index 97a59b3..325d733 100644 --- a/Makefile +++ b/Makefile @@ -15,11 +15,11 @@ reqs: pip freeze > requirements.txt coverage: - python coverage_test.py + python3 coverage_test.py test: pytest run: - - python ./ir.py --do importar_negociacoes - - python ./ir.py --do calculo_ir --numero_de_meses 99 + - python3 ./ir.py --do importar_negociacoes + - python3 ./ir.py --do calculo_ir --numero_de_meses 99 diff --git a/README.md b/README.md index 5c4a49c..eb5c0cd 100644 --- a/README.md +++ b/README.md @@ -21,10 +21,10 @@ - Configurar as variaveis de ambiente conforme (https://github.com/guilhermecgs/ir/blob/master/tests/test_environment_variables.py) - Voce pode executar tudo localmente e ver os resultados. Se quiser envio por email (SMTP), recomendo usar o https://elasticemail.com/ gratuitamente - Executar os comandos abaixo: - - python ./ir.py --do check_environment_variables - - python ./ir.py --do busca_trades_e_faz_merge_operacoes - - python ./ir.py --do calculo_ir - - python ./ir.py --do importar_negociacoes + - python3 ./ir.py --do check_environment_variables + - python3 ./ir.py --do busca_trades_e_faz_merge_operacoes + - python3 ./ir.py --do calculo_ir + - python3 ./ir.py --do importar_negociacoes ## exemplo do relatorio gerado no seu email @@ -56,7 +56,7 @@ Variáveis não definidas assumem os valores padrões definidos no arquivo `conf ![Exportar Negociações](imagens/exportar-negociacao.png) 2. Copie o arquivo exportado para pasta `importar` -3. Execute o comando para importar os arquivos: `python ./ir.py --do importar_negociacoes` +3. Execute o comando para importar os arquivos: `python3 ./ir.py --do importar_negociacoes` 4. Remova os arquivos da pasta `importar` ## disclaimer