├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .travis.yml ├── LICENSE ├── Makefile ├── README.md ├── bin ├── elastic-version └── pytest ├── build └── apm-server │ └── config │ └── apm-server.yml ├── requirements.txt ├── templates ├── Dockerfile.j2 ├── docker-compose.yml.j2 └── docker-entrypoint.j2 ├── tests ├── __init__.py ├── conftest.py ├── fixtures.py ├── helpers.py ├── test_base.py ├── test_config.py ├── test_entrypoint.py ├── test_files.py ├── test_labels.py ├── test_process.py └── test_user.py ├── tox.ini └── version.json /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Please post all questions and issues on https://discuss.elastic.co 2 | before opening a Github Issue. Your questions will reach a wider audience there, 3 | and if we confirm that there is a bug, then you can open a new issue. 4 | 5 | For security vulnerabilities please only send reports to security@elastic.co. 6 | See https://www.elastic.co/community/security for more information. 7 | 8 | For confirmed bugs, please report: 9 | - APM Server Version: 10 | - Operating System: 11 | - Docker Version: 12 | - Steps to Reproduce: 13 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Does this PR include tests? 2 | 3 | `apm-server-docker` is developed under a test-driven 4 | workflow, so please refrain from submitting patches without test 5 | coverage. If you are not familiar with testing in Python, please 6 | raise an issue instead. 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | venv 2 | build/*/Dockerfile* 3 | build/*/config/*.sh 4 | build/*/docker-entrypoint 5 | docker-compose*.yml 6 | .cache 7 | **/__pycache__ 8 | .pytest_cache 9 | snapshots 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: python 3 | python: ['3.5'] 4 | script: make 5 | 6 | sudo: required 7 | services: ['docker'] 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SHELL := /bin/bash 2 | 3 | export ELASTIC_VERSION := $(shell ./bin/elastic-version) 4 | 5 | ifdef STAGING_BUILD_NUM 6 | export VERSION_TAG := $(ELASTIC_VERSION)-$(STAGING_BUILD_NUM) 7 | DOWNLOAD_URL_ROOT ?= https://staging.elastic.co/$(VERSION_TAG)/downloads/apm-server 8 | else 9 | export VERSION_TAG := $(ELASTIC_VERSION) 10 | DOWNLOAD_URL_ROOT ?= https://artifacts.elastic.co/downloads/apm-server 11 | endif 12 | 13 | REGISTRY ?= docker.elastic.co 14 | HTTPD ?= apm-server-docker-artifact-server 15 | HTTPD_PORT ?= 8000 16 | DOCKER_ARGS ?= --network host 17 | 18 | IMAGE_FLAVORS ?= oss full 19 | FIGLET := pyfiglet -w 160 -f puffy 20 | 21 | BUILD_ARTIFACT_PATH ?= apm-server/build/distributions 22 | 23 | # Make sure we run local versions of everything, particularly commands 24 | # installed into our virtualenv with pip eg. `docker-compose`. 25 | export PATH := ./bin:./venv/bin:$(PATH) 26 | 27 | all: venv image test 28 | 29 | test: templates lint 30 | $(foreach FLAVOR, $(IMAGE_FLAVORS), \ 31 | $(FIGLET) "test: $(FLAVOR)"; \ 32 | ./bin/pytest -v --image-flavor=$(FLAVOR) tests/; \ 33 | ) 34 | .PHONY: test 35 | 36 | # Test a snapshot image, which requires modifying the ELASTIC_VERSION to find the right images. 37 | test-snapshot: 38 | ELASTIC_VERSION=$(ELASTIC_VERSION)-SNAPSHOT make test 39 | 40 | 41 | lint: venv 42 | flake8 tests/ 43 | .PHONY: lint 44 | 45 | templates: venv 46 | mkdir -p build/apm-server/config 47 | touch build/apm-server/config/apm-server.yml 48 | jinja2 \ 49 | -D elastic_version=$(ELASTIC_VERSION) \ 50 | -D url=$(DOWNLOAD_URL_ROOT)/apm-server-$(ELASTIC_VERSION)-linux-x86_64.tar.gz \ 51 | -D image_flavor=full \ 52 | templates/Dockerfile.j2 > build/apm-server/Dockerfile-full 53 | 54 | jinja2 \ 55 | -D elastic_version=$(ELASTIC_VERSION) \ 56 | -D url=$(DOWNLOAD_URL_ROOT)/apm-server-oss-$(ELASTIC_VERSION)-linux-x86_64.tar.gz \ 57 | -D image_flavor=oss \ 58 | templates/Dockerfile.j2 > build/apm-server/Dockerfile-oss 59 | 60 | jinja2 \ 61 | -D elastic_version=$(ELASTIC_VERSION) \ 62 | templates/docker-entrypoint.j2 > build/apm-server/docker-entrypoint 63 | chmod +x build/apm-server/docker-entrypoint 64 | 65 | $(foreach FLAVOR, $(IMAGE_FLAVORS), \ 66 | jinja2 \ 67 | -D version=$(VERSION_TAG) \ 68 | -D registry=$(REGISTRY) \ 69 | -D image_flavor=$(FLAVOR) \ 70 | templates/docker-compose.yml.j2 > docker-compose-$(FLAVOR).yml; \ 71 | ) 72 | .PHONY: templates 73 | 74 | image: templates 75 | $(foreach FLAVOR, $(IMAGE_FLAVORS), \ 76 | docker build $(DOCKER_FLAGS) -f build/apm-server/Dockerfile-$(FLAVOR) --tag=$(REGISTRY)/apm/apm-server-$(FLAVOR):$(VERSION_TAG) build/apm-server; \ 77 | ) 78 | docker tag $(REGISTRY)/apm/apm-server-full:$(VERSION_TAG) $(REGISTRY)/apm/apm-server:$(VERSION_TAG) 79 | 80 | build-from-local-artifacts: templates 81 | docker run --rm -d --name=$(HTTPD) $(DOCKER_ARGS) \ 82 | -v $(ARTIFACTS_DIR):/mnt \ 83 | python:3 bash -c 'cd /mnt && python3 -m http.server $(HTTPD_PORT)' 84 | timeout 120 bash -c 'until curl -s localhost:$(HTTPD_PORT) > /dev/null; do sleep 1; done' 85 | 86 | DOCKER_FLAGS='--network=host' make image || \ 87 | (docker kill $(HTTPD); false) 88 | -docker kill $(HTTPD) 89 | 90 | release-manager-snapshot: 91 | ELASTIC_VERSION=$(ELASTIC_VERSION)-SNAPSHOT \ 92 | DOWNLOAD_URL_ROOT=http://localhost:$(HTTPD_PORT)/$(BUILD_ARTIFACT_PATH) \ 93 | IMAGE=$(IMAGE)-SNAPSHOT \ 94 | make build-from-local-artifacts 95 | 96 | release-manager-release: 97 | ELASTIC_VERSION=$(ELASTIC_VERSION) \ 98 | DOWNLOAD_URL_ROOT=http://localhost:$(HTTPD_PORT)/$(BUILD_ARTIFACT_PATH) \ 99 | IMAGE=$(IMAGE) \ 100 | make build-from-local-artifacts 101 | 102 | mac-release-snapshot: 103 | DOCKER_ARGS="--network bridge -p $(HTTPD_PORT):$(HTTPD_PORT)" \ 104 | make release-manager-snapshot 105 | 106 | from-snapshot: 107 | rm -rf ./snapshots 108 | mkdir -p snapshots/$(BUILD_ARTIFACT_PATH)/$$beat; \ 109 | (cd snapshots/$(BUILD_ARTIFACT_PATH)/$$beat && \ 110 | wget https://snapshots.elastic.co/downloads/apm-server/apm-server-$(ELASTIC_VERSION)-SNAPSHOT-linux-x86_64.tar.gz && \ 111 | wget https://snapshots.elastic.co/downloads/apm-server/apm-server-oss-$(ELASTIC_VERSION)-SNAPSHOT-linux-x86_64.tar.gz); \ 112 | ARTIFACTS_DIR=$$PWD/snapshots make release-manager-snapshot 113 | 114 | 115 | # Push the image to the dedicated push endpoint at "push.docker.elastic.co" 116 | push: all 117 | docker tag $(REGISTRY)/apm/apm-server:$(VERSION_TAG) push.$(REGISTRY)/apm/apm-server:$(VERSION_TAG) 118 | docker push push.$(REGISTRY)/apm/apm-server:$(VERSION_TAG) 119 | docker rmi push.$(REGISTRY)/apm/apm-server:$(VERSION_TAG) 120 | 121 | # The tests are written in Python. Make a virtualenv to handle the dependencies. 122 | venv: requirements.txt 123 | @if [ -z $$PYTHON3 ]; then\ 124 | PY3_MINOR_VER=`python3 --version 2>&1 | cut -d " " -f 2 | cut -d "." -f 2`;\ 125 | if (( $$PY3_MINOR_VER < 5 )); then\ 126 | echo "WARNING! Tests require python3 in \$PATH that is >=3.5";\ 127 | echo "Please install python3.5 or later or explicity define the python3 executable name with \$PYTHON3";\ 128 | echo "";\ 129 | else\ 130 | export PYTHON3="python3.$$PY3_MINOR_VER";\ 131 | fi;\ 132 | fi;\ 133 | test -d venv || virtualenv --python=$$PYTHON3 venv;\ 134 | pip install -r requirements.txt;\ 135 | touch venv;\ 136 | 137 | clean: venv 138 | docker-compose down -v || true 139 | rm -f docker-compose.yml build/*/Dockerfile build/*/config/*.sh build/*/docker-entrypoint 140 | rm -rf venv 141 | find . -name __pycache__ | xargs rm -rf 142 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This repository is no longer used to generate the official [APM Server][apm-server] Docker image from 2 | [Elastic][elastic]. 3 | 4 | See [APM Server packaging][new-packaging] instructions for the current build details. 5 | 6 | To build APM Server docker images for pre-6.6 releases, switch branches in this repo to the matching release. 7 | 8 | [apm-server]: https://www.elastic.co/guide/en/apm/server/current/index.html 9 | [elastic]: https://www.elastic.co/ 10 | [new-packaging]: https://github.com/elastic/apm-server/blob/master/README.md#packaging 11 | -------------------------------------------------------------------------------- /bin/elastic-version: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Print the Elastic Stack version for the current branch, as defined in 4 | # the 'version.json' file. 5 | # 6 | # The version can also be forced by setting the ELASTIC_VERSION environment variable. 7 | 8 | import json 9 | import os 10 | 11 | 12 | def get_hard_coded_version(): 13 | version_info = json.load(open('version.json')) 14 | return version_info['version'] 15 | 16 | 17 | def qualify(version): 18 | qualifier = os.getenv('VERSION_QUALIFIER') 19 | if qualifier: 20 | # ignore None or '' 21 | return "-".join([version, qualifier]) 22 | return version 23 | 24 | 25 | def get_version(): 26 | version = os.getenv('ELASTIC_VERSION') 27 | if version: 28 | return version 29 | return qualify(get_hard_coded_version()) 30 | 31 | 32 | if __name__ == '__main__': 33 | # Provide a shell compatible interface 34 | print(get_version()) 35 | -------------------------------------------------------------------------------- /bin/pytest: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # A wrapper for `pytest` to handle the appropriate testinfra arguments. 4 | 5 | source venv/bin/activate 6 | pytest --connection=docker --hosts=apm-server $@ 7 | -------------------------------------------------------------------------------- /build/apm-server/config/apm-server.yml: -------------------------------------------------------------------------------- 1 | output.elasticsearch: 2 | hosts: ['elasticsearch:9200'] 3 | username: elastic 4 | password: changeme 5 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | docker-compose==1.11.1 2 | flake8==3.3.0 3 | jinja2-cli[yaml]==0.6.0 4 | jinja2==2.9.5 5 | testinfra==1.5.3 6 | pip<10 7 | pyyaml==3.12 8 | pyfiglet 9 | -------------------------------------------------------------------------------- /templates/Dockerfile.j2: -------------------------------------------------------------------------------- 1 | # This Dockerfile was generated from templates/Dockerfile.j2 2 | {% set home = '/usr/share/apm-server' -%} 3 | {% set binary_file = '%s/%s' % (home, 'apm-server') -%} 4 | 5 | FROM centos:7 6 | 7 | RUN yum update -y && yum install -y curl && yum clean all 8 | 9 | RUN curl -Lso - {{ url }} | \ 10 | tar zxf - -C /tmp && \ 11 | mv /tmp/apm-server-{{ elastic_version }}-linux-x86_64 {{ home }} && \ 12 | sed -zri -e 's/output.elasticsearch:(\n[^\n]*){5}/output.elasticsearch:\n hosts: ["elasticsearch:9200"]/' -e 's/ host: "localhost:8200"/ host: "0.0.0.0:8200"/' {{ home }}/apm-server.yml 13 | 14 | ENV ELASTIC_CONTAINER true 15 | ENV PATH={{ home }}:$PATH 16 | 17 | # Add entrypoint wrapper script 18 | ADD docker-entrypoint /usr/local/bin 19 | 20 | # Provide a non-root user. 21 | RUN groupadd --gid 1000 apm-server && \ 22 | useradd -M --uid 1000 --gid 1000 --home {{ home }} apm-server 23 | 24 | WORKDIR {{ home }} 25 | RUN mkdir data logs && \ 26 | chown -R root:apm-server . && \ 27 | find {{ home }} -type d -exec chmod 0750 {} \; && \ 28 | find {{ home }} -type f -exec chmod 0640 {} \; && \ 29 | chmod 0750 {{ binary_file }} && \ 30 | chmod 0770 data logs 31 | 32 | # Remove the suid bit everywhere it is set to mitigate against stackclash 33 | RUN find / -xdev -perm -4000 -exec chmod u-s {} + 34 | 35 | USER 1000 36 | 37 | EXPOSE 8200 38 | 39 | LABEL org.label-schema.schema-version="1.0" \ 40 | org.label-schema.vendor="Elastic" \ 41 | org.label-schema.name="apm-server" \ 42 | org.label-schema.version="{{ elastic_version }}" \ 43 | org.label-schema.url="https://www.elastic.co/solutions/apm" \ 44 | org.label-schema.vcs-url="https://github.com/elastic/apm-server-docker" \ 45 | {% if image_flavor == 'oss' -%} 46 | license="Apache-2.0" 47 | {% else -%} 48 | license="Elastic License" 49 | {% endif -%} 50 | 51 | ENTRYPOINT ["/usr/local/bin/docker-entrypoint"] 52 | CMD ["-e"] 53 | -------------------------------------------------------------------------------- /templates/docker-compose.yml.j2: -------------------------------------------------------------------------------- 1 | --- 2 | # This file was generated from templates/docker-compose.yml.j2 3 | version: '2.1' 4 | services: 5 | apm-server: 6 | image: {{ registry }}/apm/apm-server-{{ image_flavor }}:{{ version }} 7 | container_name: apm-server 8 | -------------------------------------------------------------------------------- /templates/docker-entrypoint.j2: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -euo pipefail 4 | 5 | # Check if the the user has invoked the image with flags. 6 | # eg. "apm-server -c apm-server.yml" 7 | if [[ -z $1 ]] || [[ ${1:0:1} == '-' ]] ; then 8 | exec apm-server "$@" 9 | else 10 | # They may be looking for a subcommand, like "apm-server setup". 11 | subcommands=$(apm-server help \ 12 | | awk 'BEGIN {RS=""; FS="\n"} /Available Commands:/' \ 13 | | awk '/^\s+/ {print $1}') 14 | 15 | # If we _did_ get a subcommand, pass it to apm-server. 16 | for subcommand in $subcommands; do 17 | if [[ $1 == $subcommand ]]; then 18 | exec apm-server "$@" 19 | fi 20 | done 21 | fi 22 | 23 | # If niether of those worked, then they have specified the binary they want, so 24 | # just do exactly as they say. 25 | exec "$@" 26 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elastic/apm-server-docker/73ff393c4f4656e2c0982498679c96e0eaf83c05/tests/__init__.py -------------------------------------------------------------------------------- /tests/conftest.py: -------------------------------------------------------------------------------- 1 | from subprocess import run 2 | 3 | 4 | def get_compose_file(config): 5 | return 'docker-compose-%s.yml' % config.getoption('--image-flavor') 6 | 7 | 8 | def pytest_addoption(parser): 9 | """Customize testinfra with config options via cli args""" 10 | # Let us specify which docker-compose-(image_flavor).yml file to use 11 | parser.addoption('--image-flavor', action='store', 12 | help='Docker image flavor; the suffix used in docker-compose-.yml') 13 | 14 | 15 | def pytest_configure(config): 16 | run(['docker-compose', '-f', get_compose_file(config), 'down']) 17 | run(['docker-compose', '-f', get_compose_file(config), 'up', '--force-recreate', '-d', '--no-deps']) 18 | 19 | 20 | def pytest_unconfigure(config): 21 | run(['docker-compose', '-f', get_compose_file(config), 'down']) 22 | -------------------------------------------------------------------------------- /tests/fixtures.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | import pytest 4 | import yaml 5 | from subprocess import run, PIPE 6 | 7 | 8 | @pytest.fixture() 9 | def apm_server(Process, File, TestinfraBackend, Command): 10 | class ApmServer: 11 | def __init__(self): 12 | name = TestinfraBackend.get_hostname() 13 | home = os.path.join(os.sep, 'usr', 'share', name) 14 | 15 | self.name = name 16 | self.version = run('./bin/elastic-version', stdout=PIPE).stdout.decode().strip() 17 | self.process = Process.get(comm=name) 18 | self.home_dir = File(home) 19 | self.data_dir = File(os.path.join(home, 'data')) 20 | self.config_dir = File(home) 21 | self.log_dir = File(os.path.join(home, 'logs')) 22 | self.kibana_dir = File(os.path.join(home, 'kibana')) 23 | self.binary_file = File(os.path.join(home, name)) 24 | self.config_file = File(os.path.join(home, '%s.yml' % name)) 25 | 26 | # Use the "export config" subcommand to find out what the final 27 | # configuration will be. This gives a nice, normalized data structure 28 | # for making assertions about the config. 29 | export_config = Command.run('%s --path.config=%s export config' % 30 | (self.binary_file.path, self.config_dir.path)) 31 | self.config = yaml.load(export_config.stdout) 32 | 33 | if 'STAGING_BUILD_NUM' in os.environ: 34 | self.tag = '%s-%s' % (self.version, os.environ['STAGING_BUILD_NUM']) 35 | else: 36 | self.tag = self.version 37 | 38 | self.flavor = pytest.config.getoption('--image-flavor') 39 | if self.flavor != 'full': 40 | self.image = 'docker.elastic.co/apm/%s-%s:%s' % (self.name, self.flavor, self.tag) 41 | else: 42 | self.image = 'docker.elastic.co/apm/%s:%s' % (self.name, self.tag) 43 | 44 | self.docker_metadata = json.loads( 45 | run(['docker', 'inspect', self.image], stdout=PIPE).stdout.decode())[0] 46 | 47 | return ApmServer() 48 | -------------------------------------------------------------------------------- /tests/helpers.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | import os 3 | 4 | 5 | def run(apm_server, command, elevated_privileges=False): 6 | image = 'docker.elastic.co/apm/%s:%s' % (apm_server.name, apm_server.tag) 7 | 8 | if elevated_privileges: 9 | cli = 'docker run -u root --rm --interactive %s %s' % (image, command) 10 | else: 11 | cli = 'docker run --rm --interactive %s %s' % (image, command) 12 | 13 | result = subprocess.run(cli, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) 14 | result.stdout = result.stdout.rstrip() 15 | return result 16 | -------------------------------------------------------------------------------- /tests/test_base.py: -------------------------------------------------------------------------------- 1 | def test_base_os(SystemInfo): 2 | assert SystemInfo.distribution == 'centos' 3 | assert SystemInfo.release == '7' 4 | -------------------------------------------------------------------------------- /tests/test_config.py: -------------------------------------------------------------------------------- 1 | from .fixtures import apm_server 2 | 3 | 4 | def test_config_file_passes_config_test(Command, apm_server): 5 | configtest = '%s -c %s -configtest' % (apm_server.binary_file.path, apm_server.config_file.path) 6 | Command.run_expect([0], configtest) 7 | 8 | 9 | def test_apm_server_listens_on_all_interfaces(apm_server): 10 | configured_host = apm_server.config['apm-server']['host'] 11 | assert configured_host == '0.0.0.0:8200' 12 | 13 | 14 | def test_elasticsearch_output_points_to_elasticsearch_host(apm_server): 15 | configured_hosts = apm_server.config['output']['elasticsearch']['hosts'] 16 | assert configured_hosts == ['elasticsearch:9200'] 17 | -------------------------------------------------------------------------------- /tests/test_entrypoint.py: -------------------------------------------------------------------------------- 1 | from .fixtures import apm_server 2 | from .helpers import run 3 | 4 | 5 | def test_entrypoint_with_args(apm_server): 6 | cmd = run(apm_server, "-c %s -configtest" % apm_server.config_file.path) 7 | assert cmd.returncode == 0 8 | 9 | 10 | def test_entrypoint_with_apm_server_subcommand(apm_server): 11 | cmd = run(apm_server, 'help') 12 | assert cmd.returncode == 0 13 | assert 'Usage:' in cmd.stdout.decode() 14 | assert apm_server.name in cmd.stdout.decode() 15 | 16 | 17 | def test_entrypoint_with_apm_server_subcommand_and_longopt(apm_server): 18 | cmd = run(apm_server, 'setup --help') 19 | assert cmd.returncode == 0 20 | assert b'This command does initial setup' in cmd.stdout 21 | 22 | 23 | def test_entrypoint_with_abitrary_command(apm_server): 24 | cmd = run(apm_server, "echo Hello World!") 25 | assert cmd.returncode == 0 26 | assert cmd.stdout == b'Hello World!' 27 | 28 | 29 | def test_entrypoint_with_explicit_apm_server_binary(apm_server): 30 | cmd = run(apm_server, '%s --version' % apm_server.name) 31 | assert cmd.returncode == 0 32 | assert apm_server.version.replace('-SNAPSHOT', '') in cmd.stdout.decode() 33 | -------------------------------------------------------------------------------- /tests/test_files.py: -------------------------------------------------------------------------------- 1 | from .fixtures import apm_server 2 | from .helpers import run 3 | import os 4 | 5 | 6 | def test_binary_file_version(Command, apm_server): 7 | version_string = '%s version %s (amd64), libbeat %s' \ 8 | % (apm_server.name, apm_server.version, apm_server.version) 9 | command = Command('%s --version' % apm_server.binary_file.path) 10 | assert command.stdout.strip() == version_string.replace('-SNAPSHOT', '') 11 | 12 | 13 | def test_binary_file_permissions(apm_server): 14 | assert apm_server.binary_file.user == 'root' 15 | assert apm_server.binary_file.group == apm_server.name 16 | assert apm_server.binary_file.mode == 0o0750 17 | 18 | 19 | def test_config_file_permissions(apm_server): 20 | assert apm_server.config_file.user == 'root' 21 | assert apm_server.config_file.group == apm_server.name 22 | assert apm_server.config_file.mode == 0o0640 23 | 24 | 25 | def test_config_dir_permissions(apm_server): 26 | assert apm_server.config_dir.user == 'root' 27 | assert apm_server.config_dir.group == apm_server.name 28 | assert apm_server.config_dir.mode == 0o0750 29 | 30 | 31 | def test_data_dir_permissions(apm_server): 32 | assert apm_server.data_dir.user == 'root' 33 | assert apm_server.data_dir.group == apm_server.name 34 | assert apm_server.data_dir.mode == 0o0770 35 | 36 | 37 | def test_kibana_dir_permissions(apm_server): 38 | assert apm_server.kibana_dir.user == 'root' 39 | assert apm_server.kibana_dir.group == apm_server.name 40 | assert apm_server.kibana_dir.mode == 0o0750 41 | 42 | 43 | def test_log_dir_permissions(apm_server): 44 | assert apm_server.log_dir.user == 'root' 45 | assert apm_server.log_dir.group == apm_server.name 46 | assert apm_server.log_dir.mode == 0o0770 47 | 48 | 49 | def test_suid_bit_removed(apm_server): 50 | cmd = run(apm_server, "find / -xdev -perm -4000", True) 51 | assert cmd.returncode == 0 52 | assert not cmd.stdout 53 | assert not cmd.stderr 54 | -------------------------------------------------------------------------------- /tests/test_labels.py: -------------------------------------------------------------------------------- 1 | from .fixtures import apm_server 2 | 3 | 4 | def test_labels(apm_server): 5 | labels = apm_server.docker_metadata['Config']['Labels'] 6 | assert labels['org.label-schema.name'] == 'apm-server' 7 | assert labels['org.label-schema.schema-version'] == '1.0' 8 | assert labels['org.label-schema.url'] == 'https://www.elastic.co/solutions/apm' 9 | assert labels['org.label-schema.vcs-url'] == 'https://github.com/elastic/apm-server-docker' 10 | assert labels['org.label-schema.vendor'] == 'Elastic' 11 | assert labels['org.label-schema.version'] == apm_server.tag 12 | if apm_server.flavor == 'oss': 13 | assert labels['license'] == 'Apache-2.0' 14 | else: 15 | assert labels['license'] == 'Elastic License' 16 | -------------------------------------------------------------------------------- /tests/test_process.py: -------------------------------------------------------------------------------- 1 | from .fixtures import apm_server 2 | 3 | 4 | def test_process_is_pid_1(apm_server): 5 | assert apm_server.process.pid == 1 6 | 7 | 8 | def test_process_is_running_as_the_correct_user(apm_server): 9 | assert apm_server.process.user == apm_server.name 10 | 11 | 12 | def test_process_was_started_with_the_foreground_flag(apm_server): 13 | assert '-e' in apm_server.process['args'] 14 | -------------------------------------------------------------------------------- /tests/test_user.py: -------------------------------------------------------------------------------- 1 | from .fixtures import apm_server 2 | 3 | 4 | def test_group_properties(Group, apm_server): 5 | group = Group(apm_server.name) 6 | assert group.exists 7 | assert group.gid == 1000 8 | 9 | 10 | def test_user_properties(User, apm_server): 11 | user = User(apm_server.name) 12 | assert user.uid == 1000 13 | assert user.gid == 1000 14 | assert user.group == apm_server.name 15 | assert user.home == '/usr/share/%s' % apm_server.name 16 | assert user.shell == '/bin/bash' 17 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | # pytest fixtures (which are wonderful) trigger false positives for these 2 | # pyflakes checks. 3 | [flake8] 4 | ignore = F401,F811 5 | max-line-length = 120 6 | -------------------------------------------------------------------------------- /version.json: -------------------------------------------------------------------------------- 1 | {"version": "7.0.0"} 2 | --------------------------------------------------------------------------------