├── tests ├── __init__.py ├── docker-compose.yml ├── helpers.py ├── test_entrypoint.py ├── test_process.py ├── constants.py ├── test_labels.py ├── conftest.py ├── test_basics.py ├── test_settings.py └── fixtures.py ├── version.json ├── .travis.yml ├── requirements.txt ├── tox.ini ├── bin ├── pytest └── elastic-version ├── .gitignore ├── .ci └── jobs │ ├── elastic+logstash-docker+master+snapshot.yml │ ├── elastic+logstash-docker+6.8+snapshot.yml │ ├── elastic+logstash-docker+7.1+snapshot.yml │ ├── elastic+logstash-docker+7.x+snapshot.yml │ └── defaults.yml ├── examples └── logstash.conf ├── README.md ├── templates ├── docker-compose.yml.j2 └── Dockerfile.j2 ├── Makefile └── LICENSE /tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /version.json: -------------------------------------------------------------------------------- 1 | {"version": "8.0.0"} 2 | -------------------------------------------------------------------------------- /tests/docker-compose.yml: -------------------------------------------------------------------------------- 1 | --- 2 | version: '3' 3 | services: 4 | logstash: 5 | container_name: logstash-test 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: python 3 | python: ['3.5'] 4 | script: make 5 | 6 | sudo: required 7 | services: ['docker'] 8 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | docker-compose==1.11.2 2 | flake8==3.4.1 3 | jinja2-cli[yaml]==0.6.0 4 | jinja2==2.9.5 5 | retrying==1.3.3 6 | testinfra==1.6.0 7 | pyfiglet 8 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /bin/pytest: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # A wrapper for `pytest` to handle the appropriate Testinfra arguments. 4 | 5 | ./venv/bin/pytest --verbose --connection=docker --hosts=logstash-test $@ 6 | -------------------------------------------------------------------------------- /tests/helpers.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | import os 3 | from .constants import image, version 4 | 5 | try: 6 | version += '-%s' % os.environ['STAGING_BUILD_NUM'] 7 | except KeyError: 8 | pass 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .envrc 2 | .#* 3 | venv 4 | .cache 5 | **/__pycache__ 6 | *.pyc 7 | /build/logstash/env2yaml/env2yaml 8 | /build/logstash/Dockerfile* 9 | /docker-compose*.yml 10 | /.pytest_cache 11 | snapshots 12 | -------------------------------------------------------------------------------- /.ci/jobs/elastic+logstash-docker+master+snapshot.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - job: 3 | name: elastic+logstash-docker+master+snapshot 4 | display-name: 'elastic / logstash-docker # master - snapshot' 5 | description: Periodic testing of snapshot builds for the Logstash Docker master 6 | branch. 7 | -------------------------------------------------------------------------------- /examples/logstash.conf: -------------------------------------------------------------------------------- 1 | input { 2 | heartbeat { 3 | interval => 5 4 | message => 'Hello from Logstash 💓' 5 | } 6 | } 7 | 8 | output { 9 | elasticsearch { 10 | hosts => [ 'elasticsearch' ] 11 | user => 'elastic' 12 | password => 'changeme' 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This repository is no longer used to generate the official [Logstash][logstash] Docker image from [Elastic][elastic]. 2 | 3 | To build Logstash docker images for pre-6.6 releases, switch branches in this repo to the matching release. 4 | 5 | [logstash]: https://www.elastic.co/products/logstash 6 | [elastic]: https://www.elastic.co/ 7 | -------------------------------------------------------------------------------- /tests/test_entrypoint.py: -------------------------------------------------------------------------------- 1 | from .fixtures import logstash 2 | import pytest 3 | 4 | 5 | @pytest.mark.xfail 6 | def test_whitespace_in_config_string_cli_flag(logstash): 7 | config = 'input{heartbeat{}} output{stdout{}}' 8 | assert logstash.run("-t -e '%s'" % config).rc == 0 9 | 10 | 11 | def test_running_an_arbitrary_command(logstash): 12 | result = logstash.run('uname --all') 13 | assert result.rc == 0 14 | assert 'GNU/Linux' in str(result.stdout) 15 | -------------------------------------------------------------------------------- /.ci/jobs/elastic+logstash-docker+6.8+snapshot.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - job: 3 | name: elastic+logstash-docker+6.8+snapshot 4 | display-name: 'elastic / logstash-docker # 6.8 - snapshot' 5 | description: Periodic testing of snapshot builds for the Logstash Docker 6.8 branch. 6 | parameters: 7 | - string: 8 | name: branch_specifier 9 | default: refs/heads/6.8 10 | description: the Git branch specifier to build (<branchName>, <tagName>, 11 | <commitId>, etc.) 12 | -------------------------------------------------------------------------------- /.ci/jobs/elastic+logstash-docker+7.1+snapshot.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - job: 3 | name: elastic+logstash-docker+7.1+snapshot 4 | display-name: 'elastic / logstash-docker # 7.1 - snapshot' 5 | description: Periodic testing of snapshot builds for the Logstash Docker 7.1 branch. 6 | parameters: 7 | - string: 8 | name: branch_specifier 9 | default: refs/heads/7.1 10 | description: the Git branch specifier to build (<branchName>, <tagName>, 11 | <commitId>, etc.) 12 | -------------------------------------------------------------------------------- /.ci/jobs/elastic+logstash-docker+7.x+snapshot.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - job: 3 | name: elastic+logstash-docker+7.x+snapshot 4 | display-name: 'elastic / logstash-docker # 7.x - snapshot' 5 | description: Periodic testing of snapshot builds for the Logstash Docker 7.x branch. 6 | parameters: 7 | - string: 8 | name: branch_specifier 9 | default: refs/heads/7.x 10 | description: the Git branch specifier to build (<branchName>, <tagName>, 11 | <commitId>, etc.) 12 | -------------------------------------------------------------------------------- /tests/test_process.py: -------------------------------------------------------------------------------- 1 | from .fixtures import logstash 2 | 3 | 4 | def test_process_is_pid_1(logstash): 5 | assert logstash.process.pid == 1 6 | 7 | 8 | def test_process_is_running_as_the_correct_user(logstash): 9 | assert logstash.process.user == 'logstash' 10 | 11 | 12 | def test_process_is_running_with_cgroup_override_flags(logstash): 13 | # REF: https://github.com/elastic/logstash-docker/pull/97 14 | assert '-Dls.cgroup.cpu.path.override=/' in logstash.process.args 15 | assert '-Dls.cgroup.cpuacct.path.override=/' in logstash.process.args 16 | -------------------------------------------------------------------------------- /tests/constants.py: -------------------------------------------------------------------------------- 1 | import os 2 | import pytest 3 | from subprocess import run, PIPE 4 | 5 | version = run('./bin/elastic-version', stdout=PIPE).stdout.decode().strip() 6 | version_number = version.split('-')[0] # '7.0.0-alpha1-SNAPSHOT' -> '7.0.0' 7 | logstash_version_string = 'logstash %s' % version_number # eg. 'logstash 7.0.0' 8 | 9 | 10 | try: 11 | if len(os.environ['STAGING_BUILD_NUM']) > 0: 12 | version += '-%s' % os.environ['STAGING_BUILD_NUM'] # eg. '5.3.0-d5b30bd7' 13 | except KeyError: 14 | pass 15 | 16 | container_name = 'logstash-test' 17 | -------------------------------------------------------------------------------- /templates/docker-compose.yml.j2: -------------------------------------------------------------------------------- 1 | --- 2 | version: '3.0' 3 | services: 4 | logstash: 5 | image: docker.elastic.co/logstash/logstash:{{ version_tag }} 6 | volumes: 7 | - ./examples/logstash.conf/:/usr/share/logstash/pipeline/logstash.conf 8 | networks: 9 | - elastic-stack 10 | 11 | elasticsearch: 12 | image: docker.elastic.co/elasticsearch/elasticsearch-platinum:{{ version_tag }} 13 | networks: 14 | - elastic-stack 15 | 16 | kibana: 17 | image: docker.elastic.co/kibana/kibana:{{ version_tag }} 18 | ports: [ '5601:5601' ] 19 | networks: 20 | - elastic-stack 21 | 22 | networks: 23 | elastic-stack: 24 | -------------------------------------------------------------------------------- /tests/test_labels.py: -------------------------------------------------------------------------------- 1 | from .fixtures import logstash 2 | 3 | 4 | def test_labels(logstash): 5 | labels = logstash.docker_metadata['Config']['Labels'] 6 | assert labels['org.label-schema.name'] == 'logstash' 7 | assert labels['org.label-schema.schema-version'] == '1.0' 8 | assert labels['org.label-schema.url'] == 'https://www.elastic.co/products/logstash' 9 | assert labels['org.label-schema.vcs-url'] == 'https://github.com/elastic/logstash-docker' 10 | assert labels['org.label-schema.vendor'] == 'Elastic' 11 | assert labels['org.label-schema.version'] == logstash.tag 12 | if logstash.image_flavor == 'oss': 13 | assert labels['license'] == 'Apache-2.0' 14 | else: 15 | assert labels['license'] == 'Elastic License' 16 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/conftest.py: -------------------------------------------------------------------------------- 1 | from subprocess import run 2 | import pytest 3 | from .constants import container_name, version 4 | import docker 5 | 6 | docker_engine = docker.from_env() 7 | 8 | 9 | def pytest_addoption(parser): 10 | """Customize testinfra with config options via cli args""" 11 | # Let us specify which docker-compose-(image_flavor).yml file to use 12 | parser.addoption('--image-flavor', action='store', default='full', 13 | help='Docker image flavor; the suffix used in docker-compose-.yml') 14 | 15 | 16 | @pytest.fixture(scope='session', autouse=True) 17 | def start_container(): 18 | image = 'docker.elastic.co/logstash/logstash-%s:%s' % (pytest.config.getoption('--image-flavor'), version) 19 | docker_engine.containers.run(image, name=container_name, detach=True, stdin_open=False) 20 | 21 | 22 | def pytest_unconfigure(config): 23 | container = docker_engine.containers.get(container_name) 24 | container.stop() 25 | container.remove() 26 | -------------------------------------------------------------------------------- /.ci/jobs/defaults.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | ##### GLOBAL METADATA 4 | 5 | - meta: 6 | cluster: devops-ci 7 | 8 | ##### JOB DEFAULTS 9 | 10 | - job: 11 | logrotate: 12 | daysToKeep: 30 13 | numToKeep: 100 14 | parameters: 15 | - string: 16 | name: branch_specifier 17 | default: refs/heads/master 18 | description: the Git branch specifier to build (<branchName>, <tagName>, 19 | <commitId>, etc.) 20 | properties: 21 | - github: 22 | url: https://github.com/elastic/logstash-docker/ 23 | - inject: 24 | properties-content: HOME=$JENKINS_HOME 25 | node: ubuntu 26 | scm: 27 | - git: 28 | name: origin 29 | credentials-id: f6c7695a-671e-4f4f-a331-acdce44ff9ba 30 | reference-repo: /var/lib/jenkins/.git-references/logstash-docker.git 31 | branches: 32 | - ${branch_specifier} 33 | url: https://github.com/elastic/logstash-docker.git 34 | basedir: '' 35 | wipe-workspace: 'True' 36 | triggers: 37 | - timed: H H/12 * * * 38 | wrappers: 39 | - ansicolor 40 | - timeout: 41 | type: absolute 42 | timeout: 120 43 | fail: true 44 | - timestamps 45 | - workspace-cleanup 46 | builders: 47 | - shell: |- 48 | #!/usr/local/bin/runbld 49 | make from-snapshot test-snapshot 50 | publishers: 51 | - email: 52 | recipients: infra-root+build@elastic.co 53 | -------------------------------------------------------------------------------- /tests/test_basics.py: -------------------------------------------------------------------------------- 1 | from .fixtures import logstash 2 | from .constants import logstash_version_string 3 | 4 | 5 | def test_logstash_is_the_correct_version(logstash): 6 | assert logstash_version_string in logstash.stdout_of('logstash --version') 7 | 8 | 9 | def test_the_default_user_is_logstash(logstash): 10 | assert logstash.stdout_of('whoami') == 'logstash' 11 | 12 | 13 | def test_that_the_user_home_directory_is_usr_share_logstash(logstash): 14 | assert logstash.environment('HOME') == '/usr/share/logstash' 15 | 16 | 17 | def test_locale_variables_are_set_correctly(logstash): 18 | assert logstash.environment('LANG') == 'en_US.UTF-8' 19 | assert logstash.environment('LC_ALL') == 'en_US.UTF-8' 20 | 21 | 22 | def test_opt_logstash_is_a_symlink_to_usr_share_logstash(logstash): 23 | assert logstash.stdout_of('realpath /opt/logstash') == '/usr/share/logstash' 24 | 25 | 26 | def test_all_logstash_files_are_owned_by_logstash(logstash): 27 | assert logstash.stdout_of('find /usr/share/logstash ! -user logstash') == '' 28 | 29 | 30 | def test_logstash_user_is_uid_1000(logstash): 31 | assert logstash.stdout_of('id -u logstash') == '1000' 32 | 33 | 34 | def test_logstash_user_is_gid_1000(logstash): 35 | assert logstash.stdout_of('id -g logstash') == '1000' 36 | 37 | 38 | def test_logging_config_does_not_log_to_files(logstash): 39 | assert logstash.stdout_of('grep RollingFile /logstash/config/log4j2.properties') == '' 40 | 41 | 42 | # REF: https://docs.openshift.com/container-platform/3.5/creating_images/guidelines.html 43 | def test_all_files_in_logstash_directory_are_gid_zero(logstash): 44 | bad_files = logstash.stdout_of('find /usr/share/logstash ! -gid 0').split() 45 | assert len(bad_files) is 0 46 | 47 | 48 | def test_all_directories_in_logstash_directory_are_setgid(logstash): 49 | bad_dirs = logstash.stdout_of('find /usr/share/logstash -type d ! -perm /g+s').split() 50 | assert len(bad_dirs) is 0 51 | -------------------------------------------------------------------------------- /templates/Dockerfile.j2: -------------------------------------------------------------------------------- 1 | # This Dockerfile was generated from templates/Dockerfile.j2 2 | {% if artifacts_dir -%} 3 | {% set url_root = 'http://localhost:8000/logstash/build/' -%} 4 | {% elif staging_build_num -%} 5 | {% set url_root = 'https://staging.elastic.co/%s/downloads/logstash' % version_tag -%} 6 | {% else -%} 7 | {% set url_root = 'https://artifacts.elastic.co/downloads/logstash' -%} 8 | {% endif -%} 9 | 10 | {% if image_flavor == 'oss' -%} 11 | {% set tarball = 'logstash-oss-%s.tar.gz' % elastic_version -%} 12 | {% else -%} 13 | {% set tarball = 'logstash-%s.tar.gz' % elastic_version -%} 14 | {% endif -%} 15 | 16 | 17 | FROM centos:7 18 | 19 | # Install Java and the "which" command, which is needed by Logstash's shell 20 | # scripts. 21 | RUN yum update -y && yum install -y java-1.8.0-openjdk-devel which && \ 22 | yum clean all 23 | 24 | # Provide a non-root user to run the process. 25 | RUN groupadd --gid 1000 logstash && \ 26 | adduser --uid 1000 --gid 1000 \ 27 | --home-dir /usr/share/logstash --no-create-home \ 28 | logstash 29 | 30 | # Add Logstash itself. 31 | RUN curl -Lo - {{ url_root }}/{{ tarball }} | \ 32 | tar zxf - -C /usr/share && \ 33 | mv /usr/share/logstash-{{ elastic_version }} /usr/share/logstash && \ 34 | chown --recursive logstash:logstash /usr/share/logstash/ && \ 35 | chown -R logstash:root /usr/share/logstash && \ 36 | chmod -R g=u /usr/share/logstash && \ 37 | find /usr/share/logstash -type d -exec chmod g+s {} \; && \ 38 | ln -s /usr/share/logstash /opt/logstash 39 | 40 | WORKDIR /usr/share/logstash 41 | 42 | ENV ELASTIC_CONTAINER true 43 | ENV PATH=/usr/share/logstash/bin:$PATH 44 | 45 | # Provide a minimal configuration, so that simple invocations will provide 46 | # a good experience. 47 | ADD config/pipelines.yml config/pipelines.yml 48 | ADD config/logstash-{{ image_flavor }}.yml config/logstash.yml 49 | ADD config/log4j2.properties config/ 50 | ADD pipeline/default.conf pipeline/logstash.conf 51 | RUN chown --recursive logstash:root config/ pipeline/ 52 | 53 | # Ensure Logstash gets a UTF-8 locale by default. 54 | ENV LANG='en_US.UTF-8' LC_ALL='en_US.UTF-8' 55 | 56 | # Place the startup wrapper script. 57 | ADD bin/docker-entrypoint /usr/local/bin/ 58 | RUN chmod 0755 /usr/local/bin/docker-entrypoint 59 | 60 | USER 1000 61 | 62 | ADD env2yaml/env2yaml /usr/local/bin/ 63 | 64 | EXPOSE 9600 5044 65 | 66 | 67 | LABEL org.label-schema.schema-version="1.0" \ 68 | org.label-schema.vendor="Elastic" \ 69 | org.label-schema.name="logstash" \ 70 | org.label-schema.version="{{ elastic_version }}" \ 71 | org.label-schema.url="https://www.elastic.co/products/logstash" \ 72 | org.label-schema.vcs-url="https://github.com/elastic/logstash-docker" \ 73 | {% if image_flavor == 'oss' -%} 74 | license="Apache-2.0" 75 | {% else -%} 76 | license="Elastic License" 77 | {% endif -%} 78 | 79 | 80 | ENTRYPOINT ["/usr/local/bin/docker-entrypoint"] 81 | -------------------------------------------------------------------------------- /tests/test_settings.py: -------------------------------------------------------------------------------- 1 | from .fixtures import logstash 2 | from retrying import retry 3 | import time 4 | 5 | 6 | def test_setting_pipeline_workers_from_environment(logstash): 7 | logstash.restart(args='-e pipeline.workers=6') 8 | assert logstash.get_node_info()['pipelines']['main']['workers'] == 6 9 | 10 | 11 | def test_setting_pipeline_batch_size_from_environment(logstash): 12 | logstash.restart(args='-e pipeline.batch.size=123') 13 | assert logstash.get_node_info()['pipelines']['main']['batch_size'] == 123 14 | 15 | 16 | def test_setting_pipeline_batch_delay_from_environment(logstash): 17 | logstash.restart(args='-e pipeline.batch.delay=36') 18 | assert logstash.get_node_info()['pipelines']['main']['batch_delay'] == 36 19 | 20 | 21 | def test_setting_pipeline_unsafe_shutdown_from_environment(logstash): 22 | logstash.restart(args='-e pipeline.unsafe_shutdown=true') 23 | assert logstash.get_settings()['pipeline.unsafe_shutdown'] is True 24 | 25 | 26 | def test_setting_pipeline_unsafe_shutdown_with_shell_style_variable(logstash): 27 | logstash.restart(args='-e PIPELINE_UNSAFE_SHUTDOWN=true') 28 | assert logstash.get_settings()['pipeline.unsafe_shutdown'] is True 29 | 30 | 31 | def test_setting_things_with_upcased_and_underscored_env_vars(logstash): 32 | logstash.restart(args='-e PIPELINE_BATCH_DELAY=24') 33 | assert logstash.get_node_info()['pipelines']['main']['batch_delay'] == 24 34 | 35 | 36 | def test_disabling_xpack_monitoring_via_environment(logstash): 37 | logstash.restart(args='-e xpack.monitoring.enabled=false') 38 | assert logstash.get_settings()['xpack.monitoring.enabled'] is False 39 | 40 | 41 | def test_enabling_java_execution_via_environment(logstash): 42 | logstash.restart(args='-e pipeline.java_execution=true') 43 | logstash.assert_in_log('logstash.javapipeline') 44 | 45 | 46 | def test_disabling_java_execution_via_environment(logstash): 47 | logstash.restart(args='-e pipeline.java_execution=true') 48 | logstash.assert_not_in_log('logstash.javapipeline') 49 | 50 | 51 | def test_setting_elasticsearch_urls_as_an_array(logstash): 52 | setting_string = '["http://node1:9200","http://node2:9200"]' 53 | logstash.restart(args='-e xpack.monitoring.elasticsearch.hosts=%s' % setting_string) 54 | live_setting = logstash.get_settings()['xpack.monitoring.elasticsearch.hosts'] 55 | assert type(live_setting) is list 56 | assert 'http://node1:9200' in live_setting 57 | assert 'http://node2:9200' in live_setting 58 | 59 | 60 | def test_invalid_settings_in_environment_are_ignored(logstash): 61 | logstash.restart(args='-e cheese.ftw=true') 62 | assert not logstash.settings_file.contains('cheese.ftw') 63 | 64 | 65 | def test_settings_file_is_untouched_when_no_settings_in_env(logstash): 66 | original_timestamp = logstash.settings_file.mtime 67 | original_hash = logstash.settings_file.sha256sum 68 | logstash.restart() 69 | time.sleep(1) # since mtime() has one second resolution 70 | assert logstash.settings_file.mtime == original_timestamp 71 | assert logstash.settings_file.sha256sum == original_hash 72 | -------------------------------------------------------------------------------- /tests/fixtures.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | import yaml 4 | from pytest import config, fixture 5 | from .constants import container_name, version 6 | from retrying import retry 7 | from subprocess import run, PIPE 8 | from time import sleep 9 | 10 | retry_settings = { 11 | 'wait_fixed': 1000, 12 | 'stop_max_attempt_number': 60 13 | } 14 | 15 | 16 | @fixture 17 | def logstash(host): 18 | class Logstash: 19 | def __init__(self): 20 | self.version = version 21 | self.name = container_name 22 | self.process = host.process.get(comm='java') 23 | self.settings_file = host.file('/usr/share/logstash/config/logstash.yml') 24 | self.image_flavor = config.getoption('--image-flavor') 25 | self.image = 'docker.elastic.co/logstash/logstash-%s:%s' % (self.image_flavor, version) 26 | 27 | if 'STAGING_BUILD_NUM' in os.environ: 28 | self.tag = '%s-%s' % (self.version, os.environ['STAGING_BUILD_NUM']) 29 | else: 30 | self.tag = self.version 31 | 32 | self.docker_metadata = json.loads( 33 | run(['docker', 'inspect', self.image], stdout=PIPE).stdout.decode())[0] 34 | 35 | def start(self, args=None): 36 | if args: 37 | arg_array = args.split(' ') 38 | else: 39 | arg_array = [] 40 | run(['docker', 'run', '-d', '--name', self.name] + arg_array + [self.image]) 41 | 42 | def stop(self): 43 | run(['docker', 'kill', self.name]) 44 | run(['docker', 'rm', self.name]) 45 | 46 | def restart(self, args=None): 47 | self.stop() 48 | self.start(args) 49 | 50 | @retry(**retry_settings) 51 | def get_node_info(self): 52 | """Return the contents of Logstash's node info API. 53 | 54 | It retries for a while, since Logstash may still be coming up. 55 | Refer: https://www.elastic.co/guide/en/logstash/master/node-info-api.html 56 | """ 57 | result = json.loads(host.command.check_output('curl -s http://localhost:9600/_node')) 58 | assert 'workers' in result['pipelines']['main'] 59 | return result 60 | 61 | def get_settings(self): 62 | return yaml.load(self.settings_file.content_string) 63 | 64 | def run(self, command): 65 | return host.run(command) 66 | 67 | def stdout_of(self, command): 68 | return host.run(command).stdout.strip() 69 | 70 | def stderr_of(self, command): 71 | return host.run(command).stderr.strip() 72 | 73 | def environment(self, varname): 74 | environ = {} 75 | for line in self.run('env').stdout.strip().split("\n"): 76 | var, value = line.split('=') 77 | environ[var] = value 78 | return environ[varname] 79 | 80 | def get_docker_log(self): 81 | return run(['docker', 'logs', self.name], stdout=PIPE).stdout.decode() 82 | 83 | @retry(**retry_settings) 84 | def assert_in_log(self, string): 85 | assert string in self.get_docker_log() 86 | 87 | @retry(**retry_settings) 88 | def assert_not_in_log(self, string): 89 | assert string not in self.get_docker_log() 90 | 91 | return Logstash() 92 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SHELL=/bin/bash 2 | ELASTIC_REGISTRY ?= docker.elastic.co 3 | 4 | export PATH := ./bin:./venv/bin:$(PATH) 5 | 6 | # Determine the version to build. Override by setting ELASTIC_VERSION env var. 7 | ELASTIC_VERSION := $(shell ./bin/elastic-version) 8 | 9 | ifdef STAGING_BUILD_NUM 10 | VERSION_TAG := $(ELASTIC_VERSION)-$(STAGING_BUILD_NUM) 11 | else 12 | VERSION_TAG := $(ELASTIC_VERSION) 13 | endif 14 | 15 | IMAGE_FLAVORS ?= oss full 16 | DEFAULT_IMAGE_FLAVOR ?= full 17 | 18 | IMAGE_TAG := $(ELASTIC_REGISTRY)/logstash/logstash 19 | HTTPD ?= logstash-docker-artifact-server 20 | 21 | FIGLET := pyfiglet -w 160 -f puffy 22 | 23 | all: build 24 | 25 | test: lint docker-compose 26 | $(foreach FLAVOR, $(IMAGE_FLAVORS), \ 27 | $(FIGLET) "test: $(FLAVOR)"; \ 28 | ./bin/pytest tests --image-flavor=$(FLAVOR); \ 29 | ) 30 | 31 | test-snapshot: 32 | ELASTIC_VERSION=$(ELASTIC_VERSION)-SNAPSHOT make test 33 | 34 | lint: venv 35 | flake8 tests 36 | 37 | build: dockerfile docker-compose env2yaml 38 | docker pull centos:7 39 | $(foreach FLAVOR, $(IMAGE_FLAVORS), \ 40 | docker build -t $(IMAGE_TAG)-$(FLAVOR):$(VERSION_TAG) \ 41 | -f build/logstash/Dockerfile-$(FLAVOR) build/logstash; \ 42 | if [[ $(FLAVOR) == $(DEFAULT_IMAGE_FLAVOR) ]]; then \ 43 | docker tag $(IMAGE_TAG)-$(FLAVOR):$(VERSION_TAG) $(IMAGE_TAG):$(VERSION_TAG); \ 44 | fi; \ 45 | ) 46 | 47 | release-manager-snapshot: clean 48 | ARTIFACTS_DIR=$(ARTIFACTS_DIR) ELASTIC_VERSION=$(ELASTIC_VERSION)-SNAPSHOT make build-from-local-artifacts 49 | 50 | release-manager-release: clean 51 | ARTIFACTS_DIR=$(ARTIFACTS_DIR) ELASTIC_VERSION=$(ELASTIC_VERSION) make build-from-local-artifacts 52 | 53 | # Build from artifacts on the local filesystem, using an http server (running 54 | # in a container) to provide the artifacts to the Dockerfile. 55 | build-from-local-artifacts: venv dockerfile docker-compose env2yaml 56 | docker run --rm -d --name=$(HTTPD) \ 57 | --network=host -v $(ARTIFACTS_DIR):/mnt \ 58 | python:3 bash -c 'cd /mnt && python3 -m http.server' 59 | timeout 120 bash -c 'until curl -s localhost:8000 > /dev/null; do sleep 1; done' 60 | -$(foreach FLAVOR, $(IMAGE_FLAVORS), \ 61 | pyfiglet -f puffy -w 160 "Building: $(FLAVOR)"; \ 62 | docker build --network=host -t $(IMAGE_TAG)-$(FLAVOR):$(VERSION_TAG) -f build/logstash/Dockerfile-$(FLAVOR) build/logstash || \ 63 | (docker kill $(HTTPD); false); \ 64 | if [[ $(FLAVOR) == $(DEFAULT_IMAGE_FLAVOR) ]]; then \ 65 | docker tag $(IMAGE_TAG)-$(FLAVOR):$(VERSION_TAG) $(IMAGE_TAG):$(VERSION_TAG); \ 66 | fi; \ 67 | ) 68 | -docker kill $(HTTPD) 69 | 70 | # Build images from the latest snapshots on snapshots.elastic.co 71 | from-snapshot: 72 | rm -rf snapshots/ 73 | mkdir -p snapshots/logstash/build/ 74 | (cd snapshots/logstash/build/ && \ 75 | wget https://snapshots.elastic.co/downloads/logstash/logstash-$(ELASTIC_VERSION)-SNAPSHOT.tar.gz && \ 76 | wget https://snapshots.elastic.co/downloads/logstash/logstash-oss-$(ELASTIC_VERSION)-SNAPSHOT.tar.gz) 77 | ARTIFACTS_DIR=$$PWD/snapshots make release-manager-snapshot 78 | 79 | demo: docker-compose clean-demo 80 | docker-compose up 81 | 82 | # Push the image to the dedicated push endpoint at "push.docker.elastic.co" 83 | push: test 84 | $(foreach FLAVOR, $(IMAGE_FLAVORS), \ 85 | docker tag $(IMAGE_TAG)-$(FLAVOR):$(VERSION_TAG) push.$(IMAGE_TAG)-$(FLAVOR):$(VERSION_TAG); \ 86 | docker push push.$(IMAGE_TAG)-$(FLAVOR):$(VERSION_TAG); \ 87 | docker rmi push.$(IMAGE_TAG)-$(FLAVOR):$(VERSION_TAG); \ 88 | ) 89 | # Also push the default version, with no suffix like '-oss' or '-full' 90 | docker tag $(IMAGE_TAG):$(VERSION_TAG) push.$(IMAGE_TAG):$(VERSION_TAG); 91 | docker push push.$(IMAGE_TAG):$(VERSION_TAG); 92 | docker rmi push.$(IMAGE_TAG):$(VERSION_TAG); 93 | 94 | # The tests are written in Python. Make a virtualenv to handle the dependencies. 95 | venv: requirements.txt 96 | @if [ -z $$PYTHON3 ]; then\ 97 | PY3_MINOR_VER=`python3 --version 2>&1 | cut -d " " -f 2 | cut -d "." -f 2`;\ 98 | if (( $$PY3_MINOR_VER < 5 )); then\ 99 | echo "Couldn't find python3 in \$PATH that is >=3.5";\ 100 | echo "Please install python3.5 or later or explicity define the python3 executable name with \$PYTHON3";\ 101 | echo "Exiting here";\ 102 | exit 1;\ 103 | else\ 104 | export PYTHON3="python3.$$PY3_MINOR_VER";\ 105 | fi;\ 106 | fi;\ 107 | test -d venv || virtualenv --python=$$PYTHON3 venv;\ 108 | pip install -r requirements.txt;\ 109 | touch venv;\ 110 | 111 | # Make a Golang container that can compile our env2yaml tool. 112 | golang: 113 | docker build -t golang:env2yaml build/golang 114 | 115 | # Compile "env2yaml", the helper for configuring logstash.yml via environment 116 | # variables. 117 | env2yaml: golang 118 | docker run --rm -i \ 119 | -v ${PWD}/build/logstash/env2yaml:/usr/local/src/env2yaml:Z \ 120 | golang:env2yaml 121 | 122 | # Generate the Dockerfiles from Jinja2 templates. 123 | dockerfile: venv templates/Dockerfile.j2 124 | $(foreach FLAVOR, $(IMAGE_FLAVORS), \ 125 | jinja2 \ 126 | -D elastic_version='$(ELASTIC_VERSION)' \ 127 | -D staging_build_num='$(STAGING_BUILD_NUM)' \ 128 | -D version_tag='$(VERSION_TAG)' \ 129 | -D image_flavor='$(FLAVOR)' \ 130 | -D artifacts_dir='$(ARTIFACTS_DIR)' \ 131 | templates/Dockerfile.j2 > build/logstash/Dockerfile-$(FLAVOR); \ 132 | ) 133 | 134 | 135 | # Generate docker-compose files from Jinja2 templates. 136 | docker-compose: venv 137 | $(foreach FLAVOR, $(IMAGE_FLAVORS), \ 138 | jinja2 \ 139 | -D version_tag='$(VERSION_TAG)' \ 140 | -D image_flavor='$(FLAVOR)' \ 141 | templates/docker-compose.yml.j2 > docker-compose-$(FLAVOR).yml; \ 142 | ) 143 | ln -sf docker-compose-$(DEFAULT_IMAGE_FLAVOR).yml docker-compose.yml 144 | 145 | clean: clean-demo 146 | rm -f build/logstash/env2yaml/env2yaml build/logstash/Dockerfile 147 | rm -rf venv 148 | 149 | clean-demo: docker-compose 150 | docker-compose down 151 | docker-compose rm --force 152 | 153 | .PHONY: build clean clean-demo demo push test 154 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------