Giter Site home page Giter Site logo

Comments (10)

ganigeorgiev avatar ganigeorgiev commented on May 12, 2024 2

Non-interactive cli execution seems to be a common request (#29).
In that case, I'll consider removing the initial admin create interactions and will replace them with a "Installer" web page.

In the meantime, I'm not sure what your use case with Docker is, but often tasks that need to be executed only once could be performed inside a DB migration - https://pocketbase.io/docs/db-migrations/.

from pocketbase.

ganigeorgiev avatar ganigeorgiev commented on May 12, 2024 2

@krushiraj If you have the time, feel free to pick it.

I was planning to work on it some time during the next week (or the week following it). Here are some suggestions about the implementation:

  • add a healthcheck endpoint that could return some json map that has a property installed, readyToUse, hasAdmin or something along the line that will be true if we have at least one admin, or false otherwise (need tests)
  • change the admin apis create handler to accept guest submits when there aren't any admins (need tests)
  • update the js-sdk package to have the new healthcheck endpoint (need tests)
  • on the frontend when initilizing the web page add a call to the healthendoint and if the map value is false show the installer page (could also store the healthcheck result in localstorage to prevent calling it on each page refresh)

from pocketbase.

krushiraj avatar krushiraj commented on May 12, 2024 1

No issues :).

I can give it a try and draft a PR. I will mention it here once I’m done.

from pocketbase.

krushiraj avatar krushiraj commented on May 12, 2024 1

Okay. I actually though of going with the later approach to redirect to register admin when there are no admins.

from pocketbase.

wilj avatar wilj commented on May 12, 2024

In the meantime, I'm not sure what your use case with Docker is, but often tasks that need to be executed only once could be performed inside a DB migration - https://pocketbase.io/docs/db-migrations/.

In Docker/Kubernetes it's common to pull the default account information from a secret when bootstrapping a new service. The usual pattern is to provide a combination of environment variables allowing the consumer to pass either the value, or the path to a file containing the value.

For example, PostgreSQL has environment variables for POSTGRES_PASSWORD and POSTGRES_PASSWORD_FILE

I've found a handy pattern in Go is to accept these as arguments to a CLI command, instead of reading the environment variables directly. Then anyone using it in a container can run CLI commands in an initContainer or entrypoint script.

Another example is Keycloak, which provides a CLI for managing users that is easy to script.

I'm interested in implementing this feature if it sounds good to you.

from pocketbase.

ganigeorgiev avatar ganigeorgiev commented on May 12, 2024

@wilj As mentioned in the closed PR #29 - for PocketBase always providing an admin email and password as flags or env variables doesn't make sense, because this is required only when you start the application for the first time (aka. when you don't even have a database file).
One time operation should be done with DB migrations (its practically the same when you want to seed or change the schema of your database).
Alternative and more easier approach, compared to the "Installer" web page, could be to provide a separate command create-admin that will have to be executed before starting the server, but that's not very user friendly.

from pocketbase.

krushiraj avatar krushiraj commented on May 12, 2024

Actually my point of creating that PR was to provide email and password for admin in a way so that in one off scripts we can easily set first admin details.

The migrations method you suggested is good but problem with that is we can’t use that with the binary that is released. Hence we must clone repo and add code to migrations file and add it. Which is complex than having a support to add new admin via CLI or web page.

Also, the suggestion you gave on #29 doesn’t seem to work.

Currently I have a work around. I locally created an admin by interacting with cli and copied pb_data directory. So I know I would have a new set of default email and password for that instance. Then I create a new admin and delete the default one.

PS: This comment is just to give idea on how to host it easily using docker. https://github.com/krushiraj/pocketbase-docker (I know I cloned the repo in this docker solution, that is because I see errors while running the binary. Used amd64/ubuntu and download adm64 binary. But I still get exec format error, which usually is an error when the architecture of compilation is different)

from pocketbase.

ganigeorgiev avatar ganigeorgiev commented on May 12, 2024

@krushiraj Thanks for clarifying. Sorry for the non-working example. I didn't tested it. It doesn't work because we outputing other things to the stdout.

But anyway, adding a new "Installer" page will remove the cli interactivity and resolve the issue.

from pocketbase.

ganigeorgiev avatar ganigeorgiev commented on May 12, 2024

@krushiraj I'll assign the issue to me and will start working on that tomorrow. Actually I think it could be implemented even easier, without the healthcheck endpoint, by adding a middleware to the ui file serving handlers that will always redirect to the installer page when there is no admin (the query will be done outside of the handlers).

from pocketbase.

ganigeorgiev avatar ganigeorgiev commented on May 12, 2024

The new Installer page was added in the v0.2.0 release.

The implementation ended up a little more complicated and hacky than I initially though, because we are using client-side fragment navigation for the admin UI (aka. /#/...) and the path is not visible on the server-side and therefore a special installer query parameter was introduced.

Please report if you stumble on something or it doesn't work as expected.

from pocketbase.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.