Skip to content

Commit e6aa065

Browse files
fix(runtimes/cloudformation): do not assume images are always plain strings
Signed-off-by: francesco-racciatti <[email protected]>
1 parent 2ac245d commit e6aa065

File tree

4 files changed

+121
-2
lines changed

4 files changed

+121
-2
lines changed

runtimes/cloudformation/cfnpatcher/cfn_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var defaultTests = [...]string{
4141
"patching/ref_tags",
4242
"patching/tags",
4343
"patching/volumes_from",
44+
"patching/dynamic_image",
4445
}
4546

4647
var enableHints = [...]string{
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"Resources": {
3+
"taskdef": {
4+
"Type": "AWS::ECS::TaskDefinition",
5+
"Properties": {
6+
"RequiresCompatibilities": [
7+
"FARGATE"
8+
],
9+
"Tags": [
10+
{
11+
"Key": "antani",
12+
"Value": "sbiribuda"
13+
},
14+
{
15+
"Key": "kiltinclude",
16+
"Value": "itisignored"
17+
}
18+
],
19+
"ContainerDefinitions": [
20+
{
21+
"Name": "app",
22+
"Image": {
23+
"Fn::Join": [
24+
"",
25+
[
26+
"quak.io/gimme/",
27+
{
28+
"Fn::GetAtt": [
29+
"fried",
30+
"chicken"
31+
]
32+
}
33+
]
34+
]
35+
},
36+
"Command": ["/bin/sh"]
37+
}
38+
]
39+
}
40+
}
41+
}
42+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"Resources": {
3+
"taskdef": {
4+
"Properties": {
5+
"ContainerDefinitions": [
6+
{
7+
"Command": [
8+
"/bin/sh"
9+
],
10+
"EntryPoint": [
11+
"/kilt/run",
12+
"--"
13+
],
14+
"Image": {
15+
"Fn::Join": [
16+
"",
17+
[
18+
"quak.io/gimme/",
19+
{
20+
"Fn::GetAtt": [
21+
"fried",
22+
"chicken"
23+
]
24+
}
25+
]
26+
]
27+
},
28+
"Name": "app",
29+
"LinuxParameters": {
30+
"Capabilities": {
31+
"Add": ["SYS_PTRACE"]
32+
}
33+
},
34+
"VolumesFrom": [
35+
{
36+
"ReadOnly": true,
37+
"SourceContainer": "KiltImage"
38+
}
39+
]
40+
},
41+
{
42+
"EntryPoint": [
43+
"/kilt/wait"
44+
],
45+
"Image": "KILT:latest",
46+
"Name": "KiltImage"
47+
}
48+
],
49+
"RequiresCompatibilities": [
50+
"FARGATE"
51+
],
52+
"Tags": [
53+
{
54+
"Key": "antani",
55+
"Value": "sbiribuda"
56+
},
57+
{
58+
"Key": "kiltinclude",
59+
"Value": "itisignored"
60+
}
61+
]
62+
},
63+
"Type": "AWS::ECS::TaskDefinition"
64+
}
65+
}
66+
}

runtimes/cloudformation/cfnpatcher/template.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cfnpatcher
22

33
import (
44
"context"
5+
"fmt"
56
"os"
67

78
"github.com/Jeffail/gabs/v2"
@@ -23,6 +24,7 @@ func fillContainerInfo(ctx context.Context, container *gabs.Container, parameter
2324
}
2425

2526
var image string
27+
// If the image is a reference to a parameter, resolve it
2628
if container.Exists("Image", "Ref") {
2729
l.Info().Str("image", container.S("Image").String()).Msg("retrieving image from template parameters")
2830

@@ -38,14 +40,22 @@ func fillContainerInfo(ctx context.Context, container *gabs.Container, parameter
3840
l.Warn().Str("image", container.S("Image").String()).Msg("could not find the name of the image parameter")
3941
}
4042
} else {
41-
image = container.S("Image").Data().(string)
43+
tag := container.S("Image").Data()
44+
switch v := tag.(type) {
45+
case string:
46+
// If the image is a string, use it as is
47+
image = v
48+
default:
49+
// Otherwise, convert it to a raw string
50+
image = fmt.Sprintf("%v", v)
51+
}
4252
}
4353

4454
if configuration.UseRepositoryHints {
4555
os.Setenv("HOME", "/tmp") // crane requires $HOME variable
4656
repoInfo, err := GetConfigFromRepository(image)
4757
if err != nil {
48-
l.Warn().Str("image", image).Err(err).Msg("could not retrieve metadata from repository")
58+
l.Err(err).Msg("The entrypoint and command of the image must be manually set in the original template")
4959
} else {
5060
// Use the image's entrypoint if the task definition does not override it
5161
if repoInfo.Entrypoint != nil && !hasOverriddenEntrypoint {

0 commit comments

Comments
 (0)