-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dockerimage.BuildFromContainerfile
- Loading branch information
1 parent
f157c69
commit 52dc295
Showing
3 changed files
with
74 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,16 @@ | ||
# Changelog | ||
|
||
# v0.0.4 | ||
- Add initial `gke` package. | ||
- Add function `AddAuthForCluster` for having local config. | ||
- Add function `StreamContainerLog` for delegating a containers remote log to local files. | ||
- Add new type `PodRun` for executing a Pod for testing. | ||
## v0.0.5 - Migrate `dockerimage` to _sherlock-mavrodi_ | ||
|
||
- Add function `dockerimage.BuildFromContainerfile` for building Container Image. | ||
|
||
**Bugfixes** | ||
- Correct docs of `StreamContainerLog` | ||
|
||
|
||
--- | ||
## v0.0.4 - Migrate `gke` package to _sherlock-mavrodi_ | ||
|
||
- Add function `gke.AddAuthForCluster` for having local config. | ||
- Add function `gke.StreamContainerLog` for delegating a containers remote log to local files. | ||
- Add new type `gke.test.PodRun` for executing a Pod for testing. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package dockerimage | ||
|
||
import "os" | ||
|
||
// BuildFromContainerfile builds a Container image from a Containerfile. | ||
// Invokes docker via CLI since Docker's dependencies and API are beyond brittle. | ||
func BuildFromContainerfile(path string, tag string) error { | ||
|
||
dir, _ := os.Getwd() | ||
os.Chdir(path) | ||
defer os.Chdir(dir) | ||
// Normally you would want to use a Golang API here. | ||
// Since the Docker API is a very thin shim, badly documented | ||
// and talking to Dockerd or Buildkit has a lot of quirks | ||
// just call the binary here and be done with it. | ||
return executeDockerCommand("build", "-f", "Containerfile", ".", "-t", tag) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package dockerimage | ||
|
||
import ( | ||
"io" | ||
"os" | ||
"os/exec" | ||
"sync" | ||
) | ||
|
||
// executeDockerCommandWithStdout calls docker CLI with `arg`. | ||
// Ensures that output is written to provided `io.Writer`. | ||
func executeDockerCommandWithStdout(stdout io.Writer, arg ...string) error { | ||
cmd := exec.Command("docker", arg...) | ||
errReader, err := cmd.StderrPipe() | ||
if err != nil { | ||
return err | ||
} | ||
defer errReader.Close() | ||
outReader, err := cmd.StdoutPipe() | ||
if err != nil { | ||
return err | ||
} | ||
defer outReader.Close() | ||
wg := sync.WaitGroup{} | ||
wg.Add(2) | ||
go func() { | ||
defer wg.Done() | ||
io.Copy(os.Stderr, errReader) | ||
}() | ||
go func() { | ||
defer wg.Done() | ||
io.Copy(stdout, outReader) | ||
}() | ||
err = cmd.Run() | ||
wg.Wait() | ||
return err | ||
} | ||
|
||
// executeDockerCommand call docker CLI with `arg`. | ||
func executeDockerCommand(arg ...string) error { | ||
return executeDockerCommandWithStdout(os.Stdout, arg...) | ||
} |