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 1 commit
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
128 changes: 27 additions & 101 deletions pkg/docker/instruction/instruction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
Omkar0114 marked this conversation as resolved.
Show resolved Hide resolved

type Field struct {
GlobalIndex int `json:"start_index"`
Expand Down Expand Up @@ -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
}