Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0f98577
Add stack provider for Elastic Cloud
jsoriano Apr 21, 2023
8315709
Fix version
jsoriano Apr 21, 2023
8d7b1d7
Merge remote-tracking branch 'origin/main' into stack-cloud-provider
jsoriano May 22, 2023
ff03886
Upload GeoIP databases
jsoriano May 22, 2023
4cede7e
Replace GeoIP database in cloud deployment
jsoriano May 23, 2023
8298102
Start local agent connected to cloud
jsoriano May 23, 2023
1931b77
Create Agent policy
jsoriano May 24, 2023
0938e7a
Fix path to env file
jsoriano May 24, 2023
3a1643f
Retrieve Fleet Server url from Fleet API
jsoriano May 24, 2023
7f1450a
Merge remote-tracking branch 'origin/main' into stack-cloud-provider
jsoriano May 24, 2023
f71f8cb
Use facts directly in templates where possible
jsoriano May 24, 2023
ee3a31b
Some refactors
jsoriano May 24, 2023
6255827
Reduce size of deployment
jsoriano May 25, 2023
9b22f2c
Parameterize deployment
jsoriano May 25, 2023
4565592
Update deployments on stack up
jsoriano May 25, 2023
4864a3d
Use diferent compose project names per project
jsoriano May 25, 2023
42b95a7
Install zipped package
jsoriano May 25, 2023
a41b053
Merge remote-tracking branch 'origin/main' into stack-cloud-provider
jsoriano May 26, 2023
ed9e89d
Remove TODO
jsoriano May 26, 2023
c61f7db
Merge remote-tracking branch 'origin/main' into stack-cloud-provider
jsoriano Jul 12, 2023
74b5d1e
Merge remote-tracking branch 'origin/main' into stack-cloud-provider
jsoriano Jul 25, 2023
7a3f2f2
Merge remote-tracking branch 'origin/main' into stack-cloud-provider
jsoriano Jul 26, 2023
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
Prev Previous commit
Next Next commit
Use diferent compose project names per project
  • Loading branch information
jsoriano committed May 25, 2023
commit 4864a3d0a7d09836c7410fe294513619beed514e
9 changes: 9 additions & 0 deletions cmd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
package cmd

import (
"fmt"
"path/filepath"

"github.com/pkg/errors"
"github.com/spf13/cobra"

"github.com/elastic/elastic-package/internal/cobraext"
"github.com/elastic/elastic-package/internal/install"
"github.com/elastic/elastic-package/internal/packages"
"github.com/elastic/elastic-package/internal/service"
)
Expand All @@ -34,6 +36,7 @@ func setupServiceCommand() *cobraext.Command {
Long: serviceLongDescription,
}
cmd.AddCommand(upCommand)
cmd.PersistentFlags().StringP(cobraext.ProfileFlagName, "p", "", fmt.Sprintf(cobraext.ProfileFlagDescription, install.ProfileNameEnvVar))

return cobraext.NewCommand(cmd, cobraext.ContextPackage)
}
Expand All @@ -57,8 +60,14 @@ func upCommandAction(cmd *cobra.Command, args []string) error {

variantFlag, _ := cmd.Flags().GetString(cobraext.VariantFlagName)

profile, err := getProfileFlag(cmd)
if err != nil {
return err
}

_, serviceName := filepath.Split(packageRoot)
err = service.BootUp(service.Options{
Profile: profile,
ServiceName: serviceName,
PackageRootPath: packageRoot,
DataStreamRootPath: dataStreamPath,
Expand Down
8 changes: 8 additions & 0 deletions cmd/testrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/elastic/elastic-package/internal/cobraext"
"github.com/elastic/elastic-package/internal/common"
"github.com/elastic/elastic-package/internal/elasticsearch"
"github.com/elastic/elastic-package/internal/install"
"github.com/elastic/elastic-package/internal/packages"
"github.com/elastic/elastic-package/internal/signal"
"github.com/elastic/elastic-package/internal/testrunner"
Expand Down Expand Up @@ -71,6 +72,7 @@ func setupTestCommand() *cobraext.Command {
cmd.PersistentFlags().BoolP(cobraext.TestCoverageFlagName, "", false, cobraext.TestCoverageFlagDescription)
cmd.PersistentFlags().DurationP(cobraext.DeferCleanupFlagName, "", 0, cobraext.DeferCleanupFlagDescription)
cmd.PersistentFlags().String(cobraext.VariantFlagName, "", cobraext.VariantFlagDescription)
cmd.PersistentFlags().StringP(cobraext.ProfileFlagName, "p", "", fmt.Sprintf(cobraext.ProfileFlagDescription, install.ProfileNameEnvVar))

for testType, runner := range testrunner.TestRunners() {
action := testTypeCommandActionFactory(runner)
Expand Down Expand Up @@ -216,9 +218,15 @@ func testTypeCommandActionFactory(runner testrunner.TestRunner) cobraext.Command
return err
}

profile, err := getProfileFlag(cmd)
if err != nil {
return err
}

var results []testrunner.TestResult
for _, folder := range testFolders {
r, err := testrunner.Run(testType, testrunner.TestOptions{
Profile: profile,
TestFolder: folder,
PackageRootPath: packageRootPath,
GenerateTestResult: generateTestResult,
Expand Down
5 changes: 3 additions & 2 deletions internal/kind/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/elastic/elastic-package/internal/docker"
"github.com/elastic/elastic-package/internal/kubectl"
"github.com/elastic/elastic-package/internal/logger"
"github.com/elastic/elastic-package/internal/profile"
"github.com/elastic/elastic-package/internal/stack"
)

Expand All @@ -35,13 +36,13 @@ func VerifyContext() error {
}

// ConnectToElasticStackNetwork function ensures that the control plane node is connected to the Elastic stack network.
func ConnectToElasticStackNetwork() error {
func ConnectToElasticStackNetwork(profile *profile.Profile) error {
containerID, err := controlPlaneContainerID()
if err != nil {
return errors.Wrap(err, "can't find kind-control plane node")
}

stackNetwork := stack.Network()
stackNetwork := stack.Network(profile)
logger.Debugf("check network connectivity between service container %s (ID: %s) and the stack network %s", ControlPlaneContainerName, containerID, stackNetwork)

networkDescriptions, err := docker.InspectNetwork(stackNetwork)
Expand Down
4 changes: 4 additions & 0 deletions internal/service/boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"syscall"

"github.com/elastic/elastic-package/internal/logger"
"github.com/elastic/elastic-package/internal/profile"

"github.com/pkg/errors"

Expand All @@ -21,6 +22,8 @@ import (

// Options define the details of the service which should be booted up.
type Options struct {
Profile *profile.Profile

ServiceName string
PackageRootPath string
DataStreamRootPath string
Expand All @@ -32,6 +35,7 @@ type Options struct {
func BootUp(options Options) error {
logger.Debugf("Create new instance of the service deployer")
serviceDeployer, err := servicedeployer.Factory(servicedeployer.FactoryOptions{
Profile: options.Profile,
PackageRootPath: options.DataStreamRootPath,
DataStreamRootPath: options.DataStreamRootPath,
Variant: options.Variant,
Expand Down
16 changes: 11 additions & 5 deletions internal/stack/boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ import (
"github.com/elastic/elastic-package/internal/builder"
"github.com/elastic/elastic-package/internal/configuration/locations"
"github.com/elastic/elastic-package/internal/files"
"github.com/elastic/elastic-package/internal/profile"
)

// DockerComposeProjectName is the name of the Docker Compose project used to boot up
// baseComposeProjectName is the base name of the Docker Compose project used to boot up
// Elastic Stack containers.
const DockerComposeProjectName = "elastic-package-stack"
const baseComposeProjectName = "elastic-package-stack"

// DockerComposeProjectName returns the docker compose project name for a given profile.
func DockerComposeProjectName(profile *profile.Profile) string {
return baseComposeProjectName + "-" + profile.ProfileName
}

// BootUp function boots up the Elastic stack.
func BootUp(options Options) error {
Expand Down Expand Up @@ -83,7 +89,7 @@ func BootUp(options Options) error {
// to fail too.
// As a workaround, try to give another chance to docker-compose if only
// elastic-agent failed.
if onlyElasticAgentFailed() {
if onlyElasticAgentFailed(options) {
fmt.Println("Elastic Agent failed to start, trying again.")
err = dockerComposeUp(options)
}
Expand All @@ -98,8 +104,8 @@ func BootUp(options Options) error {
return nil
}

func onlyElasticAgentFailed() bool {
status, err := Status()
func onlyElasticAgentFailed(options Options) bool {
status, err := Status(options)
if err != nil {
fmt.Printf("Failed to check status of the stack after failure: %v\n", err)
return false
Expand Down
2 changes: 1 addition & 1 deletion internal/stack/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ func getPackageVersion(registryURL, packageName, stackVersion string) (string, e
}

func (cp *cloudProvider) composeProjectName() string {
return DockerComposeProjectName + "-" + cp.profile.ProfileName
return DockerComposeProjectName(cp.profile)
}

func (cp *cloudProvider) localAgentComposeProject() (*compose.Project, error) {
Expand Down
12 changes: 6 additions & 6 deletions internal/stack/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (eb *envBuilder) build() []string {
}

func dockerComposeBuild(options Options) error {
c, err := compose.NewProject(DockerComposeProjectName, options.Profile.Path(profileStackPath, SnapshotFile))
c, err := compose.NewProject(DockerComposeProjectName(options.Profile), options.Profile.Path(profileStackPath, SnapshotFile))
if err != nil {
return errors.Wrap(err, "could not create docker compose project")
}
Expand All @@ -81,7 +81,7 @@ func dockerComposeBuild(options Options) error {
}

func dockerComposePull(options Options) error {
c, err := compose.NewProject(DockerComposeProjectName, options.Profile.Path(profileStackPath, SnapshotFile))
c, err := compose.NewProject(DockerComposeProjectName(options.Profile), options.Profile.Path(profileStackPath, SnapshotFile))
if err != nil {
return errors.Wrap(err, "could not create docker compose project")
}
Expand All @@ -107,7 +107,7 @@ func dockerComposePull(options Options) error {
}

func dockerComposeUp(options Options) error {
c, err := compose.NewProject(DockerComposeProjectName, options.Profile.Path(profileStackPath, SnapshotFile))
c, err := compose.NewProject(DockerComposeProjectName(options.Profile), options.Profile.Path(profileStackPath, SnapshotFile))
if err != nil {
return errors.Wrap(err, "could not create docker compose project")
}
Expand Down Expand Up @@ -139,7 +139,7 @@ func dockerComposeUp(options Options) error {
}

func dockerComposeDown(options Options) error {
c, err := compose.NewProject(DockerComposeProjectName, options.Profile.Path(profileStackPath, SnapshotFile))
c, err := compose.NewProject(DockerComposeProjectName(options.Profile), options.Profile.Path(profileStackPath, SnapshotFile))
if err != nil {
return errors.Wrap(err, "could not create docker compose project")
}
Expand Down Expand Up @@ -185,10 +185,10 @@ func withIsReadyServices(services []string) []string {
return allServices
}

func dockerComposeStatus() ([]ServiceStatus, error) {
func dockerComposeStatus(options Options) ([]ServiceStatus, error) {
var services []ServiceStatus
// query directly to docker to avoid load environment variables (e.g. STACK_VERSION_VARIANT) and profiles
containerIDs, err := docker.ContainerIDsWithLabel(projectLabelDockerCompose, DockerComposeProjectName)
containerIDs, err := docker.ContainerIDsWithLabel(projectLabelDockerCompose, DockerComposeProjectName(options.Profile))
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/stack/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func dumpStackLogs(options DumpOptions) error {
writeLogFiles(logsPath, serviceName, content)
}

err = copyDockerInternalLogs(serviceName, logsPath)
err = copyDockerInternalLogs(serviceName, logsPath, options.Profile)
if err != nil {
logger.Errorf("can't copy internal logs (service: %s): %v", serviceName, err)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/stack/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func dockerComposeLogs(serviceName string, profile *profile.Profile) ([]byte, er

snapshotFile := profile.Path(profileStackPath, SnapshotFile)

p, err := compose.NewProject(DockerComposeProjectName, snapshotFile)
p, err := compose.NewProject(DockerComposeProjectName(profile), snapshotFile)
if err != nil {
return nil, errors.Wrap(err, "could not create docker compose project")
}
Expand All @@ -44,14 +44,14 @@ func dockerComposeLogs(serviceName string, profile *profile.Profile) ([]byte, er
return out, nil
}

func copyDockerInternalLogs(serviceName, outputPath string) error {
func copyDockerInternalLogs(serviceName, outputPath string, profile *profile.Profile) error {
switch serviceName {
case elasticAgentService, fleetServerService:
default:
return nil // we need to pull internal logs only from Elastic-Agent and Fleets Server container
}

p, err := compose.NewProject(DockerComposeProjectName)
p, err := compose.NewProject(DockerComposeProjectName(profile))
if err != nil {
return errors.Wrap(err, "could not create docker compose project")
}
Expand Down
9 changes: 5 additions & 4 deletions internal/stack/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ import (
"github.com/pkg/errors"

"github.com/elastic/elastic-package/internal/docker"
"github.com/elastic/elastic-package/internal/profile"
)

// EnsureStackNetworkUp function verifies if stack network is up and running.
func EnsureStackNetworkUp() error {
_, err := docker.InspectNetwork(Network())
func EnsureStackNetworkUp(profile *profile.Profile) error {
_, err := docker.InspectNetwork(Network(profile))
return errors.Wrap(err, "network not available")
}

// Network function returns the stack network name.
func Network() string {
return fmt.Sprintf("%s_default", DockerComposeProjectName)
func Network(profile *profile.Profile) string {
return fmt.Sprintf("%s_default", DockerComposeProjectName(profile))
}
2 changes: 1 addition & 1 deletion internal/stack/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,5 @@ func (*composeProvider) Dump(options DumpOptions) (string, error) {
}

func (*composeProvider) Status(options Options) ([]ServiceStatus, error) {
return Status()
return Status(options)
}
4 changes: 2 additions & 2 deletions internal/stack/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
)

// Status shows the status for each service
func Status() ([]ServiceStatus, error) {
servicesStatus, err := dockerComposeStatus()
func Status(options Options) ([]ServiceStatus, error) {
servicesStatus, err := dockerComposeStatus(options)
if err != nil {
return nil, err
}
Expand Down
2 changes: 2 additions & 0 deletions internal/testrunner/runners/system/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func (r *runner) run() (results []testrunner.TestResult, err error) {
}

devDeployPath, err := servicedeployer.FindDevDeployPath(servicedeployer.FactoryOptions{
Profile: r.options.Profile,
PackageRootPath: r.options.PackageRootPath,
DataStreamRootPath: dataStreamPath,
})
Expand Down Expand Up @@ -187,6 +188,7 @@ func (r *runner) run() (results []testrunner.TestResult, err error) {

func (r *runner) runTestPerVariant(result *testrunner.ResultComposer, locationManager *locations.LocationManager, cfgFile, dataStreamPath, variantName string) ([]testrunner.TestResult, error) {
serviceOptions := servicedeployer.FactoryOptions{
Profile: r.options.Profile,
PackageRootPath: r.options.PackageRootPath,
DataStreamRootPath: dataStreamPath,
Variant: variantName,
Expand Down
9 changes: 6 additions & 3 deletions internal/testrunner/runners/system/servicedeployer/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ import (
"github.com/elastic/elastic-package/internal/docker"
"github.com/elastic/elastic-package/internal/files"
"github.com/elastic/elastic-package/internal/logger"
"github.com/elastic/elastic-package/internal/profile"
"github.com/elastic/elastic-package/internal/stack"
)

// DockerComposeServiceDeployer knows how to deploy a service defined via
// a Docker Compose file.
type DockerComposeServiceDeployer struct {
profile *profile.Profile
ymlPaths []string
variant ServiceVariant
}
Expand All @@ -37,8 +39,9 @@ type dockerComposeDeployedService struct {
}

// NewDockerComposeServiceDeployer returns a new instance of a DockerComposeServiceDeployer.
func NewDockerComposeServiceDeployer(ymlPaths []string, sv ServiceVariant) (*DockerComposeServiceDeployer, error) {
func NewDockerComposeServiceDeployer(profile *profile.Profile, ymlPaths []string, sv ServiceVariant) (*DockerComposeServiceDeployer, error) {
return &DockerComposeServiceDeployer{
profile: profile,
ymlPaths: ymlPaths,
variant: sv,
}, nil
Expand All @@ -61,7 +64,7 @@ func (d *DockerComposeServiceDeployer) SetUp(inCtxt ServiceContext) (DeployedSer
}

// Verify the Elastic stack network
err = stack.EnsureStackNetworkUp()
err = stack.EnsureStackNetworkUp(d.profile)
if err != nil {
return nil, errors.Wrap(err, "Elastic stack network is not ready")
}
Expand Down Expand Up @@ -101,7 +104,7 @@ func (d *DockerComposeServiceDeployer) SetUp(inCtxt ServiceContext) (DeployedSer
outCtxt.Hostname = p.ContainerName(serviceName)

// Connect service network with stack network (for the purpose of metrics collection)
err = docker.ConnectToNetwork(p.ContainerName(serviceName), stack.Network())
err = docker.ConnectToNetwork(p.ContainerName(serviceName), stack.Network(d.profile))
if err != nil {
return nil, errors.Wrapf(err, "can't attach service container to the stack network")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/elastic/elastic-package/internal/install"
"github.com/elastic/elastic-package/internal/kibana"
"github.com/elastic/elastic-package/internal/logger"
"github.com/elastic/elastic-package/internal/profile"
"github.com/elastic/elastic-package/internal/stack"
)

Expand All @@ -34,12 +35,14 @@ var dockerCustomAgentDockerfileContent []byte
// CustomAgentDeployer knows how to deploy a custom elastic-agent defined via
// a Docker Compose file.
type CustomAgentDeployer struct {
profile *profile.Profile
dockerComposeFile string
}

// NewCustomAgentDeployer returns a new instance of a deployedCustomAgent.
func NewCustomAgentDeployer(dockerComposeFile string) (*CustomAgentDeployer, error) {
func NewCustomAgentDeployer(profile *profile.Profile, dockerComposeFile string) (*CustomAgentDeployer, error) {
return &CustomAgentDeployer{
profile: profile,
dockerComposeFile: dockerComposeFile,
}, nil
}
Expand Down Expand Up @@ -101,7 +104,7 @@ func (d *CustomAgentDeployer) SetUp(inCtxt ServiceContext) (DeployedService, err
}

// Verify the Elastic stack network
err = stack.EnsureStackNetworkUp()
err = stack.EnsureStackNetworkUp(d.profile)
if err != nil {
return nil, errors.Wrap(err, "Elastic stack network is not ready")
}
Expand All @@ -124,7 +127,7 @@ func (d *CustomAgentDeployer) SetUp(inCtxt ServiceContext) (DeployedService, err
}

// Connect service network with stack network (for the purpose of metrics collection)
err = docker.ConnectToNetwork(p.ContainerName(serviceName), stack.Network())
err = docker.ConnectToNetwork(p.ContainerName(serviceName), stack.Network(d.profile))
if err != nil {
return nil, errors.Wrapf(err, "can't attach service container to the stack network")
}
Expand Down
Loading