From 4b4deff92e2d2a1080b47c7ef8f4af0fc18a5b76 Mon Sep 17 00:00:00 2001 From: Zoey de Souza Pessanha Date: Mon, 26 Jun 2023 12:40:29 -0300 Subject: [PATCH 1/6] adiciona secret key base para api --- config/config.exs | 4 +++- config/dev.exs | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/config/config.exs b/config/config.exs index 70b3aa1e..5ab38eab 100644 --- a/config/config.exs +++ b/config/config.exs @@ -65,7 +65,9 @@ config :tailwind, # ---------------------- # # Plataforma Digital API # # ---------------------- # -config :plataforma_digital_api, PlataformaDigitalAPI.Endpoint, server: false +config :plataforma_digital_api, PlataformaDigitalAPI.Endpoint, + secret_key_base: "p72JmdAzMY6LcSoQVEFDujKltZoaqCVTu5T5Fj/8PQzc079nuVa1kQfr4Z5lmJUE", + server: false # Configures Elixir's Logger config :logger, :console, diff --git a/config/dev.exs b/config/dev.exs index 077b73cb..4e0d1c9e 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -44,6 +44,9 @@ config :proxy_web, ProxyWeb.Endpoint, ] ] +config :plataforma_digital, PlataformaDigital.Endpoint, debug_errors: true +config :plataforma_digital_api, PlataformaDigitalAPI.Endpoint, debug_errors: true + # Do not include metadata nor timestamps in development logs config :logger, :console, format: "[$level] $message\n" From d2022709a0031f584df16ea60256073c28a4ff7e Mon Sep 17 00:00:00 2001 From: Zoey de Souza Pessanha Date: Thu, 20 Jul 2023 13:34:38 -0300 Subject: [PATCH 2/6] divide Dockerfile em prod e dev stages e atualiza doc --- .env-sample | 1 + .github/workflows/test.yml | 4 ++ Dockerfile | 41 ++++++++++++------ apps/cotacoes_etl/mix.exs | 1 - config/dev.exs | 2 +- config/test.exs | 12 ++++-- docker-compose.yml | 15 ++----- guides/local/docker.md | 85 ++++++++++++++++++++------------------ mix.exs | 1 + 9 files changed, 94 insertions(+), 68 deletions(-) diff --git a/.env-sample b/.env-sample index d820bdb7..746c4431 100644 --- a/.env-sample +++ b/.env-sample @@ -3,3 +3,4 @@ SECRET_KEY_BASE_API="WgrhapLJDAY2iJdga0rA+i46Cpx2KtJNBmOO8UNVMwWAqM8sNQaLCaR5DB6 DATABASE_USER="peapescarte" DATABASE_PASSWORD="peapescarte" +DATABASE_HOST="database" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 96f3d8c4..5c387ecc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,6 +10,8 @@ jobs: runs-on: ubuntu-latest env: MIX_ENV: test + DATABASE_USER: pescarte + DATABASE_PASSWORD: pescarte strategy: matrix: elixir: [1.14.2] @@ -67,6 +69,8 @@ jobs: runs-on: ubuntu-latest env: MIX_ENV: test + DATABASE_USER: pescarte + DATABASE_PASSWORD: pescarte strategy: matrix: elixir: [1.14.2] diff --git a/Dockerfile b/Dockerfile index 47ede6de..8886abe3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,12 +3,12 @@ FROM hexpm/elixir:1.14.5-erlang-25.3.2.4-debian-buster-20230612-slim as builder SHELL ["/bin/bash", "-o", "pipefail", "-c"] RUN apt-get update -y \ - && apt-get install -y --no-install-recommends build-essential curl inotify-tools \ + && apt-get install -y --no-install-recommends build-essential curl \ && curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \ && apt-get install -y --no-install-recommends nodejs \ && rm -rf /var/lib/apt/lists/* -WORKDIR /app +WORKDIR /pescarte RUN mix local.hex --force && \ mix local.rebar --force @@ -41,7 +41,6 @@ COPY config/config.exs config/${MIX_ENV}.exs config/ COPY apps/plataforma_digital/priv ./apps/plataforma_digital/priv COPY apps/plataforma_digital/assets ./apps/plataforma_digital/assets RUN ["npm", "ci", "--prefix", "./apps/plataforma_digital/assets/"] -RUN mix assets.deploy # copy source code and static files COPY apps/catalogo/lib ./apps/catalogo/lib @@ -65,13 +64,33 @@ RUN mix compile # Changes to config/runtime.exs don't require recompiling the code COPY config/runtime.exs config/ -COPY rel rel -RUN mix release +FROM builder as dev + +ARG MIX_ENV="dev" + +WORKDIR /pescarte + +RUN apt-get update -y && apt-get install -y --no-install-recommends inotify-tools + +COPY config/test.exs ./config/ +COPY /apps/cotacoes/test ./apps/cotacoes/test +COPY /apps/identidades/test ./apps/identidades/test +COPY /apps/modulo_pesquisa/test ./apps/modulo_pesquisa/test +COPY /apps/plataforma_digital/test ./apps/plataforma_digital/test +COPY /apps/plataforma_digital_api/test ./apps/plataforma_digital_api/test + +RUN mix deps.get +RUN mix do deps.compile, compile -FROM builder as runner +CMD ["mix", "phx.server"] + +FROM builder as production + +WORKDIR /pescarte +RUN chown nobody /pescarte RUN apt-get update -y -RUN apt-get install -y iputils-ping libstdc++6 inotify-tools \ +RUN apt-get install -y iputils-ping libstdc++6 \ openssl libncurses5 locales postgresql-client \ && rm -rf /var/lib/apt/lists/* \ && sed -i 's/^# *\(en_US.UTF-8\)/\1/' /etc/locale.gen \ @@ -81,14 +100,12 @@ ENV LANG en_US.UTF-8 ENV LANGUAGE en_US:en ENV LC_ALL en_US.UTF-8 -WORKDIR /pescarte -RUN chown nobody /pescarte - # set runner ENV ENV MIX_ENV="prod" -# Only copy the final release from the build stage -COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/pescarte ./ +COPY rel rel +RUN mix assets.deploy +RUN mix release && mv /pescarte/_build/${MIX_ENV}/rel/pescarte ./ USER nobody diff --git a/apps/cotacoes_etl/mix.exs b/apps/cotacoes_etl/mix.exs index 2f9c1861..e01057db 100644 --- a/apps/cotacoes_etl/mix.exs +++ b/apps/cotacoes_etl/mix.exs @@ -28,7 +28,6 @@ defmodule CotacoesETL.MixProject do {:finch, "~> 0.16"}, {:jason, ">= 1.0.0"}, {:ecto, "~> 3.10"}, - {:gen_stage, "~> 1.0"}, {:floki, "~> 0.34.0"}, {:explorer, "~> 0.5.0"}, {:unzip, "~> 0.8"}, diff --git a/config/dev.exs b/config/dev.exs index b26f5192..edee4eae 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -7,7 +7,7 @@ database = System.get_env("PG_DATABASE", "peapescarte") db_user = System.get_env("DATABASE_USER", "peapescarte") db_pass = System.get_env("DATABASE_PASSWORD", "peapescarte") # docker-compose service -hostname = System.get_env("DATABASE_HOST", "database") +hostname = System.get_env("DATABASE_HOST", "localhost") database_opts = [ username: db_user, diff --git a/config/test.exs b/config/test.exs index 752522d6..3164ec55 100644 --- a/config/test.exs +++ b/config/test.exs @@ -2,11 +2,17 @@ import Config config :database, ecto_repos: [Database.Repo] +database = System.get_env("PG_DATABASE", "peapescarte") +db_user = System.get_env("DATABASE_USER", "peapescarte") +db_pass = System.get_env("DATABASE_PASSWORD", "peapescarte") +# docker-compose service +hostname = System.get_env("DATABASE_HOST", "localhost") + database_opts = [ - username: System.get_env("DATABASE_USER", "pescarte"), - password: System.get_env("DATABASE_PASSWORD", "pescarte"), + username: db_user, + password: db_pass, + hostname: hostname, database: "peapescarte_test#{System.get_env("MIX_TEST_PARTITION")}", - hostname: "localhost", pool: Ecto.Adapters.SQL.Sandbox, pool_size: 10 ] diff --git a/docker-compose.yml b/docker-compose.yml index d0eada56..eb7f38c2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,15 +4,14 @@ services: pescarte: build: context: . - target: builder + target: dev args: - MIX_ENV=dev image: pescarte - command: [ "mix", "phx.server" ] + command: ["iex", "-S", "mix", "dev"] container_name: plataforma_pescarte ports: - 4000:4000 - - 4001:4001 depends_on: - database env_file: @@ -21,8 +20,8 @@ services: - .:/app environment: MIX_ENV: dev - networks: - - peapescarte + stdin_open: true + tty: true database: image: postgres:14.6 @@ -39,9 +38,3 @@ services: interval: 5s timeout: 2s retries: 1 - networks: - - peapescarte - -networks: - peapescarte: - driver: bridge diff --git a/guides/local/docker.md b/guides/local/docker.md index 4342a040..15777082 100644 --- a/guides/local/docker.md +++ b/guides/local/docker.md @@ -4,66 +4,79 @@ | requirement | release | | ------------------------------------------------------------- | -------- | -| [docker](https://docs.docker.com/get-docker/) | 20.10.8+ | -| [docker-compose](https://github.com/docker/compose/releases/) | 2.0.0+ | +| [docker](https://docs.docker.com/get-docker/) | 24.0.8+ | +| [docker-compose](https://github.com/docker/compose/releases/) | 2.19.0+ | --- ### Processo inicial -Antes de iniciar o processo de build dos containers no Docker, é necessário forçar a versão do -`DOCKER_BUILDKIT` e `COMPOSE_DOCKER_CLI_BUILD` para `0`, de forma que não haja erros neste -processo. Para facilitar essa configuração, defina essas variáveis na inicialização do seu shell, -ex: `~/.bash_profile`, `~/.zshrc`, `~/fish/config.fish` etc: +Como a opção padrão para executar o projeto é com `Nix`, você pode controlar as configurações do postgresql via variáveis de ambiente, caso execute apenas o container do projeto. Caso esteja usando `docker compose`, todas essas variáveis já são automaticamente configuradas: -```sh -DOCKER_BUILDKIT=0 -COMPOSE_DOCKER_CLI_BUILD=0 -``` +- `DATABASE_HOST` +- `DATABASE_PASSWORD` +- `DATABASE_USER` +- `PG_DATABASE` -Como a opçã̀o padrã̀o para executar o projeto é com `Nix`, é necessário criar um arquivo `local.secret.exs` na pasta `config` com o seguinte conteúdo: -```elixir -import Config +tanto nos ambiente de teste quanto para desenvolvimento. -config :pescarte, Pescarte.Repo, - hostname: "db" -``` - Em seguida, execute o build dos containers e obtenha as dependencias do `mix`. +Em seguida, execute o build dos containers. - docker-compose build - docker-compose run --rm pescarte mix deps.get +```console +$ docker compose build +``` -Depois, basta rodar o setup do banco de dados. +Depois, basta rodar o setup. + +```console +$ docker compose up +``` - docker-compose run --rm pescarte mix ecto.setup +Dessa forma, o setup do banco, bem como todas as dependências serão instaladas e compiladas. ### Sempre que for rodar o projeto - docker-compose up +```console +$ docker-compose up +``` + +Ou caso precise de um REPL interativo com `iex`: + +```console +$ docker compose run --rm pescarte +``` ### Para atualizar ou instalar novas dependências - docker-compose run --rm pescarte mix deps.get +```console +$ docker compose run --rm pescarte mix deps.get +``` ### Para executar migrações - docker-compose run --rm pescarte mix ecto.migrate +```console +$ docker compose run --rm pescarte mix ecto.migrate +``` ### Para reverter migrações - docker-compose run --rm pescarte mix ecto.rollback +```console +$ docker compose run --rm pescarte mix ecto.rollback +``` ### Para recriar o banco de dados - docker-compose run --rm pescarte mix ecto.reset +```console +$ docker compose run --rm pescarte mix ecto.reset +``` ### Portas expostas no sistema do host | container | port | | ------------- | ---- | -| pescarte | 4000 | -| db | 5432 | +| pescarte | 4000 | +| database | 5432 | --- @@ -71,16 +84,8 @@ Depois, basta rodar o setup do banco de dados. Para rodar os testes localmente execute o comando: - docker-compose run --rm pescarte mix test - -E para rodar todos os testes (`format`, `credo` e `test`) use: - - docker-compose run --rm pescarte mix ci - -É recomendável rodar os testes unitários sem efetuar a recriação do DB, pois o tempo de execução será -sempre menor. Porém, se o banco de testes ficar em um estado em que os dados presentes influenciem na -execução dos testes com sucesso, é recomendado recriá-lo. -Para recriar o banco de testes, rodar as seeds e os testes unitários -(`ecto.drop`, `ecto.create`, `ecto.migrate`, `seeds` e `test`) execute: +```console +$ docker compose run --rm pescarte mix test +``` - docker-compose run --rm pescarte mix test.reset +É recomendável rodar os testes unitários sem efetuar a recriação do DB, pois o tempo de execução será sempre menor. Porém, se o banco de testes ficar em um estado em que os dados presentes influenciem na execução dos testes com sucesso, é recomendado recriá-lo. diff --git a/mix.exs b/mix.exs index f2103c8a..3600b8cf 100644 --- a/mix.exs +++ b/mix.exs @@ -34,6 +34,7 @@ defmodule Pescarte.MixProject do defp aliases do [ + dev: ["setup", "phx.server"], setup: ["deps.get", "ecto.setup"], "ecto.setup": ["ecto.create", "ecto.migrate #{migrations_paths()}"], test: [ From 61fd821dfc67b1172d458437eded15c8d0c42588 Mon Sep 17 00:00:00 2001 From: douglastofoli Date: Thu, 27 Jul 2023 11:48:08 -0300 Subject: [PATCH 3/6] adicionado styles --- apps/plataforma_digital/assets/css/app.scss | 1 + .../pages/app/researcher/relatorio/anual.scss | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 apps/plataforma_digital/assets/css/pages/app/researcher/relatorio/anual.scss diff --git a/apps/plataforma_digital/assets/css/app.scss b/apps/plataforma_digital/assets/css/app.scss index 8be76233..982fb10f 100644 --- a/apps/plataforma_digital/assets/css/app.scss +++ b/apps/plataforma_digital/assets/css/app.scss @@ -176,6 +176,7 @@ footer { // Com autenticação @import "./pages/app/researcher/profile.scss"; @import "./pages/app/researcher/relatorio/mensal.scss"; +@import "./pages/app/researcher/relatorio/anual.scss"; // Páginas de Erros @import "./errors/404.scss"; diff --git a/apps/plataforma_digital/assets/css/pages/app/researcher/relatorio/anual.scss b/apps/plataforma_digital/assets/css/pages/app/researcher/relatorio/anual.scss new file mode 100644 index 00000000..0efb193c --- /dev/null +++ b/apps/plataforma_digital/assets/css/pages/app/researcher/relatorio/anual.scss @@ -0,0 +1,29 @@ +.yearly-report-wrapper { + @apply w-full; + + padding: 0 2.5rem; + overflow-y: scroll; + height: calc(100vh - $footer-height); + + > h1 { + margin: 2.5rem 0; + } + + > form .report-field { + height: max-content; + margin-bottom: 2.25rem; + + h3 { + margin-bottom: 0.75rem; + } + + textarea { + @apply w-full; + min-height: 12rem; + } + } + + button { + margin-bottom: 2rem; + } +} From 88ef5a598594b23b2c7e8038699d5b65bbb149c0 Mon Sep 17 00:00:00 2001 From: douglastofoli Date: Thu, 27 Jul 2023 11:49:02 -0300 Subject: [PATCH 4/6] =?UTF-8?q?adicionado=20rota=20para=20relat=C3=B3rio?= =?UTF-8?q?=20anual?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/plataforma_digital/lib/plataforma_digital/router.ex | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/plataforma_digital/lib/plataforma_digital/router.ex b/apps/plataforma_digital/lib/plataforma_digital/router.ex index 1c12694c..a863eb39 100644 --- a/apps/plataforma_digital/lib/plataforma_digital/router.ex +++ b/apps/plataforma_digital/lib/plataforma_digital/router.ex @@ -1,4 +1,5 @@ defmodule PlataformaDigital.Router do + alias PlataformaDigital.Researcher use PlataformaDigital, :router import PhoenixStorybook.Router @@ -43,6 +44,7 @@ defmodule PlataformaDigital.Router do scope "/relatorios" do live "/mensal", Researcher.Relatorio.MensalLive + live "/anual", Researcher.Relatorio.AnualLive end end end From bebbea52dc00fa3572245ddf5b2aed29b73ce569 Mon Sep 17 00:00:00 2001 From: douglastofoli Date: Thu, 27 Jul 2023 11:49:19 -0300 Subject: [PATCH 5/6] =?UTF-8?q?criado=20layout=20e=20adicionado=20compos?= =?UTF-8?q?=20do=20relat=C3=B3rio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../live/researcher/relatorio/anual_live.ex | 66 +++++++++++++++++++ .../researcher/relatorio/anual_live.html.heex | 15 +++++ 2 files changed, 81 insertions(+) create mode 100644 apps/plataforma_digital/lib/plataforma_digital/live/researcher/relatorio/anual_live.ex create mode 100644 apps/plataforma_digital/lib/plataforma_digital/live/researcher/relatorio/anual_live.html.heex diff --git a/apps/plataforma_digital/lib/plataforma_digital/live/researcher/relatorio/anual_live.ex b/apps/plataforma_digital/lib/plataforma_digital/live/researcher/relatorio/anual_live.ex new file mode 100644 index 00000000..5615ebe1 --- /dev/null +++ b/apps/plataforma_digital/lib/plataforma_digital/live/researcher/relatorio/anual_live.ex @@ -0,0 +1,66 @@ +defmodule PlataformaDigital.Researcher.Relatorio.AnualLive do + use PlataformaDigital, :auth_live_view + + import Timex.Format.DateTime.Formatter, only: [lformat!: 3] + + alias ModuloPesquisa.Models.RelatorioAnualPesquisa + + @locale "pt_BR" + + # Título de cada campo completo e os respectivos ids + @report_field_names [ + {"Plano de Trablho", :plano_de_trabalho}, + {"Resumo", :resumo}, + {"Introdução", :introducao}, + {"Embasamento Teórico", :embasamento_teorico}, + {"Resultados", :resultados}, + {"Atividades Acadêmicas", :atividades_academicas}, + {"Atividades Não Acadêmicas", :atividades_nao_academicas}, + {"Conclusão", :conclusao}, + {"Referências", :referencias} + ] + + @impl true + def mount(_, _, socket) do + # TODO: finalizar tela + relatorio_anual = + %RelatorioAnualPesquisa{} + |> Ecto.Changeset.change() + |> to_form(as: :relatorio_anual) + + {:ok, + socket + |> assign(field_names: @report_field_names) + |> assign(year: get_formatted_year(Date.utc_today())) + |> assign(form: relatorio_anual)} + end + + attr :form, :any, required: true + attr :label, :string, required: true + attr :id, :string, required: true + + defp report_field(assigns) do + ~H""" + <.text_area field={@form[@id]} class="report-field"> + <:label> + <.text size="h3" color="text-blue-100"> + <%= @label %> + + + + """ + end + + defp get_formatted_year(%Date{} = today) do + year = lformat!(today, "{YYYY}", @locale) + + %{year: year} + end + + # Events + + @impl true + def handle_event("save", _params, socket) do + {:noreply, socket} + end +end diff --git a/apps/plataforma_digital/lib/plataforma_digital/live/researcher/relatorio/anual_live.html.heex b/apps/plataforma_digital/lib/plataforma_digital/live/researcher/relatorio/anual_live.html.heex new file mode 100644 index 00000000..f2237698 --- /dev/null +++ b/apps/plataforma_digital/lib/plataforma_digital/live/researcher/relatorio/anual_live.html.heex @@ -0,0 +1,15 @@ +
+ <.text size="h1" color="text-blue-100"> + Relatório Mensal de Pesquisa do ano de <%= @year %> + + + <.form :let={f} for={@form} phx-submit="save"> + <.report_field :for={{name, id} <- @field_names} label={name} id={id} form={f} /> + + <.text size="h3" color="text-blue-100">Recursos + + <.button style="primary" submit> + Salvar + + +
From a2a787ecab3a1a369c11ba7bd1f8a49db3807dd2 Mon Sep 17 00:00:00 2001 From: Douglas Tofoli Date: Thu, 27 Jul 2023 18:01:43 +0000 Subject: [PATCH 6/6] Update apps/plataforma_digital/lib/plataforma_digital/live/researcher/relatorio/anual_live.ex Co-authored-by: Zoey de Souza Pessanha --- .../plataforma_digital/live/researcher/relatorio/anual_live.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/plataforma_digital/lib/plataforma_digital/live/researcher/relatorio/anual_live.ex b/apps/plataforma_digital/lib/plataforma_digital/live/researcher/relatorio/anual_live.ex index 5615ebe1..2548aa80 100644 --- a/apps/plataforma_digital/lib/plataforma_digital/live/researcher/relatorio/anual_live.ex +++ b/apps/plataforma_digital/lib/plataforma_digital/live/researcher/relatorio/anual_live.ex @@ -9,7 +9,7 @@ defmodule PlataformaDigital.Researcher.Relatorio.AnualLive do # Título de cada campo completo e os respectivos ids @report_field_names [ - {"Plano de Trablho", :plano_de_trabalho}, + {"Plano de Trabalho", :plano_de_trabalho}, {"Resumo", :resumo}, {"Introdução", :introducao}, {"Embasamento Teórico", :embasamento_teorico},