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

Deploy Plausible Analytics to a VPS 📈 📊 🚀 + Document it! 📝 #3

Closed
5 tasks done
nelsonic opened this issue Jul 26, 2024 · 14 comments · Fixed by #4
Closed
5 tasks done

Deploy Plausible Analytics to a VPS 📈 📊 🚀 + Document it! 📝 #3

nelsonic opened this issue Jul 26, 2024 · 14 comments · Fixed by #4
Assignees
Labels
enhancement New feature or enhancement of existing functionality help wanted If you can help make progress with this issue, please comment!

Comments

@nelsonic
Copy link
Member

nelsonic commented Jul 26, 2024

We've been using (and gladly paying for) Plausible Analytics for the past couple of years: dwyl/technology-stack#127
The plan was always to experiment with self-hosting it so that we can more features to analytics and have more control over the data of the people using our App(s).

With that in mind we need ...

Todo

  • Get: https://github.com/plausible/analytics running on localhost and document all the steps. 📝
    e.g. analytics/deploy-plausible-vps.md 🆕
  • Use Docker (with Ubuntu) to run it on localhost so that it's easier to deploy on VPS 💻
  • We should be able to use docker run or mix start in the /analytics directory and have it start up seamlessly 🚀
  • Create PR at this point. 🙏
  • Attempt to deploy to fly.io (which should be straightforward. 🤞); document the steps.

Note: the VPS we will be using is a Droplet on DigitalOcean
but the instructions should be applicable to any VPS provider including AWS etc.

If this is straightforward to deploy we will propose it for use by the Client who need an "On Prem" analytics option;
i.e. their data is sensitive and don't want to send it to a 3rdParty.

If this goes well, we will switch over the analytics of dwyl.com to analytics.dwyl.com 📈
But our goal is to use this as the basis for building something a lot more interesting! 😉

@nelsonic nelsonic added enhancement New feature or enhancement of existing functionality help wanted If you can help make progress with this issue, please comment! labels Jul 26, 2024
@nelsonic nelsonic changed the title Document How to Deploy Plausible Analytics to a VPS 📈 📊 🚀 Deploy Plausible Analytics to a VPS 📈 📊 🚀 + Document it! 📝 Jul 26, 2024
@nelsonic nelsonic transferred this issue from dwyl/learn-devops Aug 11, 2024
@LuchoTurtle
Copy link
Member

Created #4 to address this issue.

Spent a lot of time integrating this with a Next.js website, as the events weren't being properly registered and pageview events were not being detected at all on Plausible's server side.

plausible/analytics#1185 were not really useful, I just knew I wasn't alone on this issue.
But I've managed to fix it.

Getting localhost website and self-hosting Plausible to register localhost websites is actually harder than pointing to a production domain, go figure.

As it stands, the PR already has everything working on localhost. The only thing that's left is deploying it to fly.io.

@nelsonic
Copy link
Member Author

@LuchoTurtle Next.js is not mentioned in the OP, please don't waste any time on it. 🙅
Right now all we care about is getting Analytics running. 📈
Next.js / Nextra are built by and used by people who don't know what they are optimising for. 🐌 💸 🔥
For the purposes of this guide we will be creating ~10 pages of static HTML (😱 IKR!) deployed using GitHub Pages.

When we need to apply this to the client Next.js / Nextra we can open a separate issue so that we can capture exactly how complex/complicated it is to show that Next.js makes simple things needlessly complicated.

@LuchoTurtle
Copy link
Member

I've been trying to follow https://github.com/intever/plausible-hosting and getting it working for the past few hours to get it self-hosted in fly.io.

I ran into these problems and trudging through. I've been able to fix some errors but, even though the release command now runs successfully, I can't initialize the pg database:

fly.io is a colossal pit of frustration sometimes.

@nelsonic
Copy link
Member Author

If fly.io is being a pain, feel free to deploy anywhere else just to get something running.
We will eventually be deploying this to DigitalOcean.

Curious if we need to use ClickHouse for an instance of Analytics that won't have that many events per day ... 💭

@LuchoTurtle
Copy link
Member

I've already documented 99% of the steps to getting it on fly.io. I know I'm entering the "sunken cost fallacy" zone, but at this point, I want to try and see if I can get it working instead of documenting DigitalOcean from scratch (which I've 0 prior experience). I want to get these analytics merged ASAP so I can speed run the other features of the client.

@LuchoTurtle
Copy link
Member

LuchoTurtle commented Aug 13, 2024

This is ridiculous. I've tried all variations possible (inclusively separating each component from plausible that it depends on - Postgres and Clickhouse - and trying to deploy it separately -> https://blog.liallen.me/self-host-plausible-with-fly), even with the latest versions and I keep stumbling upon the same error when deploying the plausible service:

 create Plausible.Repo database if it doesn't exist
   WARN Reaped child process with pid: 377 and signal: SIGUSR1, core dumped? false
  00:15:52.411 [error] Ch.Connection (#PID<0.171.0>) failed to connect: ** (Mint.TransportError) non-existing domain
  00:15:52.413 [error] Postgrex.Protocol (#PID<0.181.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (plausible-ce-db:5432): non-existing domain - :nxdomain
  00:15:52.413 [error] Postgrex.Protocol (#PID<0.164.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (plausible-ce-db:5432): non-existing domain - :nxdomain
  00:15:52.413 [error] Postgrex.Protocol (#PID<0.163.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (plausible-ce-db:5432): non-existing domain - :nxdomain
  00:15:52.411 [error] Ch.Connection (#PID<0.170.0>) failed to connect: ** (Mint.TransportError) non-existing domain
  00:15:52.422 [error] Postgrex.Protocol (#PID<0.185.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (plausible-ce-db:5432): non-existing domain - :nxdomain
  ** (MatchError) no match of right hand side value: {:error, "killed"}
      (plausible 0.0.1) lib/plausible_release.ex:40: anonymous fn/2 in Plausible.Release.createdb/0
      (elixir 1.14.3) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
      (plausible 0.0.1) lib/plausible_release.ex:39: Plausible.Release.createdb/0
      nofile:1: (file)

I've tried everything:

I've been careful overriding the DATABASE_URL and CLICKHOUSE_DATABASE_URL because fly.io (for whatever reason) does not allow me to use names like plausible-db or plausible-clickhouse because they're already taken.

The worst part is that, at some point, having downgraded the versions of the Dockerfiles that are uploaded to fly.io (which is not advisable), I had it running normally on fly.io. But it's so inconsistent that it's hopeless. And making everything it worse, I've documented each step so far with fly.io, so it's been an absolute waste of my time that I could actually be productive somewhere else to deliver features, but instead I'm here stuck trying to get something that I already have working on localhost because fly.io gives me 0 control over accessing and using Dockerfiles after being deployed. All of this would have been much easier if they actually supported docker-compose, but they don't, so I'm forced to reverse-engineer and deploy separately each service found in Plausible CE.

I made good progress Sunday and made the effort to document everything on localhost, having stayed until 5 am to have it thoroughly written down. Throughout today (Monday), (which is already Tuesday, as I'm writing this), I thought it would be easy to deploy it to fly.io. Turns out it's just giving me yet another reason to hate the platform altogether. It has its perks, but it's so deeply frustrating when it doesn't work. And there's little I can do because I can't even fly ssh into the app's VM unless it's running, which I can't get to start in the first place.

I'm giving fly.io one last shot tomorrow morning. If I can't get it working, I'll just switch to another service, as Nelson suggested.
It will take me my day (and essentially make me bin all the fly.io docs I've written) just to document the deployment to yet another platform that it may or may not work. All of this whilst having everything working since Sunday makes me wonder why I'm burning my time when I could be useful somewhere else.

@nelsonic
Copy link
Member Author

This sounds frustrating. 😕
Definitely don't "bin" the work you've done for Fly.io just "park" it and open a thread on the fly forum. 💬
We will publish your fly notes with a disclaimer at the top informing people the area where they might get stuck. ⚠️

We will catch up on our morning call. 🤙

@LuchoTurtle
Copy link
Member

LuchoTurtle commented Aug 13, 2024

I've documented fly.io but left a warning of the error that's giving me, pointing to references that I've mentioned. No reason to keep going. I'm doing through DigitalOcean on a droplet, but I think I need a hostname to proceed (where's the dwyl domain?).

@nelsonic
Copy link
Member Author

Ref: #4 (comment)

@LuchoTurtle
Copy link
Member

LuchoTurtle commented Aug 14, 2024

https://analytics.dwyl.com/

It's working now. It's 6 dollars a month (cheapest Droplet).

On the first go, one needs to create an account. After that, no one can join in. I can change this setting to invite_only, if we need to. I created the account just to check if this works, and it does.

Tomorrow morning I'll shut down all the containers and re-deploy so @nelsonic can create an account and be admin.

@nelsonic
Copy link
Member Author

@LuchoTurtle can the admin account not be updated and the instance rebooted? 💭

@LuchoTurtle
Copy link
Member

The admin account is the first one to register. When I deploy with docker compose, I can set the DISABLE_REGISTRATION env variable to true, false or invite_only. I plan on doing the latter, so you can invite other members (I'm testing this as I'm writing this).

The account is a normal sign-up (asks you to register with e-mail and password). So you manage your own account, not the DevOps engineer.

@nelsonic
Copy link
Member Author

Ok. It's the way WordPress works. 👌

@LuchoTurtle
Copy link
Member

LuchoTurtle commented Aug 14, 2024

Yep.

So, I'm going to take down the website. Tomorrow morning, on standup, I'll deploy it and you create the account so you become the admin and create sites that you want to monitor. By then, I'll deploy the simple 10 line HTML on Github Pages so you can see it working.

To invite other people, you can follow https://plausible.io/docs/users-roles.

The site will be made available in https://analytics.dwyl.com/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or enhancement of existing functionality help wanted If you can help make progress with this issue, please comment!
Projects
Status: Done
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants