Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for docker based self-hosting #64

Merged
merged 88 commits into from May 26, 2020
Merged

Conversation

tckb
Copy link
Contributor

@tckb tckb commented May 15, 2020

In this PR, I made changes for making it easy for self-hosting.
Salient changes are listed below:

  • Add default user during initial setup
  • Add support for SMTP server for Mailer
  • Update base-domain according to "HOST" param
  • Cosmetic changes across website for self-hosting

// Pending changes from review:

tckb added 30 commits May 4, 2020 20:29
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
…testing

Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Gitlab Migration: Adding test stage

See merge request tckb-public/plausible!1
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Added Dockerfile and cleaned up configurations

See merge request tckb-public/plausible!2
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Adding overlay scripts for Db migration  on release artifacts

See merge request tckb-public/plausible!3
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
@ukutaht
Copy link
Contributor

ukutaht commented May 17, 2020

Something that came to mind as well: Currently, we get the visitor country code from the X-Country header which is set by Netlify's CDN.

Since we don't control how Plausible will be deployed, we can't rely on custom headers set by the CDN. We probably need some sort of local geolocation database. There's also a feature request for more accurate location (I guess that means counties/cities). I'll research what the libraries/tools are available for this.

EDIT: Based on some light research, it looks to me like using MaxMind's GeoIP database makes the most sense. They identify both countries and cities, there's a free version of the dataset and multiple libraries exist in Elixir that use their database.

@tckb
Copy link
Contributor Author

tckb commented May 17, 2020

Something that came to mind as well: Currently, we get the visitor country code from the X-Country header which is set by Netlify's CDN.

Since we don't control how Plausible will be deployed, we can't rely on custom headers set by the CDN. We probably need some sort of local geolocation database. There's also a feature request for more accurate location (I guess that means counties/cities). I'll research what the libraries/tools are available for this.

Funny I was actually on suggest MaxMind. I did use it before and does provide pretty accurate results; the free db can be sufficient for most cases. If you want more accurate results, you can subscribe to their enterprise db. We can have a separate discussion on it, if you want

@ukutaht
Copy link
Contributor

ukutaht commented May 17, 2020

Awesome. I can pick this is up probably first week on June, after the Clickhouse migration is complete.

Another thing that came to mind with Netlify: I use their custom header to get the remote client ip. See the code here: https://github.com/plausible-insights/plausible/blob/master/lib/plausible_web/controllers/api/external_controller.ex#L86

It's really hacky but it works for now. A more robust solution would be using the X-Forwarded-For header, potentially with this plug: https://github.com/ajvondrak/remote_ip

tckb added 3 commits May 17, 2020 12:32
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Addressing PR comments on upstream

Closes plausible#16

See merge request tckb-public/plausible!18
@tckb
Copy link
Contributor Author

tckb commented May 17, 2020

Another thing that came to mind with Netlify: I use their custom header to get the remote client ip. See the code here: https://github.com/plausible-insights/plausible/blob/master/lib/plausible_web/controllers/api/external_controller.ex#L86
It's really hacky but it works for now. A more robust solution would be using the X-Forwarded-For header, potentially with this plug: https://github.com/ajvondrak/remote_ip

Using custom headers isn't necessarily hacky , with remote_ip you can add x-bb-ip as additional search headers to :headers

@ukutaht I cleaned up the PR, reverted the formatting change. I will add the formatting changes to a different PR.

@tckb tckb changed the title Support for self-hosting Support for docker based self-hosting May 17, 2020
tckb added 4 commits May 18, 2020 15:33
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
adding docker-compose.yml and related instructions

See merge request tckb-public/plausible!19
this is because, it is much to test in local dev machines and in most cases there's already a layer above which is capable for `https` termination and http -> https upgrade

Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
using `plausible_url` instead of base_domain

See merge request tckb-public/plausible!20
@tckb tckb marked this pull request as ready for review May 18, 2020 16:26
Copy link
Contributor

@ukutaht ukutaht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested things out locally

  • Docker-compose works
  • mix phx.server works
  • Running as Mix release works

I'm happy with the state of the PR. Today I'm planning to deploy a new release of Plausible using a Clickhouse database. I've been working with it for almost a month, I can help integrate the new database into this infra setup if needed.

@tckb let me know if you agree with the next steps:

  • Resolve conflicts
  • Integrate Clickhouse
  • Merge this PR
  • I will start using this setup locally (probably still running mix phx.server instead of docker-compose to take advantage of code reloading)
  • I will set up Travis and DockerHub for this repository
  • Deploy a staging version using DockerHub.
  • Deploy a production release using DockerHub.
  • Public alpha release of self-hosted Plausible. Going forward I will keep a proper Changelog/Release notes and conform to the release tagging system we agreed on.

Dockerfile Outdated Show resolved Hide resolved
@tckb
Copy link
Contributor Author

tckb commented May 21, 2020

I've been working with it for almost a month, I can help integrate the new database into this infra setup if needed.

I will look into the changes, it would definately require changes to Dockerfile and docker-compose. It would be helpful if you push all your changes and have code-freeze until I make the changes or have the release/changes fixed date for the next push. This will help in saving time for ping-pong updates and fix my timeline.

let me know if you agree with the next steps:
Resolve conflicts
Integrate Clickhouse
Merge this PR

This is on my plate, I will take care of it. Need some time as I explained above.

I will set up Travis and DockerHub for this repository

Yes, that will be good idea.

Deploy a staging version using DockerHub.
Deploy a production release using DockerHub.

I can help you in setting up CI/CD pipeline. We can discuss this offline.

Public alpha release of self-hosted Plausible.

Yes, a blog-post would be awesome!

Going forward I will keep a proper Changelog/Release notes

I think this makes sense and provide more visibility and could also help in actually defining a timeline for your roadmap

conform to the release tagging system we agreed on

I always like semantic versions

@ukutaht
Copy link
Contributor

ukutaht commented May 22, 2020

Great!

I'm pretty much in a code-freeze for a few days as I'm deploying the new database and working on other performance-related things. There may be some light changes but we should not conflict.

As for Clickhouse, here's the configuration for it:
https://github.com/plausible-insights/plausible/blob/master/config/prod.exs#L74
And the docker setup for testing:
https://github.com/plausible-insights/plausible/blob/master/.travis.yml#L7

Let me know if there's any way I can help with this. I'm available for Twitter DMs and a call if needed :)

tckb added 8 commits May 22, 2020 18:52
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Signed-off-by: Chandra Tungathurthi <tckb@tgrthi.me>
Resolve "Integrate Clickhouse"

Closes plausible#17

See merge request tckb-public/plausible!21
# Conflicts:
#	config/config.exs
#	config/dev.exs
#	config/prod.exs
#	config/test.exs
#	lib/mix/tasks/hydrate_clickhouse.ex
#	lib/plausible_web/controllers/stats_controller.ex
#	lib/plausible_web/templates/auth/password_reset_request_success.html.eex
#	mix.lock
#	test/test_helper.exs
Resolve "Resolve upstream merge conflicts"

Closes plausible#18

See merge request tckb-public/plausible!22
@tckb tckb requested a review from ukutaht May 24, 2020 15:07
@tckb
Copy link
Contributor Author

tckb commented May 24, 2020

@ukutaht All requested changes are finished and is ready for review. I have integrated clickhouse and resolved the conflicts. There's still pending formatting PR . I will raise another one right after this one.

@ukutaht ukutaht merged commit 5eb8929 into plausible:master May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants