summaryrefslogtreecommitdiff
path: root/docker
diff options
context:
space:
mode:
authorDan Duvall <dduvall@wikimedia.org>2017-10-25 10:24:11 -0700
committerDan Duvall <dduvall@wikimedia.org>2017-11-06 13:28:38 -0800
commit5b5ad0496ff75e787405ab9eec17f13214d0b834 (patch)
tree5d01e88b807514999e2bd2b4eb2cf8934bcc8885 /docker
parent515d9f26eb616a9c3a0b70ba6eca88570a15b0ef (diff)
downloadblubber-5b5ad0496ff75e787405ab9eec17f13214d0b834.tar.gz
Conform to all linter warnings/advice
Summary: Fixed all linter warnings and advice except for vet's rule about unkeyed composite literals which was disabled via a `-composites=false` flag in `.arclint`. Most unkeyed literals (e.g. `build.Run{"command"}`) in this project just seem too usefully succinct compared to their more verbose keyed counterparts. Depends on D841 Test Plan: Run `arc lint --everything` and verify there are no warnings or advice. Reviewers: thcipriani, hashar, #release-engineering-team Reviewed By: thcipriani, hashar, #release-engineering-team Tags: #release-engineering-team Differential Revision: https://phabricator.wikimedia.org/D845
Diffstat (limited to 'docker')
-rw-r--r--docker/compiler.go2
-rw-r--r--docker/instructions.go62
-rw-r--r--docker/instructions_test.go34
3 files changed, 49 insertions, 49 deletions
diff --git a/docker/compiler.go b/docker/compiler.go
index 2823777..68f9384 100644
--- a/docker/compiler.go
+++ b/docker/compiler.go
@@ -87,7 +87,7 @@ func compileStage(buffer *bytes.Buffer, stage string, vcfg *config.VariantConfig
func compileInstructions(buffer *bytes.Buffer, instructions ...build.Instruction) {
for _, instruction := range instructions {
- dockerInstruction, _ := NewDockerInstruction(instruction)
+ dockerInstruction, _ := NewInstruction(instruction)
write(buffer, dockerInstruction.Compile())
}
}
diff --git a/docker/instructions.go b/docker/instructions.go
index f362814..52c281a 100644
--- a/docker/instructions.go
+++ b/docker/instructions.go
@@ -8,126 +8,126 @@ import (
"phabricator.wikimedia.org/source/blubber/build"
)
-// NewDockerInstruction takes a general internal build.Instruction and returns
+// NewInstruction takes a general internal build.Instruction and returns
// a corresponding compilable Docker specific instruction. The given internal
// instruction is partially compiled at this point by calling Compile() which
// applies its own logic for escaping arguments, etc.
//
-func NewDockerInstruction(instruction build.Instruction) (DockerInstruction, error) {
+func NewInstruction(instruction build.Instruction) (Instruction, error) {
switch instruction.(type) {
case build.Run, build.RunAll:
- var dockerInstruction DockerRun
+ var dockerInstruction Run
dockerInstruction.arguments = instruction.Compile()
return dockerInstruction, nil
case build.Copy:
- var dockerInstruction DockerCopy
+ var dockerInstruction Copy
dockerInstruction.arguments = instruction.Compile()
return dockerInstruction, nil
case build.CopyFrom:
- var dockerInstruction DockerCopyFrom
+ var dockerInstruction CopyFrom
dockerInstruction.arguments = instruction.Compile()
return dockerInstruction, nil
case build.Env:
- var dockerInstruction DockerEnv
+ var dockerInstruction Env
dockerInstruction.arguments = instruction.Compile()
return dockerInstruction, nil
case build.Label:
- var dockerInstruction DockerLabel
+ var dockerInstruction Label
dockerInstruction.arguments = instruction.Compile()
return dockerInstruction, nil
case build.Volume:
- var dockerInstruction DockerVolume
+ var dockerInstruction Volume
dockerInstruction.arguments = instruction.Compile()
return dockerInstruction, nil
}
- return nil, errors.New("Unable to create DockerInstruction")
+ return nil, errors.New("Unable to create Instruction")
}
-// DockerInstruction defines an interface for instruction compilation.
+// Instruction defines an interface for instruction compilation.
//
-type DockerInstruction interface {
+type Instruction interface {
Compile() string
Arguments() []string
}
-type abstractDockerInstruction struct {
+type abstractInstruction struct {
arguments []string
}
-func (di abstractDockerInstruction) Arguments() []string {
+func (di abstractInstruction) Arguments() []string {
return di.arguments
}
-// DockerRun compiles into a RUN instruction.
+// Run compiles into a RUN instruction.
//
-type DockerRun struct{ abstractDockerInstruction }
+type Run struct{ abstractInstruction }
// Compile compiles RUN instructions.
//
-func (dr DockerRun) Compile() string {
+func (dr Run) Compile() string {
return fmt.Sprintf(
"RUN %s\n",
join(dr.arguments, ""))
}
-// DockerCopy compiles into a COPY instruction.
+// Copy compiles into a COPY instruction.
//
-type DockerCopy struct{ abstractDockerInstruction }
+type Copy struct{ abstractInstruction }
// Compile compiles COPY instructions.
//
-func (dc DockerCopy) Compile() string {
+func (dc Copy) Compile() string {
return fmt.Sprintf(
"COPY [%s]\n",
join(dc.arguments, ", "))
}
-// DockerCopyFrom compiles into a COPY --from instruction.
+// CopyFrom compiles into a COPY --from instruction.
//
-type DockerCopyFrom struct{ abstractDockerInstruction }
+type CopyFrom struct{ abstractInstruction }
// Compile compiles COPY --from instructions.
//
-func (dcf DockerCopyFrom) Compile() string {
+func (dcf CopyFrom) Compile() string {
return fmt.Sprintf(
"COPY --from=%s [%s]\n",
dcf.arguments[0],
join(dcf.arguments[1:], ", "))
}
-// DockerEnv compiles into a ENV instruction.
+// Env compiles into a ENV instruction.
//
-type DockerEnv struct{ abstractDockerInstruction }
+type Env struct{ abstractInstruction }
// Compile compiles ENV instructions.
//
-func (de DockerEnv) Compile() string {
+func (de Env) Compile() string {
return fmt.Sprintf(
"ENV %s\n",
join(de.arguments, " "))
}
-// DockerLabel compiles into a LABEL instruction.
+// Label compiles into a LABEL instruction.
//
-type DockerLabel struct{ abstractDockerInstruction }
+type Label struct{ abstractInstruction }
// Compile returns multiple key="value" arguments as a single LABEL
// instruction.
//
-func (dl DockerLabel) Compile() string {
+func (dl Label) Compile() string {
return fmt.Sprintf(
"LABEL %s\n",
join(dl.arguments, " "))
}
-// DockerVolume compiles into a VOLUME instruction.
+// Volume compiles into a VOLUME instruction.
//
-type DockerVolume struct{ abstractDockerInstruction }
+type Volume struct{ abstractInstruction }
// Compile compiles VOLUME instructions.
//
-func (dv DockerVolume) Compile() string {
+func (dv Volume) Compile() string {
return fmt.Sprintf(
"VOLUME [%s]\n",
join(dv.arguments, ", "))
diff --git a/docker/instructions_test.go b/docker/instructions_test.go
index a4f648b..181ab71 100644
--- a/docker/instructions_test.go
+++ b/docker/instructions_test.go
@@ -11,9 +11,9 @@ import (
func TestRun(t *testing.T) {
i := build.Run{"echo", []string{"hello"}}
- di, err := docker.NewDockerInstruction(i)
+ di, err := docker.NewInstruction(i)
- var dockerRun docker.DockerRun
+ var dockerRun docker.Run
assert.Nil(t, err)
assert.IsType(t, dockerRun, di)
@@ -26,9 +26,9 @@ func TestRunAll(t *testing.T) {
{"echo", []string{"yo"}},
}}
- di, err := docker.NewDockerInstruction(i)
+ di, err := docker.NewInstruction(i)
- var dockerRun docker.DockerRun
+ var dockerRun docker.Run
assert.Nil(t, err)
assert.IsType(t, dockerRun, di)
@@ -38,9 +38,9 @@ func TestRunAll(t *testing.T) {
func TestCopy(t *testing.T) {
i := build.Copy{[]string{"foo1", "foo2"}, "bar"}
- di, err := docker.NewDockerInstruction(i)
+ di, err := docker.NewInstruction(i)
- var dockerCopy docker.DockerCopy
+ var dockerCopy docker.Copy
assert.Nil(t, err)
assert.IsType(t, dockerCopy, di)
@@ -50,9 +50,9 @@ func TestCopy(t *testing.T) {
func TestCopyFrom(t *testing.T) {
i := build.CopyFrom{"foo", build.Copy{[]string{"foo1", "foo2"}, "bar"}}
- di, err := docker.NewDockerInstruction(i)
+ di, err := docker.NewInstruction(i)
- var dockerCopyFrom docker.DockerCopyFrom
+ var dockerCopyFrom docker.CopyFrom
assert.Nil(t, err)
assert.IsType(t, dockerCopyFrom, di)
@@ -62,9 +62,9 @@ func TestCopyFrom(t *testing.T) {
func TestEnv(t *testing.T) {
i := build.Env{map[string]string{"foo": "bar", "bar": "foo"}}
- di, err := docker.NewDockerInstruction(i)
+ di, err := docker.NewInstruction(i)
- var dockerEnv docker.DockerEnv
+ var dockerEnv docker.Env
assert.Nil(t, err)
assert.IsType(t, dockerEnv, di)
@@ -74,9 +74,9 @@ func TestEnv(t *testing.T) {
func TestLabel(t *testing.T) {
i := build.Label{map[string]string{"foo": "bar", "bar": "foo"}}
- di, err := docker.NewDockerInstruction(i)
+ di, err := docker.NewInstruction(i)
- var dockerLabel docker.DockerLabel
+ var dockerLabel docker.Label
assert.Nil(t, err)
assert.IsType(t, dockerLabel, di)
@@ -86,9 +86,9 @@ func TestLabel(t *testing.T) {
func TestVolume(t *testing.T) {
i := build.Volume{"/foo/dir"}
- di, err := docker.NewDockerInstruction(i)
+ di, err := docker.NewInstruction(i)
- var dockerVolume docker.DockerVolume
+ var dockerVolume docker.Volume
assert.Nil(t, err)
assert.IsType(t, dockerVolume, di)
@@ -97,21 +97,21 @@ func TestVolume(t *testing.T) {
func TestEscapeRun(t *testing.T) {
i := build.Run{"/bin/true\nRUN echo HACKED!", []string{}}
- dr, _ := docker.NewDockerInstruction(i)
+ dr, _ := docker.NewInstruction(i)
assert.Equal(t, "RUN /bin/true\\nRUN echo HACKED!\n", dr.Compile())
}
func TestEscapeCopy(t *testing.T) {
i := build.Copy{[]string{"file.a", "file.b"}, "dest"}
- dr, _ := docker.NewDockerInstruction(i)
+ dr, _ := docker.NewInstruction(i)
assert.Equal(t, "COPY [\"file.a\", \"file.b\", \"dest\"]\n", dr.Compile())
}
func TestEscapeEnv(t *testing.T) {
i := build.Env{map[string]string{"a": "b\nRUN echo HACKED!"}}
- dr, _ := docker.NewDockerInstruction(i)
+ dr, _ := docker.NewInstruction(i)
assert.Equal(t, "ENV a=\"b\\nRUN echo HACKED!\"\n", dr.Compile())
}