This repository has been archived by the owner on Sep 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
feat: sync Docker Compose files with Beats Integrations #84
Merged
Merged
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
10388e0
feat: support cloning git repositories
mdelapenya 71dac4d
feat: add a subcommand to download elastic/beats using its master branch
mdelapenya 0e720cb
chore: add a VSCode configuration for debugging new command
mdelapenya a840bbd
feat: support using another remote different than upstream
mdelapenya 0792353
feat: support removing the existing repository before cloning
mdelapenya eed2d4b
feat: copy integrations compose file into the workspace
mdelapenya 0c40b76
chore: migrate existing services and stacks to the new format
mdelapenya b00d92c
chore: add compose files for all integrations from Beats
mdelapenya 7cd468f
feat: store new compose and related files into the packr box
mdelapenya dfdb525
chore: sync docker-compose version with Beats
mdelapenya 9429684
fix: add services and stacks that are present at tool's workspace
mdelapenya d4c7b69
chore: do not bundle the tool with any service
mdelapenya 30370f8
docs: update CLI docs
mdelapenya 1782e10
chore: sync integration services using the build
mdelapenya 9176313
chore: run go mod tidy
mdelapenya 8ee8a1d
feat: support calculating a service's environment variables from CLI …
mdelapenya 68c57e1
chore: do not pollute io file with compose business logic
mdelapenya a2d490c
fix: only copy services including a supported-versions.yml file
mdelapenya 7920118
fix: simplify calculating service environment variables
mdelapenya f44ec0b
chore: move exists method to io file
mdelapenya d70a5c4
chore: rename method to be more descriptive
mdelapenya 57a9dd4
chore: use io's mkdirall everywhere
mdelapenya 3e2bc59
chore: move writeFile to io
mdelapenya b06ce15
chore: move readDir to io
mdelapenya 55d042c
chore: move func close to its struct
mdelapenya b740aa2
chore: update vscode debug configurations
mdelapenya c2f4d1a
feat: support persisting the state of each run in a file
mdelapenya 715174a
fix: retrieve service environment when running or deploying a service
mdelapenya 464a947
feat: support updating state after docker-compose execution
mdelapenya e67d92a
chore: use same compose version in existing services
mdelapenya d37757d
chore: bump stack version to 7.6.0
mdelapenya 754cb68
fix: use same credentials for MySQL than in the Beats image
mdelapenya 7bcfe7a
feat: support adding the environment variables coming from the suppor…
mdelapenya eae1881
feat: create specific steps for service variants
mdelapenya a181898
fix: remove duplicated test
mdelapenya 244540e
fix: mkdirall must create the dirs for a path, not its parent
mdelapenya 5dc4cb0
fix: handle errors for mkdirall when needed
mdelapenya 96f571c
fix: do not capitalise variable (gocritic)
mdelapenya 9121592
chore: excludes from golint
mdelapenya 330d262
fix: rename flag to a more descriptive name
mdelapenya fc79996
fix: typos in docs
mdelapenya 83d192b
docs: document execute method
mdelapenya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,117 @@ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
"path" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/elastic/metricbeat-tests-poc/cli/config" | ||
git "github.com/elastic/metricbeat-tests-poc/cli/internal" | ||
io "github.com/elastic/metricbeat-tests-poc/cli/internal" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var deleteRepository = false | ||
var remote = "elastic:master" | ||
|
||
func init() { | ||
config.InitConfig() | ||
|
||
syncIntegrationsCmd.Flags().BoolVarP(&deleteRepository, "delete", "d", false, "Will delete the existing Beats repository before cloning it again (default false)") | ||
syncIntegrationsCmd.Flags().StringVarP(&remote, "remote", "r", "elastic:master", "Sets the remote for Beats, using 'user:branch' as format (i.e. elastic:master)") | ||
|
||
syncCmd.AddCommand(syncIntegrationsCmd) | ||
rootCmd.AddCommand(syncCmd) | ||
} | ||
|
||
var syncCmd = &cobra.Command{ | ||
Use: "sync", | ||
Short: "Sync services from Beats", | ||
Long: "Subcommands will allow synchronising services", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// NOOP | ||
}, | ||
} | ||
|
||
var syncIntegrationsCmd = &cobra.Command{ | ||
Use: "integrations", | ||
Short: "Sync services from Beats", | ||
Long: "Sync services from Beats, checking out current version of the services from GitHub", | ||
Args: func(cmd *cobra.Command, args []string) error { | ||
arr := strings.Split(remote, ":") | ||
if len(arr) == 2 { | ||
return nil | ||
} | ||
return errors.New("invalid 'user:branch' format: " + remote + ". Example: 'elastic:master'") | ||
}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
workspace := config.Op.Workspace | ||
|
||
// BeatsRepo default object representing Beats project | ||
var BeatsRepo = git.ProjectBuilder. | ||
WithBaseWorkspace(path.Join(workspace, "git")). | ||
WithGitProtocol(). | ||
WithDomain("github.com"). | ||
WithName("beats"). | ||
WithRemote(remote). | ||
Build() | ||
|
||
if deleteRepository { | ||
repoDir := path.Join(workspace, "git", BeatsRepo.Name) | ||
|
||
log.WithFields(log.Fields{ | ||
"path": repoDir, | ||
}).Debug("Removing repository") | ||
os.RemoveAll(repoDir) | ||
log.WithFields(log.Fields{ | ||
"path": repoDir, | ||
}).Debug("Repository removed") | ||
} | ||
|
||
git.Clone(BeatsRepo) | ||
mdelapenya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
copyIntegrationsComposeFiles(BeatsRepo, workspace) | ||
mdelapenya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
} | ||
|
||
// CopyComposeFiles copies only those services that has a supported-versions.yml | ||
// file from Beats integrations, and we will need to copy them into a directory | ||
// named as the original service (i.e. aerospike) under this tool's workspace, | ||
// alongside the services. Besides that, the method will copy the _meta directory | ||
// for each service | ||
func copyIntegrationsComposeFiles(beats git.Project, target string) { | ||
pattern := path.Join( | ||
beats.GetWorkspace(), "metricbeat", "module", "*", "_meta", "supported-versions.yml") | ||
|
||
files := io.FindFiles(pattern) | ||
|
||
for _, file := range files { | ||
metaDir := filepath.Dir(file) | ||
serviceDir := filepath.Dir(metaDir) | ||
service := filepath.Base(serviceDir) | ||
|
||
composeFile := filepath.Join(serviceDir, "docker-compose.yml") | ||
targetFile := filepath.Join( | ||
target, "compose", "services", service, "docker-compose.yml") | ||
|
||
err := io.CopyFile(composeFile, targetFile, 10000) | ||
if err != nil { | ||
log.WithFields(log.Fields{ | ||
"error": err, | ||
"file": file, | ||
}).Warn("File was not copied") | ||
} | ||
|
||
targetMetaDir := filepath.Join(target, "compose", "services", service, "_meta") | ||
err = io.CopyDir(metaDir, targetMetaDir) | ||
if err != nil { | ||
log.WithFields(log.Fields{ | ||
"error": err, | ||
"_meta": metaDir, | ||
}).Warn("Meta dir was not copied") | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
cli/config/compose/services/apm-server.yml → ...se/services/apm-server/docker-compose.yml
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,4 +1,4 @@ | ||
version: '3' | ||
version: '2.3' | ||
services: | ||
apm-server: | ||
environment: | ||
|
2 changes: 1 addition & 1 deletion
2
...config/compose/services/elasticsearch.yml → ...services/elasticsearch/docker-compose.yml
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,4 +1,4 @@ | ||
version: '3' | ||
version: '2.3' | ||
services: | ||
elasticsearch: | ||
environment: | ||
|
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
cli/config/compose/services/kibana.yml → ...ompose/services/kibana/docker-compose.yml
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,4 +1,4 @@ | ||
version: '3' | ||
version: '2.3' | ||
services: | ||
kibana: | ||
environment: | ||
|
2 changes: 1 addition & 1 deletion
2
cli/config/compose/services/metricbeat.yml → ...se/services/metricbeat/docker-compose.yml
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,4 +1,4 @@ | ||
version: '3' | ||
version: '2.3' | ||
services: | ||
metricbeat: | ||
command: [ | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
cli/config/compose/services/opbeans-go.yml → ...se/services/opbeans-go/docker-compose.yml
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,4 +1,4 @@ | ||
version: '3' | ||
version: '2.3' | ||
services: | ||
opbeans-go: | ||
environment: | ||
|
2 changes: 1 addition & 1 deletion
2
cli/config/compose/services/opbeans-java.yml → .../services/opbeans-java/docker-compose.yml
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,4 +1,4 @@ | ||
version: '3' | ||
version: '2.3' | ||
services: | ||
opbeans-java: | ||
environment: | ||
|
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
cli/config/compose/services/vsphere.yml → ...mpose/services/vsphere/docker-compose.yml
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,4 +1,4 @@ | ||
version: '3' | ||
version: '2.3' | ||
services: | ||
vsphere: | ||
image: "nimmis/vcsim:${vsphereTag}" | ||
|
2 changes: 1 addition & 1 deletion
2
cli/config/compose/stacks/metricbeat.yml → ...pose/stacks/metricbeat/docker-compose.yml
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,4 +1,4 @@ | ||
version: '3' | ||
version: '2.3' | ||
services: | ||
elasticsearch: | ||
environment: | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is forcing the CI to get the compose files from Beats