Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

package docker container images with mage #1543

Merged
merged 3 commits into from
Nov 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------
Dependency: github.com/elastic/beats
Version: master
Revision: 7fee516ea7a79f8ab5865186a763e36056dbd658
Revision: 1dd4fbf559e515c9141c1cb0308742a9efb10cf3
License type (autodetected): Apache-2.0
./vendor/github.com/elastic/beats/LICENSE.txt:
--------------------------------------------------------------------
Expand Down
157 changes: 157 additions & 0 deletions _beats/dev-tools/cmd/module_include_list/module_include_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package main

import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
"text/template"

"github.com/elastic/beats/dev-tools/mage"
"github.com/elastic/beats/licenses"
)

var usageText = `
Usage: module_include_list [flags] [module-dir]
module_include_list generates a list.go file containing import statements for
the module and its dataset packages. The file is usually written to the
include/list.go in the Beat's root directory.
Options:
`[1:]

var (
license string
pkg string
outFile string
)

func init() {
flag.StringVar(&license, "license", "ASL2", "License header for generated file (ASL2 or Elastic).")
flag.StringVar(&pkg, "pkg", "include", "Package name.")
flag.StringVar(&outFile, "out", "include/list.go", "Output file.")
flag.Usage = usageFlag
}

func main() {
log.SetFlags(0)
flag.Parse()

license, err := licenses.Find(license)
if err != nil {
log.Fatalf("Invalid license specifier: %v", err)
}

args := flag.Args()
if len(args) != 1 {
log.Fatal("module-dir must be passed as an argument.")
}
dir := args[0]

// Find modules and datasets.
metaDirs, err := mage.FindFiles(
filepath.Join(dir, "*/_meta"),
filepath.Join(dir, "*/*/_meta"),
)
if err != nil {
log.Fatalf("Failed finding modules and datasets: %v", err)
}

// Get the current directories Go import path.
repo, err := mage.GetProjectRepoInfo()
if err != nil {
log.Fatalf("Failed to determine import path: %v", err)
}

// Build import paths.
var imports []string
for _, metaDir := range metaDirs {
importDir := filepath.Dir(metaDir)

// Skip dirs that have no .go files.
goFiles, err := filepath.Glob(filepath.Join(importDir, "*.go"))
if err != nil {
log.Fatal("Failed checking for .go files in package dir: %v", err)
}
if len(goFiles) == 0 {
continue
}

importDir, err = filepath.Rel(mage.CWD(), filepath.Dir(metaDir))
if err != nil {
log.Fatal(err)
}

imports = append(imports, filepath.ToSlash(
filepath.Join(repo.ImportPath, importDir)))
}

// Populate the template.
var buf bytes.Buffer
err = Template.Execute(&buf, Data{
License: license,
Package: pkg,
Imports: imports,
})
if err != nil {
log.Fatal("Failed executing template: %v", err)
}

// Create the output directory.
if err = os.MkdirAll(filepath.Dir(outFile), 0755); err != nil {
log.Fatal("Failed to create output directory: %v", err)
}

// Write the output file.
if err = ioutil.WriteFile(outFile, buf.Bytes(), 0644); err != nil {
log.Fatal("Failed writing output file: %v", err)
}
}

func usageFlag() {
fmt.Fprintf(os.Stderr, usageText)
flag.PrintDefaults()
}

var Template = template.Must(template.New("normalizations").Funcs(map[string]interface{}{
"trim": strings.TrimSpace,
}).Parse(`
{{ .License | trim }}

// Code generated by beats/dev-tools/module_include_list/module_include_list.go - DO NOT EDIT.

package {{ .Package }}

import (
// Import modules.
{{- range $import := .Imports }}
_ "{{ $import }}"
{{- end }}
)
`[1:]))

type Data struct {
License string
Package string
Imports []string
}
46 changes: 46 additions & 0 deletions _beats/dev-tools/ecs-migration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,49 @@
to: agent.version
alias: true
copy_to: false

- from: source_ecs.ip
to: source.ip
alias: true
copy_to: false

- from: source_ecs.port
to: source.port
alias: true
copy_to: false

- from: source_ecs.geo.continent_name
to: source.geo.continent_name
alias: true
copy_to: false

- from: source_ecs.geo.country_iso_code
to: source.geo.country_iso_code
alias: true
copy_to: false

- from: source_ecs.geo.location
to: source.geo.location
alias: true
copy_to: false

- from: source_ecs.geo.region_name
to: source.geo.region_name
alias: true
copy_to: false

- from: source_ecs.geo.city_name
to: source.geo.city_name
alias: true
copy_to: false

- from: source_ecs.geo.region_iso_code
to: source.geo.region_iso_code
alias: true
copy_to: false

# From Auditbeat's auditd module.
- from: source.hostname
to: source.domain
alias: true
copy_to: false
Loading