-
Notifications
You must be signed in to change notification settings - Fork 20
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
bats v1.2.1 testing issue - preserve exported bash functions #17
Comments
Hi. I reproduced your problem! I will try to find the cause. |
I think I have found the cause. I ran using the
In bats v1.2.1 in the bats script at the end is a
I reverted to v1.2.0 which does not have this line and am able to run, so tend to think this is the cause. Unsure how to fix it. I also would like to take the time to say - thanks for sharing this work, I am trying to build a Dojo container for a docker image pre-commit hook. I really like this work and appreciate your examples. I will tag my Dojo images so that they can be found for use by others. |
Thanks for your investigation. I agree with the cause and will do more investigation in order to make Dojo work with latest Bats. Can't promise, however, that I will fix it today. Thanks for the nice words! :) |
You are most welcome. No rush on the fix, I will work with the v1.2.0 for now and update when it is addressed. Sorry I could not be more helpful in fixing the issue at this time. I noticed you had switched to use Python test instead of bats - is that the path you will use going forward for Dojo and Dojo images? Just wondering which you recommend, or is a mixture appropriate? I also use aws-vault when using AWS, I was able to get this working passing a value to the docker options, just wondered if this is a good pattern with Dojo. |
We decided to move away from bats, because there was some time when it was unmanaged sstephenson/bats#150. We had some problems running the dojo bats tests (I remember for sure that the exit status was invalid for Alpine Linux). Perhaps it is already fixed in bats-core. All our machines had Python installed, so it was easy to switch. For Dojo we will continue to use the Python tests, but for Dojo images you can use whatever framework suits you. Sometimes you may think that adding another language (Python) just for tests is too much for your stack and sometimes you may want to use PyCharm and be able to debug in IDE. Sometimes you can run Dojo image tests in another Dojo image (so in result it does not matter what your machine has installed, because you can just docker pull a ready environment - a Dojo image to run tests in it) and sometimes it is strenuous to do (e.g. because of mounting the volumes and file permissions). Great found with the aws-vault! I have not used it before, but I worked with AWS and know about STS. Other ideas are listed in the readme https://github.com/kudulab/dojo#secrets. The most secure solution I've used so far is with Vault from Hashicorp. This solution requires a standalone server to host the secrets but I read that aws-vault also needs a local EC2 instance. |
If you already have credentials in a file in your home directory, then they are already mounted (read-only) into |
I use the 99Designs aws-vault (https://github.com/99designs/aws-vault) - which stores your credentials in a keystore on your host machine. Was able to get the AWS credentials into the container when run using the following syntax:
Often run terraform with different profiles, so can pass the relevant profiles and set up some aliases to simplify the command. Am exploring lots of ways to use this awesome work. Once again many thanks for all your efforts. |
This issue will be solved in Dojo 0.9.0. PR is already created. Reason of this issueWhenever a bash function is exported in the following way:
Bash creates an environment variable, in this case:
So far, when there was any bash function exported, Dojo resulted in an error like:
This was made visible when using Bats-core v1.2.1, because they exported a bash function in this PR. Dojo interpreted this bash environment variable as a multiline variable and attempted to serialize it with base64. It was fine, but deserialization lead to the error above. SolutionDojo 0.9.0 treats all the environment variables which names start with "BASH_FUNC_" prefix and which values start with "()" as exported bash functions and serializes them into /etc/dojo.d/variables/01-bash-functions.sh file. This file is sourced at a container start. However, the bash functions are not preserved later, because It was decided that Dojo 0.9.0 should follow the sudo's practice and not try to add a work around leading to bash functions being preserved. But, it was made easy for the end user to preserve them with:
Usage instructions are added to readme. |
@xmik thanks for the awesome explanation of the issue and fix implementation. |
@psellars-hyprnz - I'm glad that you found this problem and we could make Dojo better :). Do not hesitate to find more :) Dojo 0.9.0 is released, thus I'm closing this issue. |
I am trying to test a dojo image and when I run bats am seeing the following issue
Wondering if anyone may be able to shed some light on this - when I
dojo
into the container the file is empty, and when I run the command usingdojo "hadolint --version"
it works fine. Only difference is running it usingbats
from CLI in test.Am using bats version 1.2.1
The text was updated successfully, but these errors were encountered: