Skip to content

Commit

Permalink
[Agent] Make default config OS agnostic (elastic#17016)
Browse files Browse the repository at this point in the history
[Agent] Make default config OS agnostic (elastic#17016)
  • Loading branch information
michalpristas authored and ph committed Apr 7, 2020
1 parent 398e16b commit c66cfbf
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 37 deletions.
16 changes: 8 additions & 8 deletions dev-tools/packaging/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ shared:
/etc/init.d/{{.BeatServiceName}}:
template: '{{ elastic_beats_dir }}/dev-tools/packaging/templates/{{.PackageType}}/init.sh.tmpl'
mode: 0755
/etc/{{.BeatName}}/data/downloads/filebeat-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz:
/etc/{{.BeatName}}/data/downloads/filebeat-{{ beat_version }}-{{.GOOS}}-{{.AgentArchName}}.tar.gz:
source: '{{ elastic_beats_dir }}/x-pack/filebeat/build/distributions/filebeat-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz'
mode: 0644
/etc/{{.BeatName}}/data/downloads/metricbeat-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz:
/etc/{{.BeatName}}/data/downloads/metricbeat-{{ beat_version }}-{{.GOOS}}-{{.AgentArchName}}.tar.gz:
source: '{{ elastic_beats_dir }}/x-pack/metricbeat/build/distributions/metricbeat-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz'
mode: 0644

Expand Down Expand Up @@ -97,10 +97,10 @@ shared:
source: 'agent.yml'
mode: 0600
config: true
/etc/{{.BeatName}}/data/downloads/filebeat-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz:
/etc/{{.BeatName}}/data/downloads/filebeat-{{ beat_version }}-{{.GOOS}}-{{.AgentArchName}}.tar.gz:
source: '{{ elastic_beats_dir }}/x-pack/filebeat/build/distributions/filebeat-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz'
mode: 0644
/etc/{{.BeatName}}/data/downloads/metricbeat-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz:
/etc/{{.BeatName}}/data/downloads/metricbeat-{{ beat_version }}-{{.GOOS}}-{{.AgentArchName}}.tar.gz:
source: '{{ elastic_beats_dir }}/x-pack/metricbeat/build/distributions/metricbeat-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz'
mode: 0644

Expand Down Expand Up @@ -131,10 +131,10 @@ shared:
<<: *common
files:
<<: *agent_binary_files
'data/downloads/filebeat-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz':
'data/downloads/filebeat-{{ beat_version }}-{{.GOOS}}-{{.AgentArchName}}.tar.gz':
source: '{{ elastic_beats_dir }}/x-pack/filebeat/build/distributions/filebeat-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz'
mode: 0644
'data/downloads/metricbeat-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz':
'data/downloads/metricbeat-{{ beat_version }}-{{.GOOS}}-{{.AgentArchName}}.tar.gz':
source: '{{ elastic_beats_dir }}/x-pack/metricbeat/build/distributions/metricbeat-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz'
mode: 0644

Expand All @@ -149,10 +149,10 @@ shared:
uninstall-service-{{.BeatName}}.ps1:
template: '{{ elastic_beats_dir }}/dev-tools/packaging/templates/windows/uninstall-service.ps1.tmpl'
mode: 0755
'data/downloads/filebeat-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.zip':
'data/downloads/filebeat-{{ beat_version }}-{{.GOOS}}-{{.AgentArchName}}.zip':
source: '{{ elastic_beats_dir }}/x-pack/filebeat/build/distributions/filebeat-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.zip'
mode: 0644
'data/downloads/metricbeat-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.zip':
'data/downloads/metricbeat-{{ beat_version }}-{{.GOOS}}-{{.AgentArchName}}.zip':
source: '{{ elastic_beats_dir }}/x-pack/metricbeat/build/distributions/metricbeat-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.zip'
mode: 0644

Expand Down
52 changes: 52 additions & 0 deletions dev-tools/packaging/templates/docker/Dockerfile.agent.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{{- $beatHome := printf "%s/%s" "/usr/share" .BeatName }}
{{- $beatBinary := printf "%s/%s" $beatHome .BeatName }}
{{- $repoInfo := repo }}

FROM {{ .from }}

LABEL \
org.label-schema.build-date="{{ date }}" \
org.label-schema.schema-version="1.0" \
org.label-schema.vendor="{{ .BeatVendor }}" \
org.label-schema.license="{{ .License }}" \
org.label-schema.name="{{ .BeatName }}" \
org.label-schema.version="{{ beat_version }}" \
org.label-schema.url="{{ .BeatURL }}" \
org.label-schema.vcs-url="{{ $repoInfo.RootImportPath }}" \
org.label-schema.vcs-ref="{{ commit }}" \
license="{{ .License }}" \
description="{{ .BeatDescription }}"

ENV ELASTIC_CONTAINER "true"
ENV PATH={{ $beatHome }}:$PATH

COPY beat {{ $beatHome }}
COPY docker-entrypoint /usr/local/bin/docker-entrypoint
RUN chmod 755 /usr/local/bin/docker-entrypoint

RUN groupadd --gid 1000 {{ .BeatName }}

RUN mkdir -p {{ $beatHome }}/data {{ $beatHome }}/logs && \
chown -R root:{{ .BeatName }} {{ $beatHome }} && \
find {{ $beatHome }} -type d -exec chmod 0750 {} \; && \
find {{ $beatHome }} -type f -exec chmod 0640 {} \; && \
chmod 0750 {{ $beatBinary }} && \
{{- if .linux_capabilities }}
setcap {{ .linux_capabilities }} {{ $beatBinary }} && \
{{- end }}
{{- range $i, $modulesd := .ModulesDirs }}
chmod 0770 {{ $beatHome}}/{{ $modulesd }} && \
{{- end }}
chmod 0770 {{ $beatHome }}/data {{ $beatHome }}/logs

{{- if ne .user "root" }}
RUN useradd -M --uid 1000 --gid 1000 --home {{ $beatHome }} {{ .user }}
{{- end }}
USER {{ .user }}

{{- range $i, $port := .ExposePorts }}
EXPOSE {{ $port }}
{{- end }}

WORKDIR {{ $beatHome }}
ENTRYPOINT ["/usr/local/bin/docker-entrypoint"]
6 changes: 3 additions & 3 deletions x-pack/agent/_meta/agent.docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ download:
# e.g /windows-x86.zip
sourceURI: "https://artifacts.elastic.co/downloads/beats/"
# path to the directory containing downloaded packages
target_directory: "/home/elastic/downloads"
target_directory: "${path.data}/downloads"
# timeout for downloading package
timeout: 30s
# file path to a public key used for verifying downloaded artifacts
# if not file is present agent will try to load public key from elastic.co website.
pgpfile: "/home/elastic/elastic.pgp"
pgpfile: "${path.data}/elastic.pgp"
# install_path describes the location of installed packages/programs. It is also used
# for reading program specifications.
install_path: "/home/elastic/install"
install_path: "${path.data}/install"

process:
# minimal port number for spawned processes
Expand Down
6 changes: 3 additions & 3 deletions x-pack/agent/_meta/agent.fleet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ download:
# e.g /windows-x86.zip
sourceURI: "https://artifacts.elastic.co/downloads/beats/"
# path to the directory containing downloaded packages
target_directory: "/home/elastic/downloads"
target_directory: "${path.data}/downloads"
# timeout for downloading package
timeout: 30s
# file path to a public key used for verifying downloaded artifacts
# if not file is present agent will try to load public key from elastic.co website.
pgpfile: "/home/elastic/elastic.pgp"
pgpfile: "${path.data}/elastic.pgp"
# install_path describes the location of installed packages/programs. It is also used
# for reading program specifications.
install_path: "/home/elastic/install"
install_path: "${path.data}/install"

process:
# minimal port number for spawned processes
Expand Down
6 changes: 3 additions & 3 deletions x-pack/agent/_meta/agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ download:
# e.g /windows-x86.zip
sourceURI: "https://artifacts.elastic.co/downloads/beats/"
# path to the directory containing downloaded packages
target_directory: "/home/elastic/downloads"
target_directory: "${path.data}/downloads"
# timeout for downloading package
timeout: 30s
# file path to a public key used for verifying downloaded artifacts
# if not file is present agent will try to load public key from elastic.co website.
pgpfile: "/home/elastic/elastic.pgp"
pgpfile: "${path.data}/elastic.pgp"
# install_path describes the location of installed packages/programs. It is also used
# for reading program specifications.
install_path: "/home/elastic/install"
install_path: "${path.data}/install"

process:
# minimal port number for spawned processes
Expand Down
6 changes: 3 additions & 3 deletions x-pack/agent/_meta/common.p2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ download:
# e.g /windows-x86.zip
sourceURI: "https://artifacts.elastic.co/downloads/beats/"
# path to the directory containing downloaded packages
target_directory: "/home/elastic/downloads"
target_directory: "${path.data}/downloads"
# timeout for downloading package
timeout: 30s
# file path to a public key used for verifying downloaded artifacts
# if not file is present agent will try to load public key from elastic.co website.
pgpfile: "/home/elastic/elastic.pgp"
pgpfile: "${path.data}/elastic.pgp"
# install_path describes the location of installed packages/programs. It is also used
# for reading program specifications.
install_path: "/home/elastic/install"
install_path: "${path.data}/install"

process:
# minimal port number for spawned processes
Expand Down
6 changes: 3 additions & 3 deletions x-pack/agent/_meta/common.reference.p2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ download:
# e.g /windows-x86.zip
sourceURI: "https://artifacts.elastic.co/downloads/beats/"
# path to the directory containing downloaded packages
target_directory: "/home/elastic/downloads"
target_directory: "${path.data}/downloads"
# timeout for downloading package
timeout: 30s
# file path to a public key used for verifying downloaded artifacts
# if not file is present agent will try to load public key from elastic.co website.
pgpfile: "/home/elastic/elastic.pgp"
pgpfile: "${path.data}/elastic.pgp"
# install_path describes the location of installed packages/programs. It is also used
# for reading program specifications.
install_path: "/home/elastic/install"
install_path: "${path.data}/install"

process:
# minimal port number for spawned processes
Expand Down
6 changes: 3 additions & 3 deletions x-pack/agent/agent.docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ download:
# e.g /windows-x86.zip
sourceURI: "https://artifacts.elastic.co/downloads/beats/"
# path to the directory containing downloaded packages
target_directory: "/home/elastic/downloads"
target_directory: "${path.data}/downloads"
# timeout for downloading package
timeout: 30s
# file path to a public key used for verifying downloaded artifacts
# if not file is present agent will try to load public key from elastic.co website.
pgpfile: "/home/elastic/elastic.pgp"
pgpfile: "${path.data}/elastic.pgp"
# install_path describes the location of installed packages/programs. It is also used
# for reading program specifications.
install_path: "/home/elastic/install"
install_path: "${path.data}/install"

process:
# minimal port number for spawned processes
Expand Down
6 changes: 3 additions & 3 deletions x-pack/agent/agent.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ download:
# e.g /windows-x86.zip
sourceURI: "https://artifacts.elastic.co/downloads/beats/"
# path to the directory containing downloaded packages
target_directory: "/home/elastic/downloads"
target_directory: "${path.data}/downloads"
# timeout for downloading package
timeout: 30s
# file path to a public key used for verifying downloaded artifacts
# if not file is present agent will try to load public key from elastic.co website.
pgpfile: "/home/elastic/elastic.pgp"
pgpfile: "${path.data}/elastic.pgp"
# install_path describes the location of installed packages/programs. It is also used
# for reading program specifications.
install_path: "/home/elastic/install"
install_path: "${path.data}/install"

process:
# minimal port number for spawned processes
Expand Down
6 changes: 3 additions & 3 deletions x-pack/agent/agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ download:
# e.g /windows-x86.zip
sourceURI: "https://artifacts.elastic.co/downloads/beats/"
# path to the directory containing downloaded packages
target_directory: "/home/elastic/downloads"
target_directory: "${path.data}/downloads"
# timeout for downloading package
timeout: 30s
# file path to a public key used for verifying downloaded artifacts
# if not file is present agent will try to load public key from elastic.co website.
pgpfile: "/home/elastic/elastic.pgp"
pgpfile: "${path.data}/elastic.pgp"
# install_path describes the location of installed packages/programs. It is also used
# for reading program specifications.
install_path: "/home/elastic/install"
install_path: "${path.data}/install"

process:
# minimal port number for spawned processes
Expand Down
2 changes: 1 addition & 1 deletion x-pack/agent/pkg/agent/application/configuration_embed.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions x-pack/agent/pkg/agent/operation/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ func (o *Operator) runFlow(p Descriptor, operations []operation) error {
continue
}

o.logger.Debugf("running operation '%s' for %s.%s", op.Name(), p.BinaryName(), p.Version())
if err := op.Run(o.bgContext, app); err != nil {
return err
}
Expand Down
9 changes: 6 additions & 3 deletions x-pack/agent/pkg/artifact/download/fs/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import (

const (
packagePermissions = 0660
beatsSubfolder = "beats"
)

var (
defaultDropSubdir = filepath.Join("data", "downloads")
)

// Downloader is a downloader able to fetch artifacts from elastic.co web page.
Expand Down Expand Up @@ -83,13 +86,13 @@ func (e *Downloader) download(operatingSystem, programName, version string) (str
func getDropPath(cfg *artifact.Config) string {
// if drop path is not provided fallback to beats subfolder
if cfg == nil || cfg.DropPath == "" {
return beatsSubfolder
return defaultDropSubdir
}

// if droppath does not exist fallback to beats subfolder
stat, err := os.Stat(cfg.DropPath)
if err != nil || !stat.IsDir() {
return beatsSubfolder
return defaultDropSubdir
}

return cfg.DropPath
Expand Down
2 changes: 1 addition & 1 deletion x-pack/agent/pkg/artifact/download/fs/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (v *Verifier) Verify(programName, version string) (bool, error) {

func (v *Verifier) getPublicAsc(filename string) ([]byte, error) {
ascFile := fmt.Sprintf("%s%s", filename, ascSuffix)
fullPath := filepath.Join(beatsSubfolder, ascFile)
fullPath := filepath.Join(defaultDropSubdir, ascFile)

b, err := ioutil.ReadFile(fullPath)
if err != nil {
Expand Down

0 comments on commit c66cfbf

Please sign in to comment.