Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use entrypoint/command from template when possibile #29

Merged
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
3 changes: 1 addition & 2 deletions .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ jobs:

- name: Test
run: |
cd runtimes/cloudformation
go test -v ./...
make -C runtimes/cloudformation test

build-cfn-runtime:
name: Build CloudFormation runtime
Expand Down
5 changes: 4 additions & 1 deletion runtimes/cloudformation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ clean:
rm agent-kilt.zip || true
rm cmd/handler/handler || true

.PHONY: clean
test:
go test -v ./...

.PHONY: clean test
23 changes: 23 additions & 0 deletions runtimes/cloudformation/cfnpatcher/cfn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ var defaultTests = [...]string{
"patching/volumes_from",
}

var enableHints = [...]string{
"patching/hints_no_overrides",
"patching/hints_override_command",
"patching/hints_override_entrypoint",
"patching/hints_override_entrypoint_command",
}

var parameterizedEnvarsTests = [...]string{
"patching/parameterize_env_add",
"patching/parameterize_env_merge",
Expand Down Expand Up @@ -205,6 +212,22 @@ func TestPatching(t *testing.T) {
}
}

func TestPatchingWithRepoHints(t *testing.T) {
l := log.Output(zerolog.ConsoleWriter{Out: os.Stderr}).With().Caller().Logger()

for _, testName := range enableHints {
t.Run(testName, func(t *testing.T) {
runTest(t, testName, l.WithContext(context.Background()),
Configuration{
Kilt: defaultConfig,
OptIn: false,
RecipeConfig: "{}",
UseRepositoryHints: true,
})
})
}
}

func TestPatchingSidecarEnv(t *testing.T) {
l := log.Output(zerolog.ConsoleWriter{Out: os.Stderr}).With().Caller().Logger()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"Resources": {
"taskdef": {
"Type": "AWS::ECS::TaskDefinition",
"Properties": {
"RequiresCompatibilities": [
"FARGATE"
],
"ContainerDefinitions": [
{
"Name": "app",
"Image": "nginx"
}
]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"Resources": {
"taskdef": {
"Properties": {
"ContainerDefinitions": [
{
"Command": [
"/docker-entrypoint.sh",
"nginx",
"-g",
"daemon off;"
],
"EntryPoint": [
"/kilt/run",
"--"
],
"Image": "nginx",
"Name": "app",
"LinuxParameters": {
"Capabilities": {
"Add": ["SYS_PTRACE"]
}
},
"VolumesFrom": [
{
"ReadOnly": true,
"SourceContainer": "KiltImage"
}
]
},
{
"EntryPoint": [
"/kilt/wait"
],
"Image": "KILT:latest",
"Name": "KiltImage"
}
],
"RequiresCompatibilities": [
"FARGATE"
]
},
"Type": "AWS::ECS::TaskDefinition"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"Resources": {
"taskdef": {
"Type": "AWS::ECS::TaskDefinition",
"Properties": {
"RequiresCompatibilities": [
"FARGATE"
],
"ContainerDefinitions": [
{
"Name": "app",
"Image": "nginx",
"Command": ["my-command"]
}
]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"Resources": {
"taskdef": {
"Properties": {
"ContainerDefinitions": [
{
"Command": [
"/docker-entrypoint.sh",
"my-command"
],
"EntryPoint": [
"/kilt/run",
"--"
],
"Image": "nginx",
"Name": "app",
"LinuxParameters": {
"Capabilities": {
"Add": ["SYS_PTRACE"]
}
},
"VolumesFrom": [
{
"ReadOnly": true,
"SourceContainer": "KiltImage"
}
]
},
{
"EntryPoint": [
"/kilt/wait"
],
"Image": "KILT:latest",
"Name": "KiltImage"
}
],
"RequiresCompatibilities": [
"FARGATE"
]
},
"Type": "AWS::ECS::TaskDefinition"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"Resources": {
"taskdef": {
"Type": "AWS::ECS::TaskDefinition",
"Properties": {
"RequiresCompatibilities": [
"FARGATE"
],
"ContainerDefinitions": [
{
"Name": "app",
"Image": "nginx",
"EntryPoint": ["my-entrypoint"]
}
]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"Resources": {
"taskdef": {
"Properties": {
"ContainerDefinitions": [
{
"Command": [
"my-entrypoint"
],
"EntryPoint": [
"/kilt/run",
"--"
],
"Image": "nginx",
"Name": "app",
"LinuxParameters": {
"Capabilities": {
"Add": ["SYS_PTRACE"]
}
},
"VolumesFrom": [
{
"ReadOnly": true,
"SourceContainer": "KiltImage"
}
]
},
{
"EntryPoint": [
"/kilt/wait"
],
"Image": "KILT:latest",
"Name": "KiltImage"
}
],
"RequiresCompatibilities": [
"FARGATE"
]
},
"Type": "AWS::ECS::TaskDefinition"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"Resources": {
"taskdef": {
"Type": "AWS::ECS::TaskDefinition",
"Properties": {
"RequiresCompatibilities": [
"FARGATE"
],
"ContainerDefinitions": [
{
"Name": "app",
"Image": "nginx",
"Command": ["my-command"],
"EntryPoint": ["my-entrypoint"]
}
]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"Resources": {
"taskdef": {
"Properties": {
"ContainerDefinitions": [
{
"Command": [
"my-entrypoint",
"my-command"
],
"EntryPoint": [
"/kilt/run",
"--"
],
"Image": "nginx",
"Name": "app",
"LinuxParameters": {
"Capabilities": {
"Add": ["SYS_PTRACE"]
}
},
"VolumesFrom": [
{
"ReadOnly": true,
"SourceContainer": "KiltImage"
}
]
},
{
"EntryPoint": [
"/kilt/wait"
],
"Image": "KILT:latest",
"Name": "KiltImage"
}
],
"RequiresCompatibilities": [
"FARGATE"
]
},
"Type": "AWS::ECS::TaskDefinition"
}
}
}
13 changes: 10 additions & 3 deletions runtimes/cloudformation/cfnpatcher/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import (
func fillContainerInfo(ctx context.Context, container *gabs.Container, parameters *gabs.Container, configuration *Configuration) {
l := log.Ctx(ctx)

if container.Exists("Command") && container.Exists("EntryPoint") {
hasOverriddenEntrypoint := container.Exists("EntryPoint")
hasOverriddenCommand := container.Exists("Command")

if hasOverriddenEntrypoint && hasOverriddenCommand {
return
}

Expand Down Expand Up @@ -44,10 +47,14 @@ func fillContainerInfo(ctx context.Context, container *gabs.Container, parameter
if err != nil {
l.Warn().Str("image", image).Err(err).Msg("could not retrieve metadata from repository")
} else {
if repoInfo.Entrypoint != nil {
// Use the image's entrypoint if the task definition does not override it
if repoInfo.Entrypoint != nil && !hasOverriddenEntrypoint {
l.Info().Str("image", container.S("Image").String()).Msgf("using default entrypoint %s", repoInfo.Entrypoint)
container.Set(repoInfo.Entrypoint, "EntryPoint")
}
if repoInfo.Command != nil {
// Use the image's command if the task definition overrides neither the entrypoint nor the command
if repoInfo.Command != nil && !hasOverriddenCommand && !hasOverriddenEntrypoint {
l.Info().Str("image", container.S("Image").String()).Msgf("using default command %s", repoInfo.Command)
container.Set(repoInfo.Command, "Command")
}
}
Expand Down
Loading