WordPress / openverse

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Home Page:https://openverse.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Local Plausible setup can fail

obulat opened this issue · comments

Description

Running just init should set up local plausible for analytics, but on my machine it throws an error.

Reproduction

  1. Run `just init`
  2. See error.
cd .. && ./setup_plausible.sh
ERROR:  function digest(unknown, unknown) does not exist
LINE 4:   (1, 1, 'Development', 'aaaaaa', encode(digest('this_is_a_s...
                                                 ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

Environment

  • Device: Apple M2 Pro
  • OS: Mac OS Sonoma 14.5
  • Other info: OrbStack

Additional context

encode was added in #4283. @sarayourfriend, do you know if the patch in Fix section below is the right way to go? If so, I'll convert this into a good first issue.

Fix

Adding the following patch works:

Subject: [PATCH] Set up pgcrypto for plausible
===================================================================
diff --git a/setup_plausible.sh b/setup_plausible.sh
--- a/setup_plausible.sh
+++ b/setup_plausible.sh
@@ -15,6 +15,7 @@
 source docker/plausible/env.docker
 
 docker compose exec -T "$PLAUSIBLE_DB_SERVICE_NAME" /bin/bash -c "psql -U deploy -d plausible <<-EOF
+  CREATE EXTENSION IF NOT EXISTS pgcrypto;
 	INSERT INTO api_keys
 	  (id, user_id, name, key_prefix, key_hash, inserted_at, updated_at, scopes, hourly_request_limit)
 	VALUES

@obulat The patch you shared works for me, yes. Here are the Postgres docs for reference: https://www.postgresql.org/docs/current/sql-createextension.html

I don't think this is a good first issue because ideally fixing it would also address why this can fail without breaking CI.

Hi @obulat I'd like to take on this(I think I worked on the initial issue). @sarayourfriend when you say "fixing it would also address why this can fail without breaking CI" can you be clearer as to what this entails? Meanwhile, I also agree with the solution @obulat shared.

I don't think this is a good first issue because ideally fixing it would also address why this can fail without breaking CI.

The CI does not check the returned after just init, and local Plausible setup is never used in testing. We only ever check if the analytics requests are sent, and abort the requests in Plausible tests.

Could you clarify what "address why this can fail without breaking CI." means? Should the CI fail if Plausible is not set up correctly?

@madewithkode, thank you! I'll wait for @sarayourfriend's reply before assigning.

Yes, CI should fail if the init scripts have a non-zero exit code, but it doesn't look like CI ever runs just frontend/init, only just api/init.

We can add a check for Plausible to the nuxt-checks step:

diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml
index e148ae733..d32bdac43 100644
--- a/.github/workflows/ci_cd.yml
+++ b/.github/workflows/ci_cd.yml
@@ -641,11 +641,14 @@ jobs:
         name:
           - unit_test
           - test_media_props
+          - frontend_init
         include:
           - name: unit_test
             recipe: frontend/run test:unit
           - name: test_media_props
             recipe: frontend/generate-docs
+          - name: frontend_init
+            recipe: frontend/init
 
     steps:
       - name: Checkout repository

That might be enough to solve that part of this @madewithkode

Thanks @sarayourfriend. I'd look into this.