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

refactor the code to use one set of Docker instructions #545

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
125 changes: 24 additions & 101 deletions pkg/docker/instruction/instruction.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,27 @@
)

// 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 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"`
Expand Down Expand Up @@ -55,91 +56,13 @@
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
_, ok := DOCKER_INSTRUCTION_NAMES[name]
return ok
}

func SupportsJSONForm() []string {
var names []string
for _, spec := range Specs {
names = append(names, spec.Name)
}

return names
return DOCKER_INSTRUCTION_NAMES

Check failure on line 67 in pkg/docker/instruction/instruction.go

View workflow job for this annotation

GitHub Actions / test (1.19)

cannot use DOCKER_INSTRUCTION_NAMES (variable of type map[string]bool) as type []string in return statement
}
Loading