-
Couldn't load subscription status.
- Fork 450
Cover more Bash versions with Docker #116
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
Conversation
Revised the Dockerfile to use the official Bash images for improved version-specific test coverage. These images are based on Alpine. Given that we're only trying to support 3.2.57 and up (because OSX), coverage has been set to only go that far back (though there are older versions available in Docker image form if we would like to use them).
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.
Good idea @cdevinesr, thanks! Minor change requested, and I'll give it a test.
Dockerfile
Outdated
| @@ -1,8 +1,9 @@ | |||
| FROM alpine:3.6 | |||
| ARG bashver | |||
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.
Could we set a default version of latest here please?
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.
Good call. This is actually my first time using ARG and the documentation I had read didn't make any mention of being able to set default values (though that seems like a no-brainer in retrospect). Thanks!
If not specified at build time, it should default to using 'bash:latest'.
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.
Just a minor comment. Very nice!
.travis.yml
Outdated
| docker run -it bats:latest --tap /opt/bats/test | ||
| for bashver in 3.2 4.0 4.1 4.2 4.3 4.4 | ||
| do | ||
| docker build --build-arg bashver=${bashver} --tag bats:bash${bashver} . |
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 per #114, the image should be bats/bats:bash${bashver}, correct?
Also, I'm partial to adding a dash, i.e. bats/bats:bash-${bashver}, but I'm not super concerned 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 was playing off the previously set versioning in the Travis CI config. That change is definitely doable.
The added dash is probably a bit more readable, too.
bats/bashX.Y -> bats/bats:bash-X.Y
|
Another couple quick questions:
I see that all the builds currently pass on Travis, so that's comforting! :-) |
|
I was operating under the assumption that Travis is essentially running under a Regarding emission of Bash version, I could have it add that to the Docker image. Would something like this be acceptable? My previous commits were relying on the building of the image showing the version via the loop variable, but I realize that's not as accurate as doing something like this. |
|
Sure enough, it does not behave like |
This is better _and more accurate) than relying on digging for the tag.
Travis doesn't operate under any sort of 'set -e' like principles. The return code provided matches the return code from the last thing to run. This change ensures the last thing to run is a check against any failures inside the version loop.
Dockerfile
Outdated
| && ln -s /opt/bats/bin/bats /usr/sbin/bats | ||
| FROM bash:${bashver} | ||
|
|
||
| RUN bash --version |
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.
Rather than baking this into the image, I'm wondering if you can update the .travis.yml script to run:
docker run -it bash:${bashver} --versionThere 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.
Assuming it does so after building the bats image for that version, that should work fine, yeah.
.travis.yml
Outdated
| docker build --build-arg bashver=${bashver} --tag bats/bats:bash-${bashver} . | ||
| docker run -it bats/bats:bash-${bashver} --tap /opt/bats/test || RC=1 | ||
| done | ||
| [ ${RC} -eq 0 ] |
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'm thinking it might be nice to capture which version failed, something like this:
failures=()
for bashver in ...
do
...
if ! docker run -t bats/bats:bash-${bashver} --tap /opt/bats/test; then
failures="$(docker run bash:${bashver} -c 'echo $BASH_VERSION')"
fi
done
if [[ "${#failures[@]}" -ne 0 ]]; then
printf 'Bats failed under the following Bash versions:\n'
printf -- '- %s\n' "${failures[@]}"
false
fiThoughts? Make sense?
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.
Heh, realized I screwed up the first version of the code above, just edited it. Sorry for the spam.
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 see what you're going for and I like it. I can only assume Travis uses Bash for underlying shell stuff since [[ works. I'll mess with that and see if I can get it implemented.
|
Travis has the concept of a build matrix, which supports generating various cross configurations of OS/runtimes/environments. We can generate the build matrix to test multiple versions of bash without using a for-loop. This will give us first-class reporting on the travis dashboard (a distinct build job for each bash version) as well as implicit "-e like" exiting. PR (to this PR) here: cdevinesr#1 |
|
Related... correct me if I'm wrong, but for linux builds, the first step in the test script is redundant, no? script:
- bash -c 'time bin/bats --tap test'
- |
if [[ "$TRAVIS_OS_NAME" == 'linux' ]]; then
"docker build"
fiWe could change the test script to be: script:
- |
if [[ "$TRAVIS_OS_NAME" == 'linux' ]]; then
"docker build"
else
bash -c 'time bin/bats --tap test'
fiUnless I'm missing something? |
|
The only thing that initial test gets us over the added version coverage is timing, but that timing step could be added to the versioned checks instead, so we can get a better idea about performance on each Bash version. Unless there's a specific reason we'd need the tests executed directly under Linux but not inside Docker (I can't think of anything unique or special that would give us over just putting it into the version checks). I'll merge your changes (still new to Travis and your implementation is much cleaner than what I was doing). |
Bash version via build matrix instead of script loop
no worries, the yml file can be ... obtuse. For instance, the matrix.include is rather odd. If we left the os having both linux and osx, we'd end up with a 2x6 build matrix (12 jobs). Of course, all we want is the 1x6 linux builds (one for each bash version) and then an extra macOS build. The explicit matrix.include lets us add specific jobs after the build matrix has been calculated. (You can also do matrix.exclude in order to exclude build configurations that match a certain criteria, as well.) |
|
Yeah, that's what I got from reading over your changes and the Travis documentation. The more I think about it, the more I think perhaps the timing piece may not give us much extra. Travis already shows run time when running jobs, and there's not much I can think of offhand in terms of real benefits that we'd get from doing it manually with |
Since this is now being tracked via Travis CI, we don't need (or want, likely) to include the version check in the image build.
|
Hmm, can we set Alternatively, perhaps we should add |
|
It doesn't work, since It can be done with |
|
Alternatively, we could include two Dockerfiles - one that builds the image people would work with, and one that builds a 'testing' image that just performs the self test with |
|
Ah, asynchronous comments... So the Travis build time factors in the time it takes for the environment to get set up, which can fluctuate. Running Hmm, thought what I read in That said, |
|
Looks pretty close to the timing we'd get wrapping the call to Bats itself: I'm good with it, personally. |
This de-dupes the Bash 4.3 test by having all Linux-based testing happen inside Docker. Timing changes due to wrapping 'docker run' should be negligible.
|
I'm going approve, but will let @sublimino register his approval as well. For the record, though, I did crack the And then after building: The first Hence, |
|
BTW, I know this PR kinda ballooned into a more complex discussion pretty quickly, but thanks for your patience and persistence! It's going to be great having this level of coverage across Bash versions with every PR—props to @jasonkarns for the Travis magic, much better than my cruddy trickery. Also, I certainly feel greatly edified by this whole exchange! Learned a few useful new things. I'd trigger the merge myself right now, but will let @sublimino do the honors if he's satisfied. |
|
Awesome, I turn around for one evening and this happens! 😍 LGTM Now all that's left is to push passing and built image versions to the docker hub. Does anybody have the keys to add secrets to Travis? |
|
Btw @mbland @jasonkarns my instinct is to squash and merge this, which last time lost gpg signing. Do we have a preference on commit history maintenance? Asking users to rebase can be nightmarish for some etc etc |
|
Meh. For most team repos, I'm strongly against squash merging (since you lose history); but that's primarily so we don't have orphaned branches that can't be tracked down. And that assumes some level of rebasing on the author's part. Generally, I'm in favor of regular old merge commits. |
|
@sublimino I'm OK not squashing, and I'm less prone to rebase than I used to be. I would say let's just hit the big "Merge pull request" button, but now that I'm really thinking about it, it would be nice to have a signed commit somewhere in the process. First, could you hit the "Approve changes" link in the PR thread here first, just to clean that up? Then, do you want to push a local signed merge to master? Or I could do it. (And I wonder if we should do that as a course of habit.) BTW, I'm thinking we could stand to put @cdevinesr At some point, could you check out https://help.github.com/articles/signing-commits-with-gpg/ so any future PRs will have GPG-signed/verified commits? |
|
I've already planned to do so, and tried once before, but since I do most of my stuff from work, and I primarily use a variation of Cygwin (drive space limitations on my laptop that I have no way or authority to work around, unfortunately), gnupg does not seem to function properly on there. I'm working on getting enough space available to put together small dev VM with Vagrant that I can get a GPG key set up on. I'll see about accomplishing that today. |
|
@cdevinesr Well, don't let not having GPG set up be a blocker. If we end up doing signed merge commits as a matter of policy, it solves the immediate issue. Having incoming PRs with signed commits is more of a nice-to-have. Oh, and since you're up and about, feel free to sneak that docker run -it bash:${bashver} --version back in there... 🙂 Only if you've a reasonable chance; I don't want to block this PR any further. Also thinking we might want to specify |
|
I think as long as we sign the tagged release, that's sufficient; especially since that technically signs the tree up to that point. (And github signs merge commits, which is close.) |
|
Oh crap, I hadn't noticed GitHub signs the merges. Makes sense they'd do that. @sublimino Can you approve the review and just click the "Merge pull request" button, then? |
|
The official Bash Docker images don't go to that level of granularity, unfortunately. They're broken down strictly by major and minor, and don't let you drill down by point release. The list of available Docker image tags can be found here. I can add the version check back to the Docker image. I was avoiding it because it obviously adds another layer for something that merely outputs to the command line (so basically we'd have an "empty" layer), but if it's not a problem for you, I don't mind re-adding it. I think having that level of detail could prove useful in the long run, even with the dashboard covering major and minor for us. |
This will let us collect information about which point release is in use in the image. Results in a lot less digging through changelogs in the event of weirdness.
|
No, not as a layer in the Dockerfile, but as a command in the .travis.yml script! docker build --build-arg bashver=${BASHVER} --tag bats/bats:bash-${BASHVER} .
docker run -it bash:${bashver} --version
time docker run -it bats/bats:bash-${BASHVER} --tap /opt/bats/testHmm, https://hub.docker.com/r/library/bash/tags/ does have tags that drill down to the patch level, but it seems only for the latest versions. Bummer. |
|
Yeah, you're seeing what I was referring to. It makes sense to have a tag with point releases, but they don't keep one for each (that'd quickly turn into a lot of images to keep around). And I see I did that Dockerfile update before your comment. I've reverted that and pushed your suggestion. Still waking up this morning. |
|
Thanks again @cdevinesr and everybody - I'm ready to Push The Button in 2m I'd be inclined to sign merges in the future as it reduces the amount of code to review and sign at "tagging time", but either effectively achieves the same end. |
Since I'm paranoid that we might need to resolve an issue specific to 4.3.11(1)-release (or whatever the Bash version is in the stock Travis Linux image). Also, I didn't want to hold up #116 any longer with more tiny requests.
Bats 1.1.0 - 2018-07-08 This is the first release with new features relative to the original Bats 0.4.0. Added: * The `-r, --recursive` flag to scan directory arguments recursively for `*.bats` files (bats-core#109) * The `contrib/rpm/bats.spec` file to build RPMs (bats-core#111) Changed: * Travis exercises latest versions of Bash from 3.2 through 4.4 (bats-core#116, bats-core#117) * Error output highlights invalid command line options (bats-core#45, bats-core#46, bats-core#118) * Replaced `echo` with `printf` (bats-core#120) Fixed: * Fixed `BATS_ERROR_STATUS` getting lost when `bats_error_trap` fired multiple times under Bash 4.2.x (bats-core#110) * Updated `bin/bats` symlink resolution, handling the case on CentOS where `/bin` is a symlink to `/usr/bin` (bats-core#113, bats-core#115)
Revised the Dockerfile to use the official Bash images for improved
version-specific test coverage. These images are based on Alpine. Given that
we're only trying to support 3.2.57 and up (because OSX), coverage has been
set to only go that far back (though there are older versions available in
Docker image form if we would like to use them).