Add ability to exclude specific variables from cache-hashes
We use CircleCI as our CI tool, and I spent the last day or so debugging an issue with the cache (that is, it isn't using it). Finally I realized please includes environment variables in computing cache keys.
This is problematic, as to use Docker in a build in CircleCI (i.e. to use packer) you run the setup_remote_docker build step which allocates a docker executor for you and sets environment variables (DOCKER_HOST, DOCKER_CERT_PATH, etc). These are different every run (even when you re-run a build on the same commit), and so the always results in cache-misses.
I understand (and generally agree with) including environment variables in cache keys (as they very much can affect the build). However there are exceptions (like this) where these values do not meaningfully affect the output (another example would be proxy settings).
Would it be a reasonable request to allow whitelisting certain PassEnv-ed environment variables from the cache-key computation? I imagine this would be implimented like excluding them from the hash computation, or normalizing them to some magic value.
To clarify - Please doesn't include all environment variables in hashes, so this is happening because you are passing them in via PassEnv?
I conceptually don't like the idea of having non-hashed inputs, but can see the point here. I guess it allows you to take that choice into your own hands so if it does break correctness you've opted into that.
so this is happening because you are passing them in via PassEnv?
That adds up. Yes I've passed them in via PassEnv.
I conceptually don't like the idea of having non-hashed inputs...
I don't either. However in practice there are going to be variables that necessarily change, but are known to not meaningfully affect results (DOCKER_HOST, as well as proxy configurations. Generally "where to go" information rather than "content" information).
I think a decent solution to these concerns is a good name. I.e.:
PassEnv = DOCKER_HOST would work as normal
PassUnsafeEnv = DOCKER_HOST would work like PassEnv, but would exclude the value of DOCKER_HOST from the cache key.
Would you mind sharing a bit further why you're including DOCKER_HOST in PassEnv, if it does not affect the build output? Would it be possible to exclude this from the target, build your binary, and then manually invoke the built artifact with an environment which includes DOCKER_HOST?
To quote my original statement:
...to use Docker in a build in CircleCI (i.e. to use packer) you run the setup_remote_docker build step which allocates a docker executor for you and sets environment variables (DOCKER_HOST, DOCKER_CERT_PATH, etc). These are different every run
My build artifact is a docker image.
Think about it like this: if I need to download an external python library (i.e. pip_library) but my network requires I access the internet through a proxy, then I must get this proxy configuration into my build.
Does the use of this proxy affect the output? No. In fact I have the hash of the library so I even validate what I download. But without this proxy I cannot access the internet.
What if I need credentials to download a dependency? Should my build be considered changed because I have different credentials (think: shared cache box in the office, everyone has different credentials). I'd say no. But I need those credentials to access the dependency.
This is the same. DOCKER_HOST is necessary to use docker, and in my particular case (on CircleCI) is different on every run.
It's not "it does not affect the build output" it's "its value does not affect build output". It must be present (and accurate) for the build to function, but the value doesn't affect the result (again, like a proxy configuration).
Realized I never added a comment here, but #768 would be one potential way to implement this feature.
@jacobwgillespie What would you advise for now while progress towards merging #768 seems stalled? How can I smuggle $HOME/.aws to commands anyhow?
@rulatir if you're okay with the build cache being invalidated when your access keys change, you can just set them with PassEnv.
Beyond that, unfortunately I don't think I can be of much help - I'm not actually using please for anything, the company I was working for at the time did not adopt it as a build tool.