diff --git a/.dockerignore b/.dockerignore index 18c84d0f47..7f725ae0fe 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,7 +1,8 @@ -/.github -/.pgdata/ /_build/ /assets/node_modules/ /deps/ +/doc/ /priv/static/assets +/test/ /tmp/ +/.pgdata/ \ No newline at end of file diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a394dbb4ad..f7c0646e3e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -121,10 +121,10 @@ jobs: postgres: image: postgres env: - POSTGRES_HOST_AUTH_METHOD: trust + POSTGRES_PASSWORD: postgres POSTGRES_DB: trento_test ports: - - 5432:5432 + - 5433:5432 # Set health checks to wait until postgres has started options: >- --health-cmd pg_isready @@ -180,10 +180,10 @@ jobs: postgres: image: postgres env: - POSTGRES_HOST_AUTH_METHOD: trust + POSTGRES_PASSWORD: postgres POSTGRES_DB: trento_dev ports: - - 5432:5432 + - 5433:5432 # Set health checks to wait until postgres has started options: >- --health-cmd pg_isready diff --git a/.tool-versions b/.tool-versions index 85f7b8d4af..6c8604f73f 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,3 +1,2 @@ elixir 1.13.1-otp-24 -erlang 24.3.3 -nodejs 16.14.1 +erlang 24.3.3 \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9697d630b4..ff04545104 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,10 +2,6 @@ We're really glad you're reading this, because we need volunteer developers to help this project come to fruition. -## Getting started - -Please refer to the [development notes](docs/development/hacking_trento.md) for more information. - ## Submitting changes Please send a [GitHub Pull Request to Trento](https://github.com/trento-project/web/pull/new/main) with a clear list of what you've done (read more about [pull requests](http://help.github.com/pull-requests/)). @@ -16,4 +12,4 @@ Always write a clear log message for your commits. One-line messages are fine fo git commit -m "A brief summary of the commit A paragraph describing what changed and its impact." -``` +``` \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 3b34a6aee8..74b815667f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,32 +1,32 @@ -FROM registry.opensuse.org/opensuse/leap:15.4 AS system +FROM opensuse/leap AS elixir-build ENV LANG en_US.UTF-8 ENV LANGUAGE en_US:en ENV LC_ALL en_US.UTF-8 -RUN zypper -n addrepo https://download.opensuse.org/repositories/devel:/languages:/erlang/15.4/devel:languages:erlang.repo &&\ - zypper -n --gpg-auto-import-keys ref -s &&\ - zypper -n in inotify-tools elixir nodejs16 npm16 -WORKDIR /source -RUN mix local.rebar --force &&\ - mix local.hex --force - -FROM system AS deps +RUN zypper -n addrepo https://download.opensuse.org/repositories/devel:/languages:/erlang/SLE_15_SP3/devel:languages:erlang.repo +RUN zypper -n --gpg-auto-import-keys ref -s +RUN zypper -n in elixir +COPY . /build +WORKDIR /build ENV MIX_ENV=prod -COPY ./mix.* /source/ -COPY assets/package*.json /source/assets/ -RUN mix install +RUN mix local.rebar --force \ + && mix local.hex --force \ + && mix deps.get -FROM deps AS full -LABEL org.opencontainers.image.version="rolling-full" -LABEL org.opencontainers.image.source="https://github.com/trento-project/web" -COPY . /source -RUN mix assets.deploy &&\ - mix release --path /app -WORKDIR /app -EXPOSE 4000/tcp -ENTRYPOINT ["/app/bin/trento"] +FROM registry.suse.com/bci/nodejs:16 AS assets-build +COPY --from=elixir-build /build /build +WORKDIR /build/assets +RUN npm install +RUN npm run tailwind:build +RUN npm run build + +FROM elixir-build AS release +COPY --from=assets-build /build /build +WORKDIR /build +ENV MIX_ENV=prod +RUN mix phx.digest +RUN mix release -FROM registry.suse.com/bci/bci-base:15.4 AS minimal -LABEL org.opencontainers.image.version="rolling" +FROM registry.suse.com/bci/bci-base:15.3 AS trento LABEL org.opencontainers.image.source="https://github.com/trento-project/web" ENV LANG en_US.UTF-8 ENV LANGUAGE en_US:en @@ -34,6 +34,6 @@ ENV LC_ALL en_US.UTF-8 # tar is required by kubectl cp RUN zypper -n in tar WORKDIR /app -COPY --from=full /app . +COPY --from=release /build/_build/prod/rel/trento . EXPOSE 4000/tcp ENTRYPOINT ["/app/bin/trento"] diff --git a/config/config.exs b/config/config.exs index 575ef43910..22c8033af3 100644 --- a/config/config.exs +++ b/config/config.exs @@ -7,18 +7,15 @@ # General application configuration import Config +config :trento, + ecto_repos: [Trento.Repo] + # Configures the endpoint config :trento, TrentoWeb.Endpoint, - http: [ - # Enable IPv6 and bind on all interfaces. - # Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access. - # See the documentation on https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html - # for details about using IPv6 vs IPv4 and loopback vs public addresses. - ip: {0, 0, 0, 0, 0, 0, 0, 0}, - port: 4000 - ], + url: [host: "localhost"], render_errors: [view: TrentoWeb.ErrorView, accepts: ~w(html json), layout: false], - pubsub_server: Trento.PubSub + pubsub_server: Trento.PubSub, + live_view: [signing_salt: "4tNZ+tm7"] # Configures the mailer # @@ -32,7 +29,10 @@ config :trento, Trento.Mailer, adapter: Swoosh.Adapters.Local # Swoosh API client is needed for adapters other than SMTP. config :swoosh, :api_client, false -config :trento, :alerting, enabled: true +# configure the recipient for alert notifications +config :trento, :alerting, + enabled: true, + recipient: "admin@trento.io" # Configure esbuild (the version is required) config :esbuild, @@ -60,16 +60,10 @@ config :trento, Trento.Commanded, pubsub: :local, registry: :local -config :trento, - ecto_repos: [Trento.Repo] - -config :trento, Trento.Repo, pool_size: 10 - config :trento, Trento.EventStore, serializer: Trento.JsonbSerializer, column_data_type: "jsonb", - types: EventStore.PostgresTypes, - pool_size: 10 + types: EventStore.PostgresTypes config :trento, event_stores: [Trento.EventStore] @@ -112,7 +106,12 @@ config :trento, Trento.Scheduler, config :trento, Trento.Integration.Telemetry, adapter: Trento.Integration.Telemetry.Suse config :trento, Trento.Integration.Checks, adapter: Trento.Integration.Checks.Runner -config :trento, :grafana, dashboards: ["node_exporter"] +config :trento, :grafana, + user: "admin", + password: "admin", + public_url: "http://localhost:3000", + api_url: "http://localhost:3000/api", + dashboards: ["node_exporter"] config :trento, uuid_namespace: "fb92284e-aa5e-47f6-a883-bf9469e7a0dc", diff --git a/config/dev.exs b/config/dev.exs index 8d1282ef32..009c4e8c40 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -2,14 +2,22 @@ import Config # Configure your database config :trento, Trento.Repo, - url: "postgres://postgres@localhost:5432/trento_dev", + username: "postgres", + password: "postgres", + database: "trento_dev", + hostname: "localhost", + port: 5433, show_sensitive_data_on_connection_error: true, + pool_size: 10, log: false config :trento, Trento.EventStore, - url: "postgres://postgres@localhost:5432/trento_eventstore_dev", - show_sensitive_data_on_connection_error: true, - log: false + username: "postgres", + password: "postgres", + database: "trento_eventstore_dev", + hostname: "localhost", + port: 5433, + pool_size: 10 # For development, we disable any cache and enable # debugging and code reloading. @@ -18,11 +26,13 @@ config :trento, Trento.EventStore, # watchers to your application. For example, we use it # with esbuild to bundle .js and .css sources. config :trento, TrentoWeb.Endpoint, + # Binding to loopback ipv4 address prevents access from other machines. + # Change to `ip: {0, 0, 0, 0}` to allow access from other machines. + http: [ip: {0, 0, 0, 0}, port: 4000], check_origin: false, code_reloader: true, debug_errors: true, secret_key_base: "s2ZdE+3+ke1USHEJ5O45KT364KiXPYaB9cJPdH3p60t8yT0nkLexLBNw8TFSzC7k", - live_view: [signing_salt: "4tNZ+tm7"], watchers: [ node: [ "build.js", @@ -100,13 +110,3 @@ config :phoenix, :stacktrace_depth, 20 config :phoenix, :plug_init_mode, :runtime config :trento, :api_key_authentication, enabled: false - -config :trento, :grafana, - user: "admin", - password: "admin", - public_url: "http://localhost:3000", - api_url: "http://localhost:3000/api" - -config :trento, Trento.Integration.Checks.Runner, runner_url: "http://localhost:8080" - -config :trento, :alerting, recipient: "mail@domain.tld" diff --git a/config/prod.exs b/config/prod.exs index 2cc657bcac..d9c95e0c44 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -5,16 +5,7 @@ config :trento, TrentoWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json", server: true -config :trento, Trento.Mailer, - adapter: Swoosh.Adapters.SMTP, - auth: :always, - ssl: :if_available, - tls: :if_available - config :swoosh, local: false # Do not print debug messages in production -config :logger, level: :info - -# alerting is usually enabled by default, but it's the opposite in prod -config :trento, :alerting, enabled: false +# config :logger, level: :info diff --git a/config/runtime.exs b/config/runtime.exs index 7f43bb7c83..41635bb69e 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -1,93 +1,121 @@ import Config -import Trento.Config # config/runtime.exs is executed for all environments, including # during releases. It is executed after compilation and before the # system starts, so it is typically used to load production configuration # and secrets from environment variables or elsewhere. Do not define # any compile-time configuration in here, as it won't be applied. +# The block below contains prod specific runtime configuration. +if config_env() == :prod do + database_url = + System.get_env("DATABASE_URL") || + raise """ + environment variable DATABASE_URL is missing. + For example: ecto://USER:PASS@HOST/DATABASE + """ -config :trento, Trento.Repo, - url: - System.get_env("DATABASE_URL") || fallback([Trento.Repo, :url]) || - raise("Missing required environment variable: DATABASE_URL"), - pool_size: get_env_int("DATABASE_POOL_SIZE") || fallback([Trento.Repo, :pool_size]) + config :trento, Trento.Repo, + # ssl: true, + # socket_options: [:inet6], + url: database_url, + pool_size: String.to_integer(System.get_env("DATABASE_POOL_SIZE") || "10") -config :trento, Trento.EventStore, - url: - System.get_env("EVENTSTORE_URL") || fallback([Trento.EventStore, :url]) || - raise("Missing required environment variable: EVENTSTORE_URL"), - pool_size: get_env_int("EVENTSTORE_POOL_SIZE") || fallback([Trento.EventStore, :pool_size]) + evenstore_url = + System.get_env("EVENTSTORE_URL") || + raise """ + environment variable EVENTSTORE_URL is missing. + For example: ecto://USER:PASS@HOST/DATABASE + """ -config :trento, TrentoWeb.Endpoint, - http: [ - port: get_env_int("PORT") || fallback([TrentoWeb.Endpoint, :http, :port]) - ], - secret_key_base: - System.get_env("SECRET_KEY_BASE") || fallback([TrentoWeb.Endpoint, :secret_key_base]) || - raise("Missing required environment variable: SECRET_KEY_BASE") + config :trento, Trento.EventStore, + url: evenstore_url, + pool_size: String.to_integer(System.get_env("EVENTSTORE_POOL_SIZE") || "10") -config :trento, Trento.Integration.Checks.Runner, - runner_url: - System.get_env("RUNNER_URL") || fallback([Trento.Integration.Checks.Runner, :runner_url]) || - raise("Missing required environment variable: RUNNER_URL") + # The secret key base is used to sign/encrypt cookies and other secrets. + # A default value is used in config/dev.exs and config/test.exs but you + # want to use a different value for prod and you most likely don't want + # to check this value into version control, so we use an environment + # variable instead. + secret_key_base = + System.get_env("SECRET_KEY_BASE") || + raise """ + environment variable SECRET_KEY_BASE is missing. + You can generate one by calling: mix phx.gen.secret + """ -config :trento, :grafana, - user: System.get_env("GRAFANA_USER") || fallback([:grafana, :user]), - password: System.get_env("GRAFANA_PASSWORD") || fallback([:grafana, :password]), - public_url: System.get_env("GRAFANA_PUBLIC_URL") || fallback([:grafana, :public_url]), - api_url: System.get_env("GRAFANA_API_URL") || fallback([:grafana, :api_url]) + config :trento, TrentoWeb.Endpoint, + http: [ + # Enable IPv6 and bind on all interfaces. + # Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access. + # See the documentation on https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html + # for details about using IPv6 vs IPv4 and loopback vs public addresses. + ip: {0, 0, 0, 0, 0, 0, 0, 0}, + port: String.to_integer(System.get_env("PORT") || "4000") + ], + secret_key_base: secret_key_base -enable_alerting = - case get_env_bool("ENABLE_ALERTING") do - value when is_boolean(value) -> value - nil -> fallback([:alerting, :enabled]) - end + runner_url = + System.get_env("RUNNER_URL") || + raise """ + environment variable RUNNER_URL is missing. + For example: http://localhost:8080 + """ -alert_recipient = System.get_env("ALERT_RECIPIENT") || fallback([:alerting, :recipient]) + config :trento, Trento.Integration.Checks.Runner, runner_url: runner_url -if enable_alerting and is_nil(alert_recipient) do - raise("Missing required environment variable: ALERT_RECIPIENT") -end + config :trento, :grafana, + user: System.get_env("GRAFANA_USER") || "admin", + password: System.get_env("GRAFANA_PASSWORD") || "admin", + public_url: System.get_env("GRAFANA_PUBLIC_URL") || "http://localhost:3000", + api_url: System.get_env("GRAFANA_API_URL") || "http://localhost:3000/api" + + # ## Using releases + # + # If you are doing OTP releases, you need to instruct Phoenix + # to start each relevant endpoint: + # + # config :trento, TrentoWeb.Endpoint, server: true + # + # Then you can assemble a release by calling `mix release`. + # See `mix help release` for more information. -config :trento, :alerting, - enabled: enable_alerting, - recipient: alert_recipient + # ## Configuring the mailer + # + # In production you need to configure the mailer to use a different adapter. + # Also, you may need to configure the Swoosh API client of your choice if you + # are not using SMTP. Here is an example of the configuration: + # + # config :trento, Trento.Mailer, + # adapter: Swoosh.Adapters.Mailgun, + # api_key: System.get_env("MAILGUN_API_KEY"), + # domain: System.get_env("MAILGUN_DOMAIN") + # + # For this example you need include a HTTP client required by Swoosh API client. + # Swoosh supports Hackney and Finch out of the box: + # + # config :swoosh, :api_client, Swoosh.ApiClient.Hackney + # + # See https://hexdocs.pm/swoosh/Swoosh.html#module-installation for details. -# ## Configuring the mailer -# -# In production you need to configure the mailer to use a different adapter. -# Also, you may need to configure the Swoosh API client of your choice if you -# are not using SMTP. Here is an example of the configuration: -# -# config :trento, Trento.Mailer, -# adapter: Swoosh.Adapters.Mailgun, -# api_key: System.get_env("MAILGUN_API_KEY"), -# domain: System.get_env("MAILGUN_DOMAIN") -# -# For this example you need include a HTTP client required by Swoosh API client. -# Swoosh supports Hackney and Finch out of the box: -# -# config :swoosh, :api_client, Swoosh.ApiClient.Hackney -# -# See https://hexdocs.pm/swoosh/Swoosh.html#module-installation for details. -config :trento, Trento.Mailer, - relay: System.get_env("SMTP_SERVER") || fallback([Trento.Mailer, :relay]), - port: System.get_env("SMTP_PORT") || fallback([Trento.Mailer, :port]), - username: System.get_env("SMTP_USER") || fallback([Trento.Mailer, :username]), - password: System.get_env("SMTP_PASSWORD") || fallback([Trento.Mailer, :password]) + config :trento, :alerting, + enabled: System.get_env("ENABLE_ALERTING", "false") == "true", + recipient: System.get_env("ALERT_RECIPIENT") || "admin@trento-project.io" -# RUNNER_INTERVAL env var is always expressed in minutes, but fallback values are different -# so we need to do some interpolation in the crontab format -runner_schedule = - case get_env_int("RUNNER_INTERVAL") do - value when is_integer(value) -> "*/#{value} * * * *" - nil -> fallback([Trento.Scheduler, :jobs, :clusters_checks_execution, :schedule]) - end + config :trento, Trento.Mailer, + adapter: Swoosh.Adapters.SMTP, + relay: System.get_env("SMTP_SERVER") || "", + port: System.get_env("SMTP_PORT") || "", + username: System.get_env("SMTP_USER") || "", + password: System.get_env("SMTP_PASSWORD") || "", + auth: :always, + ssl: :if_available, + tls: :if_available -config :trento, Trento.Scheduler, - jobs: [ - clusters_checks_execution: [ - schedule: runner_schedule + config :trento, Trento.Scheduler, + jobs: [ + clusters_checks_execution: [ + # Runs every five minutes by default + schedule: "*/#{System.get_env("RUNNER_INTERVAL", "5")} * * * *" + ] ] - ] +end diff --git a/config/test.exs b/config/test.exs index a5d8b13fa0..0a372942fc 100644 --- a/config/test.exs +++ b/config/test.exs @@ -5,14 +5,14 @@ import Config # The MIX_TEST_PARTITION environment variable can be used # to provide built-in test partitioning in CI environment. # Run `mix help test` for more information. -# Configure your database config :trento, Trento.Repo, + username: "postgres", + password: "postgres", + database: "trento_test#{System.get_env("MIX_TEST_PARTITION")}", + hostname: "localhost", + port: 5433, pool: Ecto.Adapters.SQL.Sandbox, - url: "postgres://postgres@localhost:5432/trento_test#{System.get_env("MIX_TEST_PARTITION")}" - -config :trento, Trento.EventStore, - url: - "postgres://postgres@localhost:5432/trento_eventstore_test#{System.get_env("MIX_TEST_PARTITION")}" + pool_size: 10 config :trento, Trento.Commanded, event_store: [ @@ -23,9 +23,11 @@ config :trento, Trento.Commanded, # We don't run a server during test. If one is required, # you can enable the server option below. config :trento, TrentoWeb.Endpoint, + http: [ip: {127, 0, 0, 1}, port: 4002], secret_key_base: "dN6epjGF+jdAdq1+q4cuJSMVwrwDMWUcakjB6ISxfFmvNziaOpBsJcCPaBaydJIk", server: false +# In test we don't send emails. config :trento, Trento.Mailer, adapter: Swoosh.Adapters.Test # Print only warnings and errors during test @@ -35,13 +37,3 @@ config :logger, level: :warn config :phoenix, :plug_init_mode, :runtime config :trento, :api_key_authentication, enabled: false - -config :trento, :grafana, - user: "admin", - password: "admin", - public_url: "http://localhost:3000", - api_url: "http://localhost:3000/api" - -config :trento, Trento.Integration.Checks.Runner, runner_url: "http://localhost:8080" - -config :trento, :alerting, recipient: "mail@domain.tld" diff --git a/docker-compose.yaml b/docker-compose.yaml index e9a56164f1..81935d0b0b 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,45 +1,17 @@ -version: "3.9" +version: "3" services: - web: - depends_on: - - runner - - postgres - - grafana - build: - context: . - target: system - environment: - DATABASE_URL: postgres://postgres@postgres:5432/trento - EVENTSTORE_URL: postgres://postgres@postgres:5432/trento_eventstore - GRAFANA_PUBLIC_URL: http://grafana:3000 - GRAFANA_API_URL: http://grafana:3000/api - RUNNER_URL: http://runner:8000 - volumes: - - .:/source - - build_cache:/source/_build - ports: - - 4000:4000 - - runner: - image: ghcr.io/trento-project/trento-runner:1.0.0 - command: - - --callbacks-url - - "http://web/api/runner/callback" - - start - ports: - - 8000:8000 - postgres: image: postgres:latest environment: - POSTGRES_HOST_AUTH_METHOD: trust + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + PGDATA: /var/lib/postgresql/data/pgdata ports: - - 5432:5432 + - 5433:5432 restart: always volumes: - - pg_data:/var/lib/postgresql/data - + - ./.pgdata:/var/lib/postgresql/data grafana: image: grafana/grafana:latest environment: @@ -47,7 +19,3 @@ services: GF_AUTH_ANONYMOUS_ENABLED: "true" ports: - 3000:3000 - -volumes: - build_cache: {} - pg_data: {} diff --git a/docs/development/hack_on_the_trento.md b/docs/development/hack_on_the_trento.md new file mode 100644 index 0000000000..2c73cb1ccf --- /dev/null +++ b/docs/development/hack_on_the_trento.md @@ -0,0 +1,67 @@ +# Hack on the trento + +- [Requirements](#requirements) +- [Install dependencies](#install-dependencies) +- [Development environment](#development-environment) +- [Setup trento](#setup-trento) +- [Start trento in the repl](#start-trento-in-the-repl) +- [Environment Variables](#environment-variables) +- [Scenario loading with photofinish](#scenario-loading-with-photofinish) + +## Requirements + +In order to run the trento web, you need + +1. [Elixir](https://elixir-lang.org/) +2. [Erlang OTP](https://www.erlang.org/) +3. [Docker](https://docs.docker.com/get-docker/) +4. [Docker Compose](https://docs.docker.com/compose/install/) + +## Development environment + +A `docker-compose` development environment is provided. + +``` +$> docker-compose up -d +``` + +It will start a **postgres** database and a **grafana** instance, for storage and monitoring. +## Install dependencies + +``` +$> mix deps.get +``` + +## Setup trento + +``` +$> mix setup +``` + +## Start trento in the repl + +``` +$> iex -S mix phx.server +``` + +## Environment Variables + +See [environment_variables](./environment_variables.md) + + +## Scenario loading with photofinish + +By leveraging [photofinish](https://github.com/trento-project/photofinish) it is possible to load different scenarios for development and debugging purposes. + +``` +$> photofinish run --url "http://localhost:4000/api/collect" healthy-27-node-SAP-cluster +``` +It's possible to use Photofinish' docker image too: + +``` +$> docker run -v "$PWD":/data --network host ghcr.io/trento-project/photofinish run healthy-27-node-SAP-cluster -u http://localhost:4000/api/collect +``` + +Several useful scenario fixtures are available in [./test/fixtures/scenarios](../../test/fixtures/scenarios/), the same ones used in e2e tests. + +See also [.photofinish.toml](../../.photofinish.toml). diff --git a/docs/development/hacking_trento.md b/docs/development/hacking_trento.md deleted file mode 100644 index c5c2a28e93..0000000000 --- a/docs/development/hacking_trento.md +++ /dev/null @@ -1,106 +0,0 @@ -# Hacking Trento - -- [Requirements](#requirements) -- [Install dependencies](#install-dependencies) -- [Development environment](#development-environment) -- [Setup trento](#setup-trento) -- [Start trento in the repl](#start-trento-in-the-repl) -- [Environment Variables](#environment-variables) -- [Scenario loading with photofinish](#scenario-loading-with-photofinish) - -## Requirements - -In order to run the trento web, you need - -1. [Elixir](https://elixir-lang.org/) -2. [Erlang OTP](https://www.erlang.org/) -3. [NodeJS](https://www.nodejs.org/) -4. [Docker](https://docs.docker.com/get-docker/) -5. [Docker Compose](https://docs.docker.com/compose/install/) - - -## Development environment - -The entire environment can be set up with [asdf](http://asdf-vm.com/). - -After you installed the `asdf` CLI tool, you need to install all the relevant plugins, and then the requirements. - -```shell -asdf plugin add erlang -asdf plugin add elixir -asdf plugin add nodejs -asdf install -``` - -This will install local versions of all the above. Docker is - - -## Docker and docker-compose - -A `docker-compose` development environment is provided. - -```shell -docker-compose up -d -``` - -It will start all the services required to run the application. - -It also provides a `web` service that you can use to run Elixir within a development container. -This service does nothing by default (i.e. it invokes `bash` with no command), so you will need to attach to it explicitly via an interactive terminal, or run mix commands with it. - -E.g. to start an interactive containerized terminal session: -```shell -docker-compose run -ti -p 4000:4000 web -``` - - -## Mix tasks - -There are many `mix` tasks. You can see them all with `mix help`. - -The fastes way to get started is `mix start`, which expands to the following three sections. - -### Install dependencies - -```shell -mix install -``` - -> Note: this will take care of both Mix and NPM dependencies. - -### Setup persistence - -```shell -mix setup -``` - -### Start the web server in the repl - -```shell -iex -S mix phx.server -``` - -> Note: all the mix commands can be executed either within or outside this container. - - -## Environment Variables - -See [environment_variables](./environment_variables.md) - - -## Scenario loading with photofinish - -By leveraging [photofinish](https://github.com/trento-project/photofinish) it is possible to load different scenarios for development and debugging purposes. - -```shell -photofinish run --url "http://localhost:4000/api/collect" healthy-27-node-SAP-cluster -``` -It's possible to use Photofinish' docker image too: - -```shell -docker run -v "$PWD":/data --network host ghcr.io/trento-project/photofinish run healthy-27-node-SAP-cluster -u http://localhost:4000/api/collect -``` - -Several useful scenario fixtures are available in [./test/fixtures/scenarios](../../test/fixtures/scenarios/), the same ones used in e2e tests. - -See also [.photofinish.toml](../../.photofinish.toml). diff --git a/lib/trento/support/config.ex b/lib/trento/support/config.ex deleted file mode 100644 index d1c033ab89..0000000000 --- a/lib/trento/support/config.ex +++ /dev/null @@ -1,34 +0,0 @@ -defmodule Trento.Config do - @moduledoc """ - Configuration helper functions - """ - - @doc """ - retrieve an environment configuration setting from the system environment - using existing Application configuration as fallback - """ - def fallback(config_path) do - :trento |> Application.get_all_env() |> get_in(config_path) - end - - def get_env_int(env_var, default \\ nil) do - value = System.get_env(env_var, default) - - if is_nil(value) do - value - else - String.to_integer(value) - end - end - - def get_env_bool(env_var, default \\ nil) do - value = System.get_env(env_var, default) - - cond do - is_nil(value) -> nil - value in ["true", "1", "yes"] -> true - value in ["false", "0", "no"] -> false - true -> raise "Cannot parse #{env_var} boolean value from '#{value}'" - end - end -end diff --git a/mix.exs b/mix.exs index 072b3e3b1e..ffc1d7b719 100644 --- a/mix.exs +++ b/mix.exs @@ -91,14 +91,14 @@ defmodule Trento.MixProject do defp aliases do [ start: [ - "install", - "setup", + "cmd docker-compose up -d", + "deps.get", + "ecto.create", + "ecto.migrate", + "event_store.setup", "phx.server" ], - "start.full": ["docker-compose up -d postgres grafana", "start"], - install: ["deps.get", "cmd --cd assets npm install"], - setup: ["event_store.setup", "ecto.setup", "init_grafana_dashboards"], - reset: ["event_store.reset", "ecto.reset"], + setup: ["deps.get", "event_store.setup", "ecto.setup", "init_grafana_dashboards"], "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"], "ecto.reset": ["ecto.drop", "ecto.setup"], "event_store.setup": ["event_store.create", "event_store.init"],