compose_yml
compose_yml copied to clipboard
Valueless keys
In environment
sections you can specify valueless keys like
environment:
- FOO
- BAR
And docker-compose will pick up the relevant values on the machine compose runs on.
The other form,
environment:
FOO:
BAR:
would require serde_yaml changes, I believe.
Serde_yaml sees the second form as having null values. This matches other YAML libraries I tried.
extern crate serde_yaml;
use serde_yaml::Value;
const Y: &str = "
---
environment:
FOO:
BAR:
";
fn main() {
println!("{:#?}", serde_yaml::from_str::<Value>(Y).unwrap());
}
I don't know if there's a spec for docker-compose.yml
beyond the reference, but it's documented at https://docs.docker.com/compose/compose-file/compose-file-v2/#environment with no minor version qualifications.
The reason I didn't add an assert_roundtrip!
test is that this already fails even for keys with values because compose_yml
canonicalizes the array form to the object form. i.e.
environment:
- FOO=bar
fails an assert_roundtrip!
with
left: `Object({"environment": Object({"FOO": String("bar")})})`,
right: `Object({"environment": Array([String("FOO=bar")])})`'
What else needs to happen here?
I don't see it documented anywhere but it does happen.
khuey@workspace:~/scratch/docker-test$ docker -v
Docker version 1.13.1, build 092cba3
khuey@workspace:~/scratch/docker-test$ docker-compose -v
docker-compose version 1.18.0, build 8dd22a9
khuey@workspace:~/scratch/docker-test$ cat docker-compose.yml
test:
image: jwilder/whoami
env_file: test.env
khuey@workspace:~/scratch/docker-test$ cat test.env
TEST_VALUE
khuey@workspace:~/scratch/docker-test$ export TEST_VALUE=Hi
khuey@workspace:~/scratch/docker-test$ docker-compose up -d
Recreating dockertest_test_1 ... done
khuey@workspace:~/scratch/docker-test$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
56dfcff90ec5 jwilder/whoami "/app/http" 3 seconds ago Up 2 seconds 8000/tcp dockertest_test_1
khuey@workspace:~/scratch/docker-test$ docker exec -it 56df sh
/app # echo $TEST_VALUE
Hi
(docker-compose behaves this way with an explicit version: "2"
in the compose file as well)
@khuey OK, if docker-compose
supports it, we can certainly implement it.
But please keep in mind my comments on https://github.com/faradayio/cage/issues/87#issuecomment-354767603. We don't have any kind of coherent, principled model for how cage
should handle env interpolation, so I'd be careful about relying on these features too heavily if you're using them with cage
—at least until we have solid conceptual model about how they should work.
Anyway, this looks about ready to merge. If you don't hear from me by Wednesday, please ping me.