diff --git a/CHANGELOG.md b/CHANGELOG.md index 56a992a1f53e608f21447fbe713b1cd76f08c411..a3ed73945e2e41e269ed798878a53bb19e281efc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,3 +8,8 @@ All notable changes to this project will be documented in this file. ### Changed - Replace configuration parameters `CLICKHOUSE_DATABASE_{HOST,NAME,USER,PASSWORD}` with a single `CLICKHOUSE_DATABASE_URL` [plausible/analytics#317](https://github.com/plausible/analytics/pull/317) +- Disable subscriptions by default +- Remove `CLICKHOUSE_DATABASE_POOLSIZE`, `DATABASE_POOLSIZE` and `DATABASE_TLS_ENABLED` parameters. Use query parameters in `CLICKHOUSE_DATABASE_URL` and `DATABASE_URL` instead. +- Remove `HOST` and `SCHEME` parameters in favor of a single `BASE_URL` parameter. +- Make `Bamboo.SMTPAdapter` the default as opposed to `Bamboo.PostmarkAdapter` +- Disable subscription flow by default diff --git a/Dockerfile b/Dockerfile index c5ce01fe1f6a1e14ca77a4b13e73e5b27040a0c8..2cfc3abc756fce3494d0211406dc10e408f722e4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -37,11 +37,6 @@ RUN set -x \ && gosu --version \ && gosu nobody true -COPY config ./config -COPY assets ./assets -COPY tracker ./tracker -COPY priv ./priv -COPY lib ./lib COPY mix.exs ./ COPY mix.lock ./ RUN mix local.hex --force && \ @@ -49,10 +44,20 @@ RUN mix local.hex --force && \ mix deps.get --only prod && \ mix deps.compile +COPY assets/package.json assets/package-lock.json ./assets/ +COPY tracker/package.json tracker/package-lock.json ./tracker/ + RUN npm audit fix --prefix ./assets && \ npm install --prefix ./assets && \ - npm run deploy --prefix ./assets && \ - npm install --prefix ./tracker && \ + npm install --prefix ./trackerc + +COPY assets ./assets +COPY tracker ./tracker +COPY config ./config +COPY priv ./priv +COPY lib ./lib + +RUN npm run deploy --prefix ./assets && \ npm run deploy --prefix ./tracker && \ mix phx.digest priv/static diff --git a/HOSTING.md b/HOSTING.md deleted file mode 100644 index ebbc497dca1667b8fd5ae7048ee61e2b324ff9c7..0000000000000000000000000000000000000000 --- a/HOSTING.md +++ /dev/null @@ -1,212 +0,0 @@ ---- -status: Beta ---- - -# Plausible Analytics - -Self-hosting is possible based on the docker images and are automatically pushed into [Dockerhub](https://hub.docker.com/r/plausible/analytics) registry for all commits on `master` branch. At the moment, `latest` is the only tag on DockerHub as we haven't reached a stable release of self-hosted Plausible yet. - -### Architecture - -Plausible runs as a single server, backed by two databases: PostgreSQL for user data and ClickhouseDB for the stats. When you -download and run the docker image you also need to provide connection details for these two databases. - -Most hosting providers will offer a managed PostgreSQL instance, but it's not as simple with Clickhouse. -You can [install Clickhouse on a VPS](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-clickhouse-on-ubuntu-18-04), -run it using their [official Docker image](https://hub.docker.com/r/yandex/clickhouse-server/), or use a managed service provided by -[Yandex Cloud](https://cloud.yandex.com/services/managed-clickhousec). [Aiven has announced](https://landing.aiven.io/2020-upcoming-aiven-services-webinar) that they are planning offer a managed ClickHouse service in the future and more hosting providers are following suit. - -As of June 2020, here's the setup of the official cloud version of Plausible for reference: -* Web server: Digital Ocean Droplet w/ 1vCPU & 2GB RAM. Managed via the [official Docker app](https://marketplace.digitalocean.com/apps/docke://marketplace.digitalocean.com/apps/docker). -* User database: Digital Ocean Managed PostgreSQL w/ 1vCPU & 1GB RAM. -* Stats database: Digital Ocean Droplet w/ 6vCPU & 16GB RAM. Installed on Ubuntu 18.04 using the [official tutorial](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-clickhouse-on-ubuntu-18-04) - -Total cost: $105/mo - -### Building Docker image -Besides the DockerHub registry, one can build docker image from [Dockerfile](./Dockerfile). - -#### Up and Running -The repo supplies with a [Docker Compose](./docker-compose.yml) file and the sample [environment variables](./plausible-variables.sample.env) , this serves as a sample for running Plausible with Docker. - -- Running the setup takes care of the initial migration steps, this needs to be executed only once, on the first run. - ```bash - docker-compose run --rm setup - docker-compose down - ``` - -- After the setup, you can start plausible as -- - ```bash - docker-compose up -d plausible - ``` - after a successful startup (can take upto 5 mins), `plausible` is available at port `80`, navigate to [`http://localhost`](http://localhost). - -- stopping plausible -- - ```bash - docker-compose down - ``` -- purging and removing everything -- - ```bash - docker-compose down - docker volume rm plausible_event-data -f - docker volume rm plausible_db-data -f - ``` -Note: -- #1 you need to stop plausible and restart plausible if you change the environment variables. -- #2 With docker-compose, you need to remove the existing container and rebuild if you want your changes need to be reflected: - ```bash - docker rmi -f plausible_plausible:latest - docker-compose up -d plausible - ``` -### Non-docker building -It is possible to create a release artifact by running a release. - -```elixir -MIX_ENV=prod mix release plausible -``` -the release will create the pre-packed artifact at `_build/prod/rel/plausible/bin/plausible`, the release will also create a tarball at `_build/prod/` for convenience. - -Note, that you have to feed in the related environment variables (see below `Environment Variables`) - -## Database Migration -On the initial setup, a migration step is necessary to create database and table schemas needed for initial bootup. -Normally, this done by mix aliases like `ecto.setup` defined in the `mix.exs`. As this not available in "released" artifact, [`plausible_migration.ex`](./lib/plausible_migration.ex) facilitates this process. -The overlay [scripts](./rel/overlays) take care of these. - -After the release, these are available under `_build/prod/rel/plausible` -- - - -```bash -_build/prod/rel/plausible/createdb.sh -_build/prod/rel/plausible/init-admin.sh -_build/prod/rel/plausible/migrate.sh -_build/prod/rel/plausible/rollback.sh -_build/prod/rel/plausible/seed.sh -``` - -the same is available in the docker images as follows -- - -```bash -docker run plausible:master-12add db createdb -docker run plausible:master-12add db init-admin -docker run plausible:master-12add db migrate -docker run plausible:master-12add db rollback -docker run plausible:master-12add db seed -``` - - -## Environment Variables -Plausible relies on the several services for operating, the expected environment variables are explaiend below. - -### Server -Following are the variables that can be used to configure the availability of the server. - -- HOST (*String*) - - The hosting address of the server. For running on local system, this can be set to **localhost**. In production systems, this can be your ingress host. -- SCHEME (*String*) - - The scheme of the URL, either `http` or `https`. When using a reverse proxy with https, it'll be required to set this. _defaults to `http`_ -- PORT (*Number*) - - The port on which the server is available. -- SECRET_KEY_BASE (*String*) - - An internal secret key used by [Phoenix Framework](https://www.phoenixframework.org/). Follow the [instructions](https://hexdocs.pm/phoenix/Mix.Tasks.Phx.Gen.Secret.html#content) to generate one. -- ENVIRONMENT (*String*) - - The current running environment. _defaults to **prod**_ -- APP_VERSION (*String*) - - The version of the app running. _defaults to current docker tag_ -- DISABLE_AUTH (*Boolean String*) - - Disables authentication completely, no registration, login will be shown. _defaults to `false`_ - - Note: This option is **not recommended** for production deployments. -- DISABLE_REGISTRATION - - Disables registration of new users, keep your admin credentials handy ;) _defaults to `false`_ -- DISABLE_SUBSCRIPTION - - Disables changing of subscription and removes the trial notice banner (use with caution!) _defaults to `false`_ - -### Default User Generation -For self-hosting, a default user can be generated using the `db init-admin` command. To be noted that, a default user is a user whose trial period expires in 100 Years ;). -It is *highly* recommended that you configure these parameters. - -- ADMIN_USER_NAME - - The default ("admin") username. _if not provided, one will be generated for you_ -- ADMIN_USER_EMAIL - - The default ("admin") user email. _if not provided, one will be generated for you_ -- ADMIN_USER_PWD - - The default ("admin") user password. _if not provided, one will be generated for you_ - -### Mailer/SMTP Setup - -- MAILER_ADAPTER (*String*) - - The adapter used for sending out e-mails. Available: `Bamboo.PostmarkAdapter` / `Bamboo.SMTPAdapter` -- MAILER_EMAIL (*String*) - - The email id to use for as _from_ address of all communications from Plausible. - -In case of `Bamboo.SMTPAdapter` you need to supply the following variables: - -- SMTP_HOST_ADDR (*String*) - - The host address of your smtp server. -- SMTP_HOST_PORT (*Number*) - - The port of your smtp server. -- SMTP_USER_NAME (*String*) - - The username/email for smtp auth. -- SMTP_USER_PWD (*String*) - - The password for smtp auth. -- SMTP_HOST_SSL_ENABLED (*Boolean String*) - - If ssl is enabled for connecting to Smtp, _defaults to `false`_ -- SMTP_RETRIES (*Number*) - - Number of retries to make until mailer gives up. _defaults to `2`_ -- SMTP_MX_LOOKUPS_ENABLED (*Boolean String*) - - If MX lookups should be done before sending out emails. _defaults to `false`_ - -### Database - -Plausible uses [postgresql as database](https://www.tutorialspoint.com/postgresql/postgresql_environment.htm) for storing all the user-data. Use the following variables to configure it. - -- DATABASE_URL (*String*) - - The repo Url as dictated [here](https://hexdocs.pm/ecto/Ecto.Repo.html#module-urls) -- DATABASE_POOL_SIZE (*Number*) - - A default pool size for connecting to the database, defaults to *10*, a higher number is recommended for a production system. -- DATABASE_TLS_ENABLED (*Boolean String*) - - A flag that says whether to connect to the database via TLS, read [here](https://www.postgresql.org/docs/10/ssl-tcp.html) - -For performance reasons, all the analytics events are stored in [clickhouse](https://clickhouse.tech/docs/en/getting-started/tutorial/): - -- CLICKHOUSE_DATABASE_URL (*String*) - - Connection string for Clickhouse. The protocol is either `http` or `https` depending on your setup. -- CLICKHOUSE_DATABASE_POOLSIZE (*Number*) - - A default pool size for connecting to the database, defaults to *10*, a higher number is recommended for a production system. - -### IP Geolocation - -Plausible uses the GeoLite2 database created by [MaxMind](https://www.maxmind.com) for enriching analytics data with visitor countries. Their -end-user license does not make it very easy to just package the database along with an open-source product. This is why, if you want -to get country data for your analytics, you need to create an account and download their **GeoLite2 Country** database. - -Once you have the database, mount it on the Plausible docker image and configure the path of the database file: -- GEOLITE2_COUNTRY_DB (*String*) - -To make this as easy as possible you can use the [`maxmindinc/geoipupdate`](https://hub.docker.com/r/maxmindinc/geoipupdate) Docker image. -You just need to add your account details, mount the database in the `plausible` container and let the image update the database automatically. -To run the complete setup including geoip see [`docker-compose-geoip.yml`](docker-compose-geoip.yml#L35). - -If the Geolite database is not configured, no country data will be captured. - -### External Services - -- [Google Client](https://developers.google.com/api-client-library) - - GOOGLE_CLIENT_ID - - GOOGLE_CLIENT_SECRET -- [Sentry](https://sentry.io/) - - SENTRY_DSN -- [Paddle](https://paddle.com/) - - PADDLE_VENDOR_AUTH_CODE -- [PostMark](https://postmarkapp.com/), only in case of `Bamboo.PostmarkAdapter` mail adapter. - - POSTMARK_API_KEY - -Apart from these, there are also the following integrations - -- [Twitter](https://developer.twitter.com/en/docs) - - TWITTER_CONSUMER_KEY - - TWITTER_CONSUMER_SECRET - - TWITTER_ACCESS_TOKEN - - TWITTER_ACCESS_TOKEN_SECRET -- [Slack](https://api.slack.com/messaging/webhooks) - - SLACK_WEBHOOK diff --git a/config/config.exs b/config/config.exs index b551d94896d4b8f223dd998ee6528fb4b3e9dd60..73790589499e035e086cc53a696d6cedc5ef0d39 100644 --- a/config/config.exs +++ b/config/config.exs @@ -1,5 +1,8 @@ use Mix.Config +base_url = System.get_env("BASE_URL", "http://localhost:8000") + |> URI.parse + config :plausible, admin_user: System.get_env("ADMIN_USER_NAME", "admin"), admin_email: System.get_env("ADMIN_USER_EMAIL", "admin@plausible.local"), @@ -22,8 +25,9 @@ config :plausible, :selfhost, # Configures the endpoint config :plausible, PlausibleWeb.Endpoint, url: [ - host: System.get_env("HOST", "localhost"), - scheme: System.get_env("SCHEME", "http") + host: base_url.host, + scheme: base_url.scheme, + port: base_url.port ], http: [ port: String.to_integer(System.get_env("PORT", "8000")) @@ -77,7 +81,6 @@ config :plausible, :paddle, config :plausible, Plausible.ClickhouseRepo, loggers: [Ecto.LogEntry], - pool_size: String.to_integer(System.get_env("CLICKHOUSE_DATABASE_POOLSIZE", "5")), url: System.get_env( "CLICKHOUSE_DATABASE_URL", "http://127.0.0.1:8123/plausible_test" @@ -85,7 +88,6 @@ config :plausible, Plausible.ClickhouseRepo, config :plausible, Plausible.Repo, - pool_size: String.to_integer(System.get_env("DATABASE_POOLSIZE", "10")), timeout: 300_000, connect_timeout: 300_000, handshake_timeout: 300_000, @@ -93,8 +95,7 @@ config :plausible, System.get_env( "DATABASE_URL", "postgres://postgres:postgres@127.0.0.1:5432/plausible_dev?currentSchema=default" - ), - ssl: String.to_existing_atom(System.get_env("DATABASE_TLS_ENABLED", "false")) + ) cron_enabled = String.to_existing_atom(System.get_env("CRON_ENABLED", "false")) @@ -159,7 +160,7 @@ case mailer_adapter do password: System.fetch_env!("SMTP_USER_PWD"), tls: :if_available, allowed_tls_versions: [:tlsv1, :"tlsv1.1", :"tlsv1.2"], - ssl: System.get_env("SMTP_HOST_SSL_ENABLED") || true, + ssl: System.get_env("SMTP_HOST_SSL_ENABLED") || false, retries: System.get_env("SMTP_RETRIES") || 2, no_mx_lookups: System.get_env("SMTP_MX_LOOKUPS_ENABLED") || true, auth: :if_available diff --git a/config/releases.exs b/config/releases.exs index b4c3ee2af136977dbc8f2ed722c9e3674e37f589..eef6ea2281c322f369cc879a86691d4a50b2c520 100644 --- a/config/releases.exs +++ b/config/releases.exs @@ -5,33 +5,25 @@ import Config # params are made optional to facilitate smooth release port = System.get_env("PORT") || 8000 -host = System.get_env("HOST", "localhost") -scheme = System.get_env("SCHEME", "http") +base_url = System.get_env("BASE_URL", "http://localhost:8000") + |> URI.parse -secret_key_base = - System.get_env( - "SECRET_KEY_BASE", - "/NJrhNtbyCVAsTyvtk1ZYCwfm981Vpo/0XrVwjJvemDaKC/vsvBRevLwsc6u8RCg" - ) - -db_pool_size = String.to_integer(System.get_env("DATABASE_POOLSIZE", "10")) +secret_key_base = System.get_env("SECRET_KEY_BASE") db_url = System.get_env( "DATABASE_URL", - "postgres://postgres:postgres@127.0.0.1:5432/plausible_dev" + "postgres://postgres:postgres@plausible_db:5432/plausible_db" ) -db_tls_enabled? = String.to_existing_atom(System.get_env("DATABASE_TLS_ENABLED", "false")) admin_user = System.get_env("ADMIN_USER_NAME") admin_email = System.get_env("ADMIN_USER_EMAIL") admin_pwd = System.get_env("ADMIN_USER_PWD") env = System.get_env("ENVIRONMENT", "prod") -mailer_adapter = System.get_env("MAILER_ADAPTER", "Bamboo.PostmarkAdapter") +mailer_adapter = System.get_env("MAILER_ADAPTER", "Bamboo.SMTPAdapter") mailer_email = System.get_env("MAILER_EMAIL", "hello@plausible.local") app_version = System.get_env("APP_VERSION", "0.0.1") -ch_db_url = System.get_env("CLICKHOUSE_DATABASE_URL", "http://localhost:8123/plausible_dev") -ch_db_pool = String.to_integer(System.get_env("CLICKHOUSE_DATABASE_POOLSIZE", "10")) +ch_db_url = System.get_env("CLICKHOUSE_DATABASE_URL", "http://plausible_events_db:8123/plausible_events_db") ### Mandatory params End sentry_dsn = System.get_env("SENTRY_DSN") @@ -63,7 +55,7 @@ config :plausible, config :plausible, :selfhost, disable_authentication: disable_auth, - disable_subscription: String.to_existing_atom(System.get_env("DISABLE_SUBSCRIPTION", "false")), + disable_subscription: String.to_existing_atom(System.get_env("DISABLE_SUBSCRIPTION", "true")), disable_registration: if(!disable_auth, do: String.to_existing_atom(System.get_env("DISABLE_REGISTRATION", "false")), @@ -71,10 +63,8 @@ config :plausible, :selfhost, ) config :plausible, PlausibleWeb.Endpoint, - url: [host: host, scheme: scheme], - http: [ - port: port - ], + url: [host: base_url.host, scheme: base_url.scheme, port: base_url.port], + http: [port: port], secret_key_base: secret_key_base, cache_static_manifest: "priv/static/cache_manifest.json", check_origin: false, @@ -84,10 +74,8 @@ config :plausible, PlausibleWeb.Endpoint, config :plausible, Plausible.Repo, - pool_size: db_pool_size, url: db_url, - adapter: Ecto.Adapters.Postgres, - ssl: db_tls_enabled? + adapter: Ecto.Adapters.Postgres config :sentry, dsn: sentry_dsn, @@ -106,8 +94,7 @@ config :plausible, :slack, webhook: slack_hook_url config :plausible, Plausible.ClickhouseRepo, loggers: [Ecto.LogEntry], - url: ch_db_url, - pool_size: ch_db_pool + url: ch_db_url case mailer_adapter do "Bamboo.PostmarkAdapter" -> @@ -118,17 +105,16 @@ case mailer_adapter do "Bamboo.SMTPAdapter" -> config :plausible, Plausible.Mailer, adapter: :"Elixir.#{mailer_adapter}", - server: System.fetch_env!("SMTP_HOST_ADDR"), - hostname: System.get_env("HOST", "localhost"), - port: System.fetch_env!("SMTP_HOST_PORT"), - username: System.fetch_env!("SMTP_USER_NAME"), - password: System.fetch_env!("SMTP_USER_PWD"), + server: System.get_env("SMTP_HOST_ADDR", "mail"), + hostname: base_url.host, + port: System.get_env("SMTP_HOST_PORT", "25"), + username: System.get_env("SMTP_USER_NAME"), + password: System.get_env("SMTP_USER_PWD"), tls: :if_available, allowed_tls_versions: [:tlsv1, :"tlsv1.1", :"tlsv1.2"], - ssl: System.get_env("SMTP_HOST_SSL_ENABLED") || true, + ssl: System.get_env("SMTP_HOST_SSL_ENABLED") || false, retries: System.get_env("SMTP_RETRIES") || 2, - no_mx_lookups: System.get_env("SMTP_MX_LOOKUPS_ENABLED") || true, - auth: :always + no_mx_lookups: System.get_env("SMTP_MX_LOOKUPS_ENABLED") || true _ -> raise "Unknown mailer_adapter; expected SMTPAdapter or PostmarkAdapter" diff --git a/docker-compose-geoip.yml b/docker-compose-geoip.yml deleted file mode 100644 index 29cba2d0dea7911e3ecc684f1893cf5a7921c842..0000000000000000000000000000000000000000 --- a/docker-compose-geoip.yml +++ /dev/null @@ -1,97 +0,0 @@ -# NOTE: -# This Docker-compose file is created as a sample and should not be used directly for production -# You can adjust the settings as-per your environment -version: "3.3" -services: - # As it says, this service is a fake smtp server which accepts SMTP connections - # the inbox is available at localhost:8025, in actuality, you need to use a proper smtp server - fake_smtp: - image: mailhog/mailhog:v1.0.0 - ports: - - 1025:1025 - - 8025:8025 - healthcheck: - test: echo | telnet 127.0.0.1 1025 - - plausible_db: - image: postgres:12 - command: ["postgres", "-c", "log_statement=all", "-c", "log_destination=stderr"] - volumes: - - db-data:/var/lib/postgresql/data - environment: - - POSTGRES_PASSWORD=postgres - - POSTGRES_DB=plausible_db - - POSTGRES_USER=postgres - ports: - - 5432:5432 - - plausible_events_db: - image: yandex/clickhouse-server:latest - volumes: - - event-data:/var/lib/clickhouse - ports: - - 8123:8123 - - # optional, if you want to setup a geoip database and let it update automatically - # this requires an account at maxmind.com (https://www.maxmind.com/en/geolite2/signup) - geoip: - image: maxmindinc/geoipupdate - ports: - - 1080:1080 - environment: - - GEOIPUPDATE_ACCOUNT_ID=<your-account-id> - - GEOIPUPDATE_LICENSE_KEY=<your-license-key> - - GEOIPUPDATE_EDITION_IDS=GeoLite2-Country - # update every 7 days - - GEOIPUPDATE_FREQUENCY=168 - volumes: - - geoip:/usr/share/GeoIP - - plausible: - build: - context: . - dockerfile: ./Dockerfile - command: sh -c "sleep 10 && /entrypoint.sh db migrate && /entrypoint.sh run" - depends_on: - - plausible_db - - plausible_events_db - - geoip - - fake_smtp - ports: - - 80:8080 - links: - - plausible_db - - plausible_events_db - - geoip - - fake_smtp - env_file: - - plausible-variables.sample.env - # only if you use the geioip container - environment: - - GEOLITE2_COUNTRY_DB=/geoip/GeoLite2-Country.mmdb - volumes: - - geoip:/geoip:ro - - setup: - build: - context: . - dockerfile: ./Dockerfile - command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh db init-admin" - depends_on: - - plausible_db - - plausible_events_db - - geoip - links: - - plausible_db - - plausible_events_db - - geoip - env_file: - - plausible-variables.sample.env - -volumes: - db-data: - driver: local - event-data: - driver: local - geoip: - driver: local diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index b521aef075a155cffdbaf191d8eef8f877584b50..0000000000000000000000000000000000000000 --- a/docker-compose.yml +++ /dev/null @@ -1,76 +0,0 @@ -# NOTE: -# This Docker-compose file is created as a sample and should not be used directly for production -# You can adjust the settings as-per your environment -version: "3.3" -services: - -# As it says, this service is a fake smtp server which accepts SMTP connections -# the inbox is available at localhost:8025, in actuality, you need to use a proper smtp server - fake_smtp: - image: mailhog/mailhog:v1.0.0 - ports: - - 1025:1025 - - 8025:8025 - healthcheck: - test: echo | telnet 127.0.0.1 1025 - - - plausible_db: - image: postgres:12 - command: ["postgres", "-c", "log_statement=all", "-c", "log_destination=stderr"] - volumes: - - db-data:/var/lib/postgresql/data - environment: - - POSTGRES_PASSWORD=postgres - - POSTGRES_DB=plausible_db - - POSTGRES_USER=postgres - ports: - - 5432:5432 - - plausible_events_db: - image: yandex/clickhouse-server:latest - volumes: - - event-data:/var/lib/clickhouse - ports: - - 8123:8123 - - plausible: - build: - context: . - dockerfile: ./Dockerfile - command: sh -c "sleep 10 && /entrypoint.sh db migrate && /entrypoint.sh run" - depends_on: - - plausible_db - - plausible_events_db - - fake_smtp - ports: - - 80:8080 - links: - - plausible_db - - plausible_events_db - - fake_smtp - env_file: - - plausible-variables.sample.env - environment: - - GEOLITE2_COUNTRY_DB=/geoip/GeoLite2-Country.mmdb - - setup: - build: - context: . - dockerfile: ./Dockerfile - command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh db init-admin" - depends_on: - - plausible_db - - plausible_events_db - links: - - plausible_db - - plausible_events_db - env_file: - - plausible-variables.sample.env - - -volumes: - db-data: - driver: local - event-data: - driver: local diff --git a/lib/plausible/google/api.ex b/lib/plausible/google/api.ex index 3313225e0abb9d6a74468fc8530bcb0e44c65567..36c66b291a9cd510766c006522b03d175aef7605 100644 --- a/lib/plausible/google/api.ex +++ b/lib/plausible/google/api.ex @@ -148,6 +148,6 @@ defmodule Plausible.Google.Api do end defp redirect_uri() do - PlausibleWeb.Endpoint.clean_url() <> "/auth/google/callback" + PlausibleWeb.Endpoint.url() <> "/auth/google/callback" end end diff --git a/lib/plausible_release.ex b/lib/plausible_release.ex index 9caaa98e423352dfb7db095daef67325ddd205ef..fbde8dfb316947a6545b0df5a6cd5f42e77c05ae 100644 --- a/lib/plausible_release.ex +++ b/lib/plausible_release.ex @@ -50,8 +50,11 @@ defmodule Plausible.Release do end def createdb do - prepare() - do_create_db() + :ok = Application.load(@app) + + for repo <- repos() do + :ok = ensure_repo_created(repo) + end IO.puts("Creation of Db successful!") end @@ -116,12 +119,6 @@ defmodule Plausible.Release do {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true)) end - defp do_create_db do - for repo <- repos() do - :ok = ensure_repo_created(repo) - end - end - defp ensure_repo_created(repo) do IO.puts("create #{inspect(repo)} database if it doesn't exist") diff --git a/lib/plausible_web/controllers/auth_controller.ex b/lib/plausible_web/controllers/auth_controller.ex index 4d98b5d1f1bb36550d7b428040af3b460c683a1b..989845fc75d1f04c628e2b3f2dd3bbb23d213617 100644 --- a/lib/plausible_web/controllers/auth_controller.ex +++ b/lib/plausible_web/controllers/auth_controller.ex @@ -31,7 +31,7 @@ defmodule PlausibleWeb.AuthController do case Ecto.Changeset.apply_action(user, :insert) do {:ok, user} -> token = Auth.Token.sign_activation(user.name, user.email) - url = PlausibleWeb.Endpoint.clean_url() <> "/claim-activation?token=#{token}" + url = PlausibleWeb.Endpoint.url() <> "/claim-activation?token=#{token}" Logger.info(url) email_template = PlausibleWeb.Email.activation_email(user, url) Plausible.Mailer.send_email(email_template) @@ -101,7 +101,7 @@ defmodule PlausibleWeb.AuthController do if user do token = Auth.Token.sign_password_reset(email) - url = PlausibleWeb.Endpoint.clean_url() <> "/password/reset?token=#{token}" + url = PlausibleWeb.Endpoint.url() <> "/password/reset?token=#{token}" Logger.debug("PASSWORD RESET LINK: " <> url) email_template = PlausibleWeb.Email.password_reset_email(email, url) Plausible.Mailer.deliver_now(email_template) diff --git a/lib/plausible_web/controllers/tracker_controller.ex b/lib/plausible_web/controllers/tracker_controller.ex index c6464cdb72668ac5d3506f89843d827da3379396..08cbed563341472247d17d038a55e06a8242b4d5 100644 --- a/lib/plausible_web/controllers/tracker_controller.ex +++ b/lib/plausible_web/controllers/tracker_controller.ex @@ -50,6 +50,6 @@ defmodule PlausibleWeb.TrackerController do end defp base_url() do - PlausibleWeb.Endpoint.clean_url() + PlausibleWeb.Endpoint.url() end end diff --git a/lib/plausible_web/endpoint.ex b/lib/plausible_web/endpoint.ex index ea82c2a14f6b1132cb83fec28a8ae45d492ec231..9a9b85e10398a25272d2cb8fad82c96386f76c58 100644 --- a/lib/plausible_web/endpoint.ex +++ b/lib/plausible_web/endpoint.ex @@ -41,15 +41,4 @@ defmodule PlausibleWeb.Endpoint do plug CORSPlug plug PlausibleWeb.Router - - def clean_url() do - url = PlausibleWeb.Endpoint.url() - - case Application.get_env(:plausible, :environment) do - # do not truncate the port in case of dev or test environment - env when env in ["dev", "test"] -> url - # in most deployments, there's a layer above the above - _ -> URI.parse(url) |> Map.put(:port, nil) |> URI.to_string() - end - end end diff --git a/lib/plausible_web/views/auth_view.ex b/lib/plausible_web/views/auth_view.ex index 3c372011be58c8ab29c0da8f276c8a0425d9ca6f..d30121cd97d26106e970f78e8e00b25a997cdecd 100644 --- a/lib/plausible_web/views/auth_view.ex +++ b/lib/plausible_web/views/auth_view.ex @@ -33,7 +33,7 @@ defmodule PlausibleWeb.AuthView do end def plausible_url do - PlausibleWeb.Endpoint.clean_url() + PlausibleWeb.Endpoint.url() end def subscription_quota(subscription) do diff --git a/lib/plausible_web/views/billing_view.ex b/lib/plausible_web/views/billing_view.ex index 54650c41350b6a75f1ed7b19bad2e835d4a4856b..19ea331875c5cc4b8bf1a9a7fd251119b1dd13a7 100644 --- a/lib/plausible_web/views/billing_view.ex +++ b/lib/plausible_web/views/billing_view.ex @@ -10,7 +10,7 @@ defmodule PlausibleWeb.BillingView do end def plausible_url do - PlausibleWeb.Endpoint.clean_url() + PlausibleWeb.Endpoint.url() end def present_date(date) do diff --git a/lib/plausible_web/views/email_view.ex b/lib/plausible_web/views/email_view.ex index 6e4342140a64263fa07de164b1df1a4dfe5e6d24..48280cb2847324133bc2454f9dd96dc1ba7b8733 100644 --- a/lib/plausible_web/views/email_view.ex +++ b/lib/plausible_web/views/email_view.ex @@ -6,7 +6,7 @@ defmodule PlausibleWeb.EmailView do end def plausible_url do - PlausibleWeb.Endpoint.clean_url() + PlausibleWeb.Endpoint.url() end def base_domain() do diff --git a/lib/plausible_web/views/layout_view.ex b/lib/plausible_web/views/layout_view.ex index 2a5c20c138a164acb6447db0b879d322e072581f..3f1ea3e25afa0ccfff9c17e6cd7926cfb4b2f588 100644 --- a/lib/plausible_web/views/layout_view.ex +++ b/lib/plausible_web/views/layout_view.ex @@ -10,7 +10,7 @@ defmodule PlausibleWeb.LayoutView do end def plausible_url do - PlausibleWeb.Endpoint.clean_url() + PlausibleWeb.Endpoint.url() end def home_dest(conn) do diff --git a/lib/plausible_web/views/page_view.ex b/lib/plausible_web/views/page_view.ex index 12119a80e6ae83d4472e67873872ddce171dcae6..f0fd45dea827729b60317643466ef360f34091e2 100644 --- a/lib/plausible_web/views/page_view.ex +++ b/lib/plausible_web/views/page_view.ex @@ -10,6 +10,6 @@ defmodule PlausibleWeb.PageView do end def plausible_url do - PlausibleWeb.Endpoint.clean_url() + PlausibleWeb.Endpoint.url() end end diff --git a/lib/plausible_web/views/site_view.ex b/lib/plausible_web/views/site_view.ex index ecb18ebe2a72db988457fa36800ad3bacfc207a6..7a1014e59ebff35a2dca4e7ca032fa8caa3424a9 100644 --- a/lib/plausible_web/views/site_view.ex +++ b/lib/plausible_web/views/site_view.ex @@ -6,7 +6,7 @@ defmodule PlausibleWeb.SiteView do end def plausible_url do - PlausibleWeb.Endpoint.clean_url() + PlausibleWeb.Endpoint.url() end def base_domain() do diff --git a/lib/plausible_web/views/stats_view.ex b/lib/plausible_web/views/stats_view.ex index 1edef558bca92e8710ec645307d5bb10c54f82f1..fb138bf218e4eee872d6a027019f8facd12c4258 100644 --- a/lib/plausible_web/views/stats_view.ex +++ b/lib/plausible_web/views/stats_view.ex @@ -10,7 +10,7 @@ defmodule PlausibleWeb.StatsView do end def plausible_url do - PlausibleWeb.Endpoint.clean_url() + PlausibleWeb.Endpoint.url() end def large_number_format(n) do diff --git a/lib/workers/send_email_report.ex b/lib/workers/send_email_report.ex index 0bbd544ad8988945f9b0025798ab39e423e9c296..b3896b6b21008117a2dd66c87ed75ff01fc487cb 100644 --- a/lib/workers/send_email_report.ex +++ b/lib/workers/send_email_report.ex @@ -11,7 +11,7 @@ defmodule Plausible.Workers.SendEmailReport do for email <- site.weekly_report.recipients do unsubscribe_link = - PlausibleWeb.Endpoint.clean_url() <> + PlausibleWeb.Endpoint.url() <> "/sites/#{URI.encode_www_form(site.domain)}/weekly-report/unsubscribe?email=#{email}" send_report(email, site, "Weekly", unsubscribe_link, query) @@ -37,7 +37,7 @@ defmodule Plausible.Workers.SendEmailReport do for email <- site.monthly_report.recipients do unsubscribe_link = - PlausibleWeb.Endpoint.clean_url() <> + PlausibleWeb.Endpoint.url() <> "/sites/#{URI.encode_www_form(site.domain)}/monthly-report/unsubscribe?email=#{email}" send_report(email, site, Timex.format!(last_month, "{Mfull}"), unsubscribe_link, query) diff --git a/plausible-variables.sample.env b/plausible-variables.sample.env deleted file mode 100644 index d7142dad2d4e1656b7dd806248eddcf20a4784ea..0000000000000000000000000000000000000000 --- a/plausible-variables.sample.env +++ /dev/null @@ -1,21 +0,0 @@ -ENVIRONMENT=production -PORT=8080 -SECRET_KEY_BASE=iYb1mP5cnmY+gUxo7C/h6XMigossPhzwd8/ic6LFnQ9Y58Fl1xduSWaPq0fHDdbn -SIGNING_SALT=PL/THF0VMOzuv1bOcldjDzYFBLryvXNs -HOST=localhost -DATABASE_URL=postgres://postgres:postgres@plausible_db:5432/plausible_db -DATABASE_TLS_ENABLED=false -CLICKHOUSE_DATABASE_URL=http://default:@plausible_events_db/plausible_events_db -ADMIN_USER_NAME=admin -ADMIN_USER_EMAIL=admin@plausible.local -ADMIN_USER_PWD=admin@1234! -APP_VERSION=test -MAILER_ADAPTER=Bamboo.SMTPAdapter -SMTP_HOST_ADDR=fakesmtp_server -SMTP_HOST_PORT=1025 -SMTP_USER_NAME=fakeuser@plausible.local -SMTP_USER_PWD=password -SMTP_HOST_SSL_ENABLED=false -SMTP_MX_LOOKUPS_ENABLED=false -DISABLE_AUTH=false -DISABLE_REGISTRATION=false