Skip to content

Commit

Permalink
Negotiate docker API on dockerlogbeat packaging (elastic#17066) (elas…
Browse files Browse the repository at this point in the history
…tic#17076)

(cherry picked from commit fc921a3)
  • Loading branch information
jsoriano committed Mar 19, 2020
1 parent aa13b46 commit bacc249
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions x-pack/dockerlogbeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func createContainer(ctx context.Context, cli *client.Client) error {
// start to build the root container that'll be used to build the plugin
tmpDir, err := ioutil.TempDir("", "dockerBuildTar")
if err != nil {
return errors.Wrap(err, "Error locating temp dir")
return errors.Wrap(err, "error locating temp dir")
}
defer sh.Rm(tmpDir)

Expand Down Expand Up @@ -119,16 +119,16 @@ func createContainer(ctx context.Context, cli *client.Client) error {
// * send this to the plugin create API endpoint
func BuildContainer(ctx context.Context) error {
// setup
cli, err := client.NewClientWithOpts(client.FromEnv)
cli, err := newDockerClient(ctx)
if err != nil {
return errors.Wrap(err, "Error creating docker client")
return errors.Wrap(err, "error creating docker client")
}

mage.CreateDir(packageStagingDir)
mage.CreateDir(packageEndDir)
err = os.MkdirAll(filepath.Join(buildDir, "rootfs"), 0755)
if err != nil {
return errors.Wrap(err, "Error creating build dir")
return errors.Wrap(err, "error creating build dir")
}

err = createContainer(ctx, cli)
Expand Down Expand Up @@ -167,7 +167,7 @@ func BuildContainer(ctx context.Context) error {

_, err = io.Copy(file, exportReader)
if err != nil {
return errors.Wrap(err, "Error writing exported container")
return errors.Wrap(err, "error writing exported container")
}

//misc prepare operations
Expand Down Expand Up @@ -203,9 +203,9 @@ func cleanDockerArtifacts(ctx context.Context, containerID string, cli *client.C

// Uninstall removes working objects and containers
func Uninstall(ctx context.Context) error {
cli, err := client.NewClientWithOpts(client.FromEnv)
cli, err := newDockerClient(ctx)
if err != nil {
return errors.Wrap(err, "Error creating docker client")
return errors.Wrap(err, "error creating docker client")
}

//check to see if we have a plugin we need to remove
Expand Down Expand Up @@ -249,9 +249,9 @@ func Install(ctx context.Context) error {
return err
}

cli, err := client.NewClientWithOpts(client.FromEnv)
cli, err := newDockerClient(ctx)
if err != nil {
return errors.Wrap(err, "Error creating docker client")
return errors.Wrap(err, "error creating docker client")
}

archiveOpts := &archive.TarOptions{
Expand Down Expand Up @@ -346,3 +346,12 @@ func IntegTest() {
func Update() {
fmt.Printf("There is no Update for The Elastic Log Plugin\n")
}

func newDockerClient(ctx context.Context) (*client.Client, error) {
cli, err := client.NewClientWithOpts(client.FromEnv)
if err != nil {
return nil, err
}
cli.NegotiateAPIVersion(ctx)
return cli, nil
}

0 comments on commit bacc249

Please sign in to comment.