is there a way to only (define and use) environmen...
# general
b
is there a way to only (define and use) environments locally and skip in the CI?
r
Yes it's explained in the env doc towards the end. Pants looks for
pants.ci.toml
to run CI specific stuff.
b
hmm, it might be a way to go however I'm still missing something. I build a pex_binary locally in parameterized environments (one for macos_arm64 and one in a docker_environment for linux_x86_64) and I'm adding the latter to a docker_image. So I'd need to have a different dependency locally and on the CI for the image for this to work.
maybe a macro would be more suitable
a
I have the same question, replying just in case someone pops into the thread with an answer
c
So iiuc your setup ought to look something like:
Copy code
# BUILD
pex_binary(name="bin", environment=parametrize("local", "linux"), ...)
local_environment(name="local", ...)
docker_environment(name="docker", ...)
docker_image(name="image", dependencies=[":bin@linux"], ...)
Copy code
# pants.toml
[environments-preview.names]
local = "//:local"
linux = "//:docker"
Copy code
# pants.ci.toml
[environments-preview.names.add]
linux = "//:local"
that is, locally you use two environments while in CI you short circuit the linux env to be the same as the local one. Not tested this myself, so pls share how it turns out if you try this šŸ™‚
a
Might give it a go later. I, a sensible person, use Linux, but most of my team are running MacOS, and it irritates me šŸ˜„
šŸ‘ 1
šŸ˜… 2
c
so for you Bob, you’d likely want a
Copy code
# .pants.rc
[environments-preview.names.add]
linux = "//:local"
to mimic the ci setup and not use docker at all.. šŸ˜„
šŸ‘ 1
a
Bless you, Andreas.
šŸ™ 1
b
thanks for the suggestion @curved-television-6568 unfortunately it didn't work for me, as in the CI environment it sees 2 environments (local and linux) that are compatible and doesn't know which one to choose. Overwriting the environment-preview.names section to only have linux defined in CI didn't work either, the pex_binary expects a named environment local.. I'll keep trying
could we skip the parametrize targets based on a condition? or provide a list of available environments as argument to parametrize (instead of hard-coded ones)
c
I think a better answer is called for, but a hacky idea for ā€œprovide a list of available environments as argument to parametrizeā€ could perhaps be N.B. this is huge HACK
Copy code
environment=parametrize(*env("ENVIRONMENTS").split())
also, I think there’s an open issue wrgt parametrizing with only a single arg, so this may not even work, I realize… ah, yes https://github.com/pantsbuild/pants/issues/16978
2 environments (local and linux) that are compatible and doesn’t know which one to choose.
when the two environments refers to the same actual target, I think it should be smart enough to use it, so this is a bug/feature request I think.
b
I'm getting an error:
AmbiguousEnvironmentError: Multiple
local_environment
targets from
[environments-preview].names
are compatible with the current platform
linux_x86_64
, so it is ambiguous which to use: ['//:local_linux', '//:local_linux']
I think I got it working by having the docker environment fall back to local. Could also disable docker execution in the CI? Overall, it feels like there's some work to be done with respect to environments, but you know this already
šŸ‘ 1
c
Thanks for the feedback. And yes, it is in experimental/preview so rough edges are to be expected.