-
Notifications
You must be signed in to change notification settings - Fork 48
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
Refactor bash scripts with some new updates #482
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this approach and the docs are awesome. I have some thoughts on how we might use this to share some common checks in both script/setup and script/system_check!
For example, right now we check a bunch of stuff in script/setup, but I think those checks could/should go in system_check and script/setup calls the system_check script. This way when you run Lucky Dev and you forget script/setup you still get a lot of nice errors if it can't find psql, crystal, yarn etc.
The only problem is in the script/setup you may not have the redis/elastic/whatever running and it may not make sense to require that at the beginning of the setup script...but maybe it does since if you need those for the app to work then it might make sense to check they are running in the setup script too...I think it'd work and be nice. Thoughts?
I'm very excited about having a convention for where to put these checks. In almost every codebase I've been on there are notes in the README (if I'm lucky) and checks in setup (again, if I'm lucky haha). Having a clear place will really help with this, especially if we have some nice default ones like crystal, yarn, postgres, etc. checks |
Just put this in to my project, and it's working out great
The one I'm using is: redis-cli ping
if [ $? -ne 0 ] # Check the exit_code of the previous task. If not equal to 0, then print_error
then
print_error "Redis is not currently running. Be sure to boot it first."
fi |
I really like this idea |
Ok, after bashing my head against this code, I was able to get some other stuff working as well specific for my apps. I wonder if this should include some bash guides, or helpful tips? Maybe even a few helper methods to check some things? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes totally. A short guide with examples would be amazing. I think that could probably go on the website with links to it. Otherwise this file will be YUGE
Also did you get a chance to look at the comment about putting the checks we have in script/setup in script/system_check instead? Stuff like checking for process runner, yarn, pg can go here. Then in script/setup we call this script.
Would be super cool so you could have those checks in both the setup and when starting the app! Thoughts?
Ok, after this is merged in, I'll open up an issue about writing some docs on it. I was thinking about the setup stuff coming over to this, but had a concern. I originally saw this as purely a way to check and make sure things that need to be running for you to work on the app are actually running. I'm wondering if it would slow down the boot time if it has to check these on every boot:
To me, these make sense to check when you setup your app, but once you've done that, you don't need to check them again. Unless you randomly uninstalled yarn or pg? but that feels edge casey... Let me know if I'm just over thinking this 😅 I guess we could throw them in and try it out, if it gets clunky, we just rip it out. Pre 1.0 is the time to experiment 😆 |
@jwoertink I think that those checks are super fast typically, also system_check will run in a separate process so will not block yarn or crystal compilation. The other part of this is what if you have a new check in setup because someone added elasticsearch to the setup checks. If you already had the app setup you'd start with The other part is that sometimes people just don't run the setup script 🤣 so having this would be an extra layer of helpful checks. Does that make sense? EDIT: Actually one downside here is the extra output. I'd say the checks for yarn/crystal/pg should go in system_check, but process runner probably doesn't need to. So I think anything at the top of script/setup that doesn't output anything on success would be a good candidate to put in check_system |
ah! Ok, Ok, I'll add that in... Also, side note, you've called it |
Co-Authored-By: Paul Smith <paulcsmith@users.noreply.github.com>
Co-Authored-By: Paul Smith <paulcsmith@users.noreply.github.com>
Co-Authored-By: Paul Smith <paulcsmith@users.noreply.github.com>
Yeah I noticed that. I think you were right. I intuitively call it system_check and seems you did too so we can switch it back. My bad! 🤣 |
Oh, here's a question. In the setup script, we create the DB, then check to see we can connect before migrating. We are also saying postgres has to be connected before booting. It's a whole chicken an egg deal now when running a setup because it'll be like: When running setup
When running lucky dev, it won't matter. Should the setup script just catch that first error and skip past it? |
maybe I can just pass in a flag on whether or not it should be checked. Add it in the Procfile, but tell it no for setup |
I’m thinking we don’t do the verify Db in the system check and only do it in setup so the script doesn’t get too complex. Kind of a bummer to not have that but I think it’ll be ok since we have good errors when it can’t connect |
…anyway. system_check is now an ECR template to add additional scripts if you generate a browser app. Moving all of the system_check stuff from the setup script and cleaning up the setup script
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks awesome. Very stoked about this. A few suggestions, but looks good to merge when you're ready
# echo "do linux stuff" | ||
# fi | ||
is_linux() { | ||
if [[ "$OSTYPE" == "linux"* ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems most people I asked get back linux-gnu
on arch, debian, or other flavors. I didn't actually test this though, but I assume it works.
# print_error "Redis is not running." | ||
# fi | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thought was having a very clear place to put your own custom stuff. This file is already really busy, so if you're new to bash, then it might not be apparent where you'd do stuff, or what you'd do.
Ok, I added a bunch of goodies here. I threw this in to a fresh 0.19 app and it worked great. If y'all wanna give it a once over that'd be cool, but I think it's ready to go now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love the new function helpers. So nice to have those abstracted away. I always have to look up this stuff so it’s nice to have it right there.
A few small suggestions. The most important is moving shell to the Procfile since it is the only thing that needs it. I think that should work 🤞
# Prints error and exit. | ||
# example: | ||
# print_error "Redis is not running. Run it with some_command" | ||
print_error() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes sense in the text helpers script but up to you. I don’t feel strongly about it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that at first, but because it does an exit, and has specific text in it, it felt more like a function to me
…ove it there. This way if you want to call the system_check from some other script, you can.
* adding a system_check script for pre boot tasks in development. * Updating the system_check with some better examples, and a place to start writing your checks. * I think you can do this... * actually use the system_check to make the examples of what to do easier to understand. * renamed system_check to check_system * Update src/web_app_skeleton/script/check_system Co-Authored-By: Paul Smith <paulcsmith@users.noreply.github.com> * Update src/web_app_skeleton/script/check_system Co-Authored-By: Paul Smith <paulcsmith@users.noreply.github.com> * Update src/web_app_skeleton/script/check_system Co-Authored-By: Paul Smith <paulcsmith@users.noreply.github.com> * calling check_system system_check again because we kept call it that anyway. system_check is now an ECR template to add additional scripts if you generate a browser app. Moving all of the system_check stuff from the setup script and cleaning up the setup script * huge refactor of script setup system. Added some new bash helpers * Since the Procfile is the only thing that needs that SHELL, we just move it there. This way if you want to call the system_check from some other script, you can. Co-authored-by: Paul Smith <paulcsmith@users.noreply.github.com>
Fixes luckyframework/lucky#953
This has evolved a bit from it's first iteration. This PR refactors the setup script a bit and adds in some new stuff.
system_check
script which is added to yourProcfile.dev
. This can check for things that need to run before your app is booted each time.setup
tosystem_check
. Nowsetup
just installs what it needs.setup
script which moves those abstractions to a new helper directorytext_helpers
andfunction_helpers
to make writing bash easier because let's face it.. it's hard