forked from elastic/package-spec
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update base docker image for EPR (elastic#125)
* WIP * Use docker command to fetch base image for EPR * Fix: sort fields * Remove TODO file * Fix: comment
- Loading branch information
Showing
8 changed files
with
234 additions
and
155 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
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,31 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package docker | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/elastic/elastic-package/internal/logger" | ||
) | ||
|
||
// Pull downloads the latest available revision of the image. | ||
func Pull(image string) error { | ||
cmd := exec.Command("docker", "pull", image) | ||
|
||
if logger.IsDebugMode() { | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
} | ||
|
||
logger.Debugf("running command: %s", cmd) | ||
err := cmd.Run() | ||
if err != nil { | ||
return errors.Wrap(err, "running docker command failed") | ||
} | ||
return nil | ||
} |
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
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
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,133 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package stack | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/elastic/elastic-package/internal/compose" | ||
"github.com/elastic/elastic-package/internal/install" | ||
) | ||
|
||
const snapshotDefinitionFile = "snapshot.yml" | ||
|
||
func dockerComposeBuild(options Options) error { | ||
stackDir, err := install.StackDir() | ||
if err != nil { | ||
return errors.Wrap(err, "locating stack directory failed") | ||
} | ||
|
||
c, err := compose.NewProject(DockerComposeProjectName, filepath.Join(stackDir, snapshotDefinitionFile)) | ||
if err != nil { | ||
return errors.Wrap(err, "could not create docker compose project") | ||
} | ||
|
||
opts := compose.CommandOptions{ | ||
Env: []string{fmt.Sprintf("STACK_VERSION=%s", options.StackVersion)}, | ||
Services: withIsReadyServices(withDependentServices(options.Services)), | ||
} | ||
|
||
if err := c.Build(opts); err != nil { | ||
return errors.Wrap(err, "running command failed") | ||
} | ||
return nil | ||
} | ||
|
||
func dockerComposePull(options Options) error { | ||
stackDir, err := install.StackDir() | ||
if err != nil { | ||
return errors.Wrap(err, "locating stack directory failed") | ||
} | ||
|
||
c, err := compose.NewProject(DockerComposeProjectName, filepath.Join(stackDir, snapshotDefinitionFile)) | ||
if err != nil { | ||
return errors.Wrap(err, "could not create docker compose project") | ||
} | ||
|
||
opts := compose.CommandOptions{ | ||
Env: []string{fmt.Sprintf("STACK_VERSION=%s", options.StackVersion)}, | ||
Services: withIsReadyServices(withDependentServices(options.Services)), | ||
} | ||
|
||
if err := c.Pull(opts); err != nil { | ||
return errors.Wrap(err, "running command failed") | ||
} | ||
return nil | ||
} | ||
|
||
func dockerComposeUp(options Options) error { | ||
stackDir, err := install.StackDir() | ||
if err != nil { | ||
return errors.Wrap(err, "locating stack directory failed") | ||
} | ||
|
||
c, err := compose.NewProject(DockerComposeProjectName, filepath.Join(stackDir, snapshotDefinitionFile)) | ||
if err != nil { | ||
return errors.Wrap(err, "could not create docker compose project") | ||
} | ||
|
||
var args []string | ||
if options.DaemonMode { | ||
args = append(args, "-d") | ||
} | ||
|
||
opts := compose.CommandOptions{ | ||
Env: []string{fmt.Sprintf("STACK_VERSION=%s", options.StackVersion)}, | ||
ExtraArgs: args, | ||
Services: withIsReadyServices(withDependentServices(options.Services)), | ||
} | ||
|
||
if err := c.Up(opts); err != nil { | ||
return errors.Wrap(err, "running command failed") | ||
} | ||
return nil | ||
} | ||
|
||
func dockerComposeDown() error { | ||
stackDir, err := install.StackDir() | ||
if err != nil { | ||
return errors.Wrap(err, "locating stack directory failed") | ||
} | ||
|
||
c, err := compose.NewProject(DockerComposeProjectName, filepath.Join(stackDir, snapshotDefinitionFile)) | ||
if err != nil { | ||
return errors.Wrap(err, "could not create docker compose project") | ||
} | ||
|
||
opts := compose.CommandOptions{ | ||
// We set the STACK_VERSION env var here to avoid showing a warning to the user about | ||
// it not being set. | ||
Env: []string{fmt.Sprintf("STACK_VERSION=%s", DefaultVersion)}, | ||
} | ||
|
||
if err := c.Down(opts); err != nil { | ||
return errors.Wrap(err, "running command failed") | ||
} | ||
return nil | ||
} | ||
|
||
func withDependentServices(services []string) []string { | ||
for _, aService := range services { | ||
if aService == "elastic-agent" { | ||
return []string{} // elastic-agent service requires to load all other services | ||
} | ||
} | ||
return services | ||
} | ||
|
||
func withIsReadyServices(services []string) []string { | ||
if len(services) == 0 { | ||
return services // load all defined services | ||
} | ||
|
||
var allServices []string | ||
for _, aService := range services { | ||
allServices = append(allServices, aService, fmt.Sprintf("%s_is_ready", aService)) | ||
} | ||
return allServices | ||
} |
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,13 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package stack | ||
|
||
// Options defines available image booting options. | ||
type Options struct { | ||
DaemonMode bool | ||
StackVersion string | ||
|
||
Services []string | ||
} |
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,26 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package stack | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
|
||
"github.com/elastic/elastic-package/internal/docker" | ||
"github.com/elastic/elastic-package/internal/install" | ||
) | ||
|
||
// Update pulls down the most recent versions of the Docker images. | ||
func Update(options Options) error { | ||
err := docker.Pull(install.PackageRegistryBaseImage) | ||
if err != nil { | ||
return errors.Wrap(err, "pulling package-registry docker image failed") | ||
} | ||
|
||
err = dockerComposePull(options) | ||
if err != nil { | ||
return errors.Wrap(err, "updating docker images failed") | ||
} | ||
return nil | ||
} |
Oops, something went wrong.