fly-apps / fly-laravel

Run your Laravel apps on Fly
40 stars 2 forks source link

Consolidate all user input commands #38

Closed Johannes-Werbrouck closed 1 year ago

Johannes-Werbrouck commented 1 year ago

I'd like to see all the questions directed at the user grouped before we do anything. This way, the user can just fill in everything needed to make the setup they want, and we can get going after all the questions are filled in. Here's my proposal: We put all the answers the user gives into an array, that has an array for every service the user wants to run. So the array could look like this:

$userInput = [
    'laravel' => [
        'appname' => 'app',
        'phpVersion' => 18
    ],
    'cron' => [],
    'mysql' => [
        'appname' => 'app-mysql',
        'database_name' => 'app' 
    ] 
]

We can set up our questions in 2 steps: first we'll ask everything laravel-related since that's definitely what the user wants. Then we can ask for extra laravel-processes like cron and queue workers, and then we can ask for extra services like MySQL or Redis. For each process or service we could create a function that just adds extra stuff into the userInput array. After that, we could have a function for every service that just executes the tasks needed to set it up.

So for each service we would have a input function that adds to the userInput array, and a setUp function that executes the tasks needed. Every task would have its own function just like it is right now for the laravel app setup. When the user answered all the questions, we can just run over the keys in the $userInput array and execute the tasks we need.

I believe this would provide a good user experience since the user can just answer all the questions and let the command handle everything after that, and it would provide a great structure for us to build upon because every service follows the same pattern. If we want to add LiteFS later on for example, we just add it to the 'select services' prompt and add inputLitefs() and setupLitefs() methods.

Let me know what you guys think of this!

fideloper commented 1 year ago

This is for the fly launch command, or something more abstract?

Johannes-Werbrouck commented 1 year ago

This is for the fly launchcommand! It's the only place where we'll have a lot of user input combined with a lot of different steps to execute

Johannes-Werbrouck commented 1 year ago

I wonder how this would work with secret questions like database passwords and the like. Is it safe to keep these in an array until we use them?

KTanAug21 commented 1 year ago

Don't roast me for this(please), but, for additional services like setting up mysql or redis( any extra fly app really! ), I think it might be a good idea to consider separating them into a separate fly command right( like "fly service:database(which will ask whether user wants mysql postgres or litefs) or fly service:cache(which i think would only provide redis for now")?

Possible reasons:

  1. We get a command for each different service types to add to a Laravel app ( isolating the services from each other and the launch command as well ) So if one command fails the other wont have to be effected ( "hey i can easily deploy a mysql app without deploying a laravel app!" )
  2. So that it can be used with existing Laravel fly apps that were not deployed/created through our fly launch command.
  3. The launch command is getting a bit crowded

Possible reasons not to:

  1. The user needs to run a separate command other than fly launch to set up their db, cache, storage, etc
Johannes-Werbrouck commented 1 year ago

Hmm, you do raise valid points. I'm thinking out loud here, but I guess the only issue I could see is fitting a laravel app and a mysql app (for example) together: The database name has to be set on both apps, for example. We could just ignore this and assume there's going to be a fly.toml file in the root directory and run it that way.

Yeah maybe you're right, let's do it that way!

KTanAug21 commented 1 year ago

Wew, I was not roasted. Thanks @Johannes-Werbrouck ! Yup That is one way to go about it, assume that the fly.toml file would be in the root dir, if no fly.toml is there, then sadly we dont get to edit a laravel fly app's fly.toml for the database details. But if it's there great!