Use containers for local development#749
Use containers for local development#749djberg96 wants to merge 14 commits intostefankroes:masterfrom
Conversation
|
Hey Dan! Wondering if that PR ballooned a little bit
I had on my TODO list to test the I will make Since CI runs tests, I'm hesitant to add a second testing environment. If I misunderstood, please let me know. This does look like cool stuff. |
|
ok. I fixed a merge conflict. (you may have to pull down) But I'm hoping we can maybe just gate the mysql2 driver? |
|
@kbrock Hola! You wouldn't use this in CI, this would only be for local development. It may feel a bit redundant if you already have a github workflow, but it makes local development easier. While mysql2 was the main motivation for this PR, really it would be beneficial to anyone who doesn't want any of the database engines installed locally, but still wants to test local changes against all of them. |
|
@kbrock ok, rebased master and updated the Gemfile. I'm not familiar with trilogy, but based on what you did I guessed as to the proper handling. |
kbrock
left a comment
There was a problem hiding this comment.
If you are running bundle install, then you are running tests locally?
Or are you thinking you'll only test in a container?
Based on the rakefile, it looks like you plan to run tests only in Podman.
If you are testing in a container, do you need to bundle install?
If you are developing locally, it seems a pain to have to remember to:
BUNDLE_INSTALL_POSTGRES=1 BUNDLE_INSTALL_SQLITE3=1 BUNDLE_INSTALL_MYSQL=1 bundle install
DB=pg BUNDLE_INSTALL_POSTGRES=1 bundle exec rake
Also, what database are you running?
Do we really need to guard anything other than MySQL?
I'm leaning heavily towards only guarding the mysql2 driver. Don't really see the need to guard against SQLite3, PG, or even Trilogy.
ancestry.gemspec
Outdated
| docker_artifacts = Dir[ | ||
| 'Dockerfile*', | ||
| '.dockerignore', | ||
| 'docker-compose.y*ml', | ||
| 'compose.y*ml', | ||
| 'docker/**/*' | ||
| ] | ||
|
|
There was a problem hiding this comment.
We only have a wild character in the lib directory.
Does What does this filter out?
There was a problem hiding this comment.
Going to reiterate, The original s.files has wildcharacters and does not touch docker_artifacts.
Remove this unless you see a need that I'm missing
Gemfile
Outdated
| gem "sqlite3", "~> 1.6.9" if ENV["BUNDLE_INSTALL_SQLITE3"] | ||
| gem "pg" if ENV["BUNDLE_INSTALL_POSTGRES"] == "1" |
There was a problem hiding this comment.
When using appraisals, we generate gemspecs for each Rails version.
We can't carry the if condition across. So we'll need to ensure the gemspec gets all the necessary gems.
Please add appraisal condition to SQLite and PG. blocker.
|
ok I ran locally. I will try see if I can get something running off podman with a local Container/Docker file. I think adding a few |
|
I would say any library that has any sort of external dependency, especially if it requires configuration (like a database), should at least have the option to run in a containerized environment. You, personally, may have everything setup locally so that you don't need to do it, and that's fine, but it makes contributing easier for other people. So yes, I would say it should be done for postgres and sqlite as well. I've done this for a couple of my libraries now, like rkerberos, since I have absolutely no desire to install a kerberos server on my personal computer. ;) |
|
I'll see what I can do about cleaning things up a bit with the Rakefile and gemspec. |
|
Ok, I guess I should actually add a proper compose file so we can run tests with PG or MySQL instead of sqlite3. |
|
Please understand my primary thought: If you are not running tests locally, then you don't need to bundle install locally, because you don't need to develop the gem locally. This is orthogonal to running tests in a container. Because we could add Podman support without implementing any of the bundler environmental variables. Thought I might be missing something about why you need to bundle install. Second though |
|
@djberg96 miq slack? |
|
Ok, hopefully this PR makes more sense now and is more useful, as it was what I had originally intended but apparently never actually implemented. Anyway, so now you can do the following, which will spin up the appropriate container with the database engine of your choice and run the tests:
And you'll see some output like this: I guessed a bit on the gemspec, let me know if it needs updating. |
|
Alright, updated so that it will default to sqlite3, so you can just run As discussed, this is a lighter approach than the act-cli approach, since that will take longer and runs through more variations that are currently setup in the github workflow. I personally prefer this, but if you decide you'd rather go with the act-cli approach I will understand and you can close this. |
| task :build_sqlite do | ||
| compose_build("sqlite") | ||
| end |
There was a problem hiding this comment.
we are in 2 modes:
DB=pg rake testrake compose:build_sqlite
Why not DB=pg rake compose:build?
Dependencies probably work better for the build_sqlite long version but this adds quite a few cookie-cutter methods.
- How do you typically run local tests?
- How do you typically run container tests?
- I don't care if you call this docker or container for calling podman/docker.
Would prefer to remove many of these aliases. Just pick one way and if it is wrong, we can pick another.
DB=pg rake test
DB=pg rake container:test # docker:test test:dockerI agree act is overboard, but it is nice to maintain only 1 set of container commands.
I keep going back to thinking your changes could be an add on gem or a local file and not part of this project.
Sure, it may need some modifications, and I'm good with that. But the duplication of the github action has me concerned.
There was a problem hiding this comment.
Ok, I've updated it so that rake container:test honors the DB environment variable, if present.
Description
You have database requirements in your Gemfile. I don't want to install mysql2 locally.
No, you can't make me, you're not my dad.
Let's use containers!
We'll prefer podman, and fall back to docker because that's the way, uh-huh, uh-huh, I like it.
The gemspec has been updated to ignore these files, since I assume you don't want them bundled in an actual release.
Before
Sadness. Storm clouds hovered nearby, and I could barely get out of bed.
A local
bundle installfails because I do not have mysql2 installed. It's only a coincidence that I have sqlite3 and postgresql installed, otherwise those would've failed too.After
Joy. The skies are clear and I hear birds singing outside. I am ready to take on the world.
I can run
bundle install test:composeand everything builds in the container, and all tests pass.Type of Change
Checklist
bundle exec rake test)No new code really, other than some Rakefile and Gemfile updates. This is just infrastructure.
How Has This Been Tested?
The proof is in the pudding. Does
bundle exec rake test:composework locally?Yes, on both Fedora Linux (podman) and MacOS (Docker).
Le proof!