From b901638cd246a6a6d5e66aeb5398e16589c69ab6 Mon Sep 17 00:00:00 2001 From: Omkar Date: Thu, 6 Jul 2023 15:54:44 +0530 Subject: [PATCH 1/2] refactor the code to use one set of Docker instructions Signed-off-by: Omkar --- pkg/docker/instruction/instruction.go | 128 ++++++-------------------- 1 file changed, 27 insertions(+), 101 deletions(-) diff --git a/pkg/docker/instruction/instruction.go b/pkg/docker/instruction/instruction.go index 0614984a88..763e65459e 100644 --- a/pkg/docker/instruction/instruction.go +++ b/pkg/docker/instruction/instruction.go @@ -6,26 +6,26 @@ import ( ) // All supported instruction names -const ( - Add = "add" - Arg = "arg" - Cmd = "cmd" - Copy = "copy" - Entrypoint = "entrypoint" - Env = "env" - Expose = "expose" - From = "from" - Healthcheck = "healthcheck" - Label = "label" - Maintainer = "maintainer" - Onbuild = "onbuild" - Run = "run" - Shell = "shell" - StopSignal = "stopsignal" - User = "user" - Volume = "volume" - Workdir = "workdir" -) +var DOCKER_INSTRUCTION_NAMES []string = []string{ + "Add", + "Arg", + "Cmd", + "Copy", + "Entrypoint", + "Env", + "Expose", + "From", + "Healthcheck", + "Label", + "Maintainer", + "Onbuild", + "Run", + "Shell", + "StopSignal", + "User", + "Volume", + "Workdir", +} type Field struct { GlobalIndex int `json:"start_index"` @@ -55,91 +55,17 @@ type Format struct { IsDepricated bool } -// Specs is a map of all available instructions and their format info (by name) -var Specs = map[string]Format{ - Add: { - Name: Add, - SupportsFlags: true, - SupportsJSONForm: true, - }, - Arg: { - Name: Arg, - SupportsNameValues: true, - }, - Cmd: { - Name: Cmd, - SupportsJSONForm: true, - }, - Copy: { - Name: Copy, - SupportsFlags: true, - SupportsJSONForm: true, - }, - Entrypoint: { - Name: Entrypoint, - SupportsJSONForm: true, - }, - Env: { - Name: Env, - RequiresNameValues: true, - }, - Expose: { - Name: Expose, - }, - From: { - Name: From, - SupportsFlags: true, - }, - Healthcheck: { - Name: Healthcheck, - SupportsJSONForm: true, - }, - Label: { - Name: Label, - RequiresNameValues: true, - }, - Maintainer: { - Name: Maintainer, - IsDepricated: true, - }, - Onbuild: { - Name: Label, - SupportsSubInst: true, - }, - Run: { - Name: Run, - SupportsJSONForm: true, - }, - Shell: { - Name: Shell, - SupportsJSONForm: true, - }, - StopSignal: { - Name: StopSignal, - }, - User: { - Name: User, - }, - Volume: { - Name: Volume, - SupportsJSONForm: true, - }, - Workdir: { - Name: Workdir, - }, -} func IsKnown(name string) bool { name = strings.ToLower(name) - _, ok := Specs[name] - return ok + for _, instructionName := range DOCKER_INSTRUCTION_NAMES { + if instructionName == name { + return true + } + } + return false } func SupportsJSONForm() []string { - var names []string - for _, spec := range Specs { - names = append(names, spec.Name) - } - - return names + return DOCKER_INSTRUCTION_NAMES } From 7b2bae932cc178307823d21045b1ae64eabcd820 Mon Sep 17 00:00:00 2001 From: Omkar kulkarni <88308267+Omkar0114@users.noreply.github.com> Date: Thu, 10 Aug 2023 17:58:20 +0530 Subject: [PATCH 2/2] Update instruction.go --- pkg/docker/instruction/instruction.go | 47 +++++++++++++-------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/pkg/docker/instruction/instruction.go b/pkg/docker/instruction/instruction.go index 763e65459e..2863d89686 100644 --- a/pkg/docker/instruction/instruction.go +++ b/pkg/docker/instruction/instruction.go @@ -6,26 +6,27 @@ import ( ) // All supported instruction names -var DOCKER_INSTRUCTION_NAMES []string = []string{ - "Add", - "Arg", - "Cmd", - "Copy", - "Entrypoint", - "Env", - "Expose", - "From", - "Healthcheck", - "Label", - "Maintainer", - "Onbuild", - "Run", - "Shell", - "StopSignal", - "User", - "Volume", - "Workdir", +var DOCKER_INSTRUCTION_NAMES map[string]bool = map[string]bool{ + "Add": true, + "Arg": true, + "Cmd": true, + "Copy": true, + "Entrypoint": true, + "Env": true, + "Expose": true, + "From": true, + "Healthcheck": true, + "Label": true, + "Maintainer": true, + "Onbuild": true, + "Run": true, + "Shell": true, + "StopSignal": true, + "User": true, + "Volume": true, + "Workdir": true, } + type Field struct { GlobalIndex int `json:"start_index"` @@ -58,12 +59,8 @@ type Format struct { func IsKnown(name string) bool { name = strings.ToLower(name) - for _, instructionName := range DOCKER_INSTRUCTION_NAMES { - if instructionName == name { - return true - } - } - return false + _, ok := DOCKER_INSTRUCTION_NAMES[name] + return ok } func SupportsJSONForm() []string {