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

Commit

Permalink
Apply template args to step image (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
imjasonh authored and google-prow-robot committed Aug 2, 2018
1 parent 398c888 commit 0fa4a76
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions pkg/builder/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,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

0 comments on commit 0fa4a76

Please sign in to comment.