Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Apply template args to step image #293

Merged
merged 1 commit into from
Aug 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/builder/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func ApplyTemplate(u *v1alpha1.Build, tmpl *v1alpha1.BuildTemplate) (*v1alpha1.B
steps := build.Spec.Steps
for i := range steps {
steps[i].Name = applyReplacements(steps[i].Name)
steps[i].Image = applyReplacements(steps[i].Image)
for ia, a := range steps[i].Args {
steps[i].Args[ia] = applyReplacements(a)
}
Expand Down
20 changes: 12 additions & 8 deletions pkg/builder/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ func TestApplyTemplate(t *testing.T) {
tmpl: &v1alpha1.BuildTemplate{
Spec: v1alpha1.BuildTemplateSpec{
Steps: []corev1.Container{{
Name: "hello ${FOO}",
Args: []string{"hello", "to the ${FOO}"},
Name: "hello ${FOO}",
Image: "busybox:${FOO}",
Args: []string{"hello", "to the ${FOO}"},
Env: []corev1.EnvVar{{
Name: "FOO",
Value: "is ${FOO}",
Expand All @@ -120,8 +121,9 @@ func TestApplyTemplate(t *testing.T) {
want: &v1alpha1.Build{
Spec: v1alpha1.BuildSpec{
Steps: []corev1.Container{{
Name: "hello world",
Args: []string{"hello", "to the world"},
Name: "hello world",
Image: "busybox:world",
Args: []string{"hello", "to the world"},
Env: []corev1.EnvVar{{
Name: "FOO",
Value: "is world",
Expand Down Expand Up @@ -245,8 +247,9 @@ func TestApplyTemplate(t *testing.T) {
tmpl: &v1alpha1.BuildTemplate{
Spec: v1alpha1.BuildTemplateSpec{
Steps: []corev1.Container{{
Name: "hello ${FOO}",
Args: []string{"hello", "to the ${FOO}"},
Name: "hello ${FOO}",
Image: "busybox:${FOO}",
Args: []string{"hello", "to the ${FOO}"},
Env: []corev1.EnvVar{{
Name: "FOO",
Value: "is ${FOO}",
Expand All @@ -263,8 +266,9 @@ func TestApplyTemplate(t *testing.T) {
want: &v1alpha1.Build{
Spec: v1alpha1.BuildSpec{
Steps: []corev1.Container{{
Name: "hello world",
Args: []string{"hello", "to the world"},
Name: "hello world",
Image: "busybox:world",
Args: []string{"hello", "to the world"},
Env: []corev1.EnvVar{{
Name: "FOO",
Value: "is world",
Expand Down
10 changes: 6 additions & 4 deletions test/template-args/0-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,29 @@ metadata:
spec:
steps:
# Use the build's declared argument value.
- image: ubuntu
- image: ${IMAGE}
command: ['bash']
args: ['-c', '[[ ${FOO} == "foo" ]]']
# Use the template parameter's default value.
- image: ubuntu
- image: ${IMAGE}
command: ['bash']
args: ['-c', '[[ ${BAR} == "bar" ]]']
# Use the build's declared argument value, overriding the parameter's default
# value.
- image: ubuntu
- image: ${IMAGE}
command: ['bash']
args: ['-c', '[[ ${BAZ} == "bazzzzz" ]]']
# This is just an environment variable, not a template parameter.
- image: ubuntu
- image: ${IMAGE}
command: ['bash']
args: ['-c', '[[ $FOO == "foo" ]]']
env:
- name: FOO
value: foo

parameters:
- name: IMAGE
default: ubuntu
- name: FOO
- name: BAR
default: bar
Expand Down