Merging Yaml arrarys nested
This is a bit of a follow up to Ben's post is there YAML syntax for sharing part of a list or map, although I am taking it one step farther and inheriting a third time after merging two arrays.
I am creating a docker-compose.yml
file and want to do anchors and alias as such
x-template:
base-template: &base-template
environemt:
FOO=BAR
custom-template-1: &custom-template1
<<: *base-template
environment+:
FOO2=BAR2
services:
service-1:
<<: *custom-template1
but I get the error
Unsupported config option for services.service-1: 'environment+'
If I do not use the environment+:
at the custom-tamplate-1:
level, or if I define environment+:
at the service-1:
level it works.
I'd like the result to be
services:
service-1:
environment:
FOO:BAR
FOO2:BAR2
is it possible to achieve what I want?
arrays dictionary docker-compose yaml
add a comment |
This is a bit of a follow up to Ben's post is there YAML syntax for sharing part of a list or map, although I am taking it one step farther and inheriting a third time after merging two arrays.
I am creating a docker-compose.yml
file and want to do anchors and alias as such
x-template:
base-template: &base-template
environemt:
FOO=BAR
custom-template-1: &custom-template1
<<: *base-template
environment+:
FOO2=BAR2
services:
service-1:
<<: *custom-template1
but I get the error
Unsupported config option for services.service-1: 'environment+'
If I do not use the environment+:
at the custom-tamplate-1:
level, or if I define environment+:
at the service-1:
level it works.
I'd like the result to be
services:
service-1:
environment:
FOO:BAR
FOO2:BAR2
is it possible to achieve what I want?
arrays dictionary docker-compose yaml
add a comment |
This is a bit of a follow up to Ben's post is there YAML syntax for sharing part of a list or map, although I am taking it one step farther and inheriting a third time after merging two arrays.
I am creating a docker-compose.yml
file and want to do anchors and alias as such
x-template:
base-template: &base-template
environemt:
FOO=BAR
custom-template-1: &custom-template1
<<: *base-template
environment+:
FOO2=BAR2
services:
service-1:
<<: *custom-template1
but I get the error
Unsupported config option for services.service-1: 'environment+'
If I do not use the environment+:
at the custom-tamplate-1:
level, or if I define environment+:
at the service-1:
level it works.
I'd like the result to be
services:
service-1:
environment:
FOO:BAR
FOO2:BAR2
is it possible to achieve what I want?
arrays dictionary docker-compose yaml
This is a bit of a follow up to Ben's post is there YAML syntax for sharing part of a list or map, although I am taking it one step farther and inheriting a third time after merging two arrays.
I am creating a docker-compose.yml
file and want to do anchors and alias as such
x-template:
base-template: &base-template
environemt:
FOO=BAR
custom-template-1: &custom-template1
<<: *base-template
environment+:
FOO2=BAR2
services:
service-1:
<<: *custom-template1
but I get the error
Unsupported config option for services.service-1: 'environment+'
If I do not use the environment+:
at the custom-tamplate-1:
level, or if I define environment+:
at the service-1:
level it works.
I'd like the result to be
services:
service-1:
environment:
FOO:BAR
FOO2:BAR2
is it possible to achieve what I want?
arrays dictionary docker-compose yaml
arrays dictionary docker-compose yaml
edited Dec 29 '18 at 20:12
Anthon
29.2k1693145
29.2k1693145
asked Dec 28 '18 at 23:32
scottscott
396
396
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
TL;DR: No, it is not possible
First of all, you have typos in your docker-compose, please copy the whole docker-compose next time. Here is mine corrected (I didn't wanted to edit your question) and extended to be testable:
version: '2.4'
x-base-template: &base-template
image: alpine
command: env
environment:
- FOO=BAR
x-custom-template-1: &custom-template1
<<: *base-template
environment:
- FOO2=BAR2
services:
service-1:
<<: *custom-template1
This setup will completely override the environment setting, so only FOO2
is set, i suppose that's why you asking.
I don't know where you picked up the plus+
syntax, but i can't find anything about it. The only place i did find +
is in https://yaml.org/refcard.html, but there is not mentioned with arrays at all. That's for strings.
You cannot merge arrays at all, but you can use key: value
syntax for environment, and that can be merged this way:
version: '2.4'
x-base-environment: &base-environment
FOO: BAR
x-base-template: &base-template
image: alpine
command: env
environment: *base-environment # This is only necessary if you want variables in base-template
x-custom-template-1: &custom-template1
<<: *base-template
environment:
<<: *base-environment
FOO2: BAR2
services:
service-1:
<<: *custom-template1
The merging we are using, the Merge Key Language-Independent Type, doesn't support nested merging. That means that key is either picked from one object, or the other, no combination. And that's intended desing, it's good behaviour most of the time. Sad thing is, there is no yaml feature (any i know of), that supports nested merging, so simple answer to you questions is "No, it is not possible"
Sidenote: GitLab tried to solve this for their CI config with their proprietary extends
which supports
reverse deep merge based on the keys
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53965417%2fmerging-yaml-arrarys-nested%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
TL;DR: No, it is not possible
First of all, you have typos in your docker-compose, please copy the whole docker-compose next time. Here is mine corrected (I didn't wanted to edit your question) and extended to be testable:
version: '2.4'
x-base-template: &base-template
image: alpine
command: env
environment:
- FOO=BAR
x-custom-template-1: &custom-template1
<<: *base-template
environment:
- FOO2=BAR2
services:
service-1:
<<: *custom-template1
This setup will completely override the environment setting, so only FOO2
is set, i suppose that's why you asking.
I don't know where you picked up the plus+
syntax, but i can't find anything about it. The only place i did find +
is in https://yaml.org/refcard.html, but there is not mentioned with arrays at all. That's for strings.
You cannot merge arrays at all, but you can use key: value
syntax for environment, and that can be merged this way:
version: '2.4'
x-base-environment: &base-environment
FOO: BAR
x-base-template: &base-template
image: alpine
command: env
environment: *base-environment # This is only necessary if you want variables in base-template
x-custom-template-1: &custom-template1
<<: *base-template
environment:
<<: *base-environment
FOO2: BAR2
services:
service-1:
<<: *custom-template1
The merging we are using, the Merge Key Language-Independent Type, doesn't support nested merging. That means that key is either picked from one object, or the other, no combination. And that's intended desing, it's good behaviour most of the time. Sad thing is, there is no yaml feature (any i know of), that supports nested merging, so simple answer to you questions is "No, it is not possible"
Sidenote: GitLab tried to solve this for their CI config with their proprietary extends
which supports
reverse deep merge based on the keys
add a comment |
TL;DR: No, it is not possible
First of all, you have typos in your docker-compose, please copy the whole docker-compose next time. Here is mine corrected (I didn't wanted to edit your question) and extended to be testable:
version: '2.4'
x-base-template: &base-template
image: alpine
command: env
environment:
- FOO=BAR
x-custom-template-1: &custom-template1
<<: *base-template
environment:
- FOO2=BAR2
services:
service-1:
<<: *custom-template1
This setup will completely override the environment setting, so only FOO2
is set, i suppose that's why you asking.
I don't know where you picked up the plus+
syntax, but i can't find anything about it. The only place i did find +
is in https://yaml.org/refcard.html, but there is not mentioned with arrays at all. That's for strings.
You cannot merge arrays at all, but you can use key: value
syntax for environment, and that can be merged this way:
version: '2.4'
x-base-environment: &base-environment
FOO: BAR
x-base-template: &base-template
image: alpine
command: env
environment: *base-environment # This is only necessary if you want variables in base-template
x-custom-template-1: &custom-template1
<<: *base-template
environment:
<<: *base-environment
FOO2: BAR2
services:
service-1:
<<: *custom-template1
The merging we are using, the Merge Key Language-Independent Type, doesn't support nested merging. That means that key is either picked from one object, or the other, no combination. And that's intended desing, it's good behaviour most of the time. Sad thing is, there is no yaml feature (any i know of), that supports nested merging, so simple answer to you questions is "No, it is not possible"
Sidenote: GitLab tried to solve this for their CI config with their proprietary extends
which supports
reverse deep merge based on the keys
add a comment |
TL;DR: No, it is not possible
First of all, you have typos in your docker-compose, please copy the whole docker-compose next time. Here is mine corrected (I didn't wanted to edit your question) and extended to be testable:
version: '2.4'
x-base-template: &base-template
image: alpine
command: env
environment:
- FOO=BAR
x-custom-template-1: &custom-template1
<<: *base-template
environment:
- FOO2=BAR2
services:
service-1:
<<: *custom-template1
This setup will completely override the environment setting, so only FOO2
is set, i suppose that's why you asking.
I don't know where you picked up the plus+
syntax, but i can't find anything about it. The only place i did find +
is in https://yaml.org/refcard.html, but there is not mentioned with arrays at all. That's for strings.
You cannot merge arrays at all, but you can use key: value
syntax for environment, and that can be merged this way:
version: '2.4'
x-base-environment: &base-environment
FOO: BAR
x-base-template: &base-template
image: alpine
command: env
environment: *base-environment # This is only necessary if you want variables in base-template
x-custom-template-1: &custom-template1
<<: *base-template
environment:
<<: *base-environment
FOO2: BAR2
services:
service-1:
<<: *custom-template1
The merging we are using, the Merge Key Language-Independent Type, doesn't support nested merging. That means that key is either picked from one object, or the other, no combination. And that's intended desing, it's good behaviour most of the time. Sad thing is, there is no yaml feature (any i know of), that supports nested merging, so simple answer to you questions is "No, it is not possible"
Sidenote: GitLab tried to solve this for their CI config with their proprietary extends
which supports
reverse deep merge based on the keys
TL;DR: No, it is not possible
First of all, you have typos in your docker-compose, please copy the whole docker-compose next time. Here is mine corrected (I didn't wanted to edit your question) and extended to be testable:
version: '2.4'
x-base-template: &base-template
image: alpine
command: env
environment:
- FOO=BAR
x-custom-template-1: &custom-template1
<<: *base-template
environment:
- FOO2=BAR2
services:
service-1:
<<: *custom-template1
This setup will completely override the environment setting, so only FOO2
is set, i suppose that's why you asking.
I don't know where you picked up the plus+
syntax, but i can't find anything about it. The only place i did find +
is in https://yaml.org/refcard.html, but there is not mentioned with arrays at all. That's for strings.
You cannot merge arrays at all, but you can use key: value
syntax for environment, and that can be merged this way:
version: '2.4'
x-base-environment: &base-environment
FOO: BAR
x-base-template: &base-template
image: alpine
command: env
environment: *base-environment # This is only necessary if you want variables in base-template
x-custom-template-1: &custom-template1
<<: *base-template
environment:
<<: *base-environment
FOO2: BAR2
services:
service-1:
<<: *custom-template1
The merging we are using, the Merge Key Language-Independent Type, doesn't support nested merging. That means that key is either picked from one object, or the other, no combination. And that's intended desing, it's good behaviour most of the time. Sad thing is, there is no yaml feature (any i know of), that supports nested merging, so simple answer to you questions is "No, it is not possible"
Sidenote: GitLab tried to solve this for their CI config with their proprietary extends
which supports
reverse deep merge based on the keys
answered Jan 1 at 22:10
michal.hosnamichal.hosna
41829
41829
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53965417%2fmerging-yaml-arrarys-nested%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown