aboutsummaryrefslogtreecommitdiff
path: root/docker/macros.j2
blob: 25d3a375294eef6a7ac01514143cce3e40b19f5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
{% macro install_packages(packages, chain=False, clean=clean_package_cache) -%}
{% if packages is defined and packages|length > 0 -%}
    {% if not chain -%} RUN {% endif -%}
    {%- if base_package_type == 'rpm' -%}
        {{ distro_package_manager }} -y install {{ packages | join(' ') }}
        {%- if clean %} \
    && {{ distro_package_manager }} clean all && rm -rf /var/cache/{{ distro_package_manager }}{% endif -%}
    {%- elif base_package_type == 'deb' -%}
        {#-
          debian_package_install is a utility method to build up an appropriate
          set of commands to install packages in a debian-based environment that
          may include URL links to a .deb package
        -#}
        {{ debian_package_install(packages, clean) }}
    {%- endif %}
{%- endif %}
{%- endmacro %}

{# Be Extra vigilant about introducing any extra whitespace at the
   end of the macro for chaining purposes -#}
{% macro rpm_security_update(cleanup) -%}
    {{ distro_package_manager }} -y update --security --sec-severity=Important --sec-severity=Critical
    {%- if cleanup %} \
    && {{ distro_package_manager }} clean all && rm -rf /var/cache/{{ distro_package_manager }}{% endif -%}
{%- endmacro %}

{% macro sed(file='', expressions=[]) -%}
{% if file != '' and expressions|length >0 %}
    RUN {% for expression in expressions %} sed -i "{{ file }}" -e "{{ expression }}" {% if not loop.last %} && {% endif %} {% endfor %}
{% else %}
    RUN echo "file and expressions must be set to use the sed macro"; /bin/false
{% endif %}
{%- endmacro %}

{% macro get_pip() %}
{% if distro_python_version == '2.7' %}
    {% set python='python' %}
{% else %}
    {% set python='python3' %}
{% endif %}
RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py \
    && {{python}} get-pip.py \
    && rm get-pip.py
{% endmacro %}

{% macro install_pip(packages, constraints = true, pip_version = pip) %}
{%- if packages is sequence and packages|length > 0 -%}
{%- if not pip_version -%}
    {%- set pip_version = 'pip' -%}
{%- endif -%}
    {{ pip_version }} --no-cache-dir install --upgrade{{ ' ' }}
    {%- if constraints %}-c /requirements/upper-constraints.txt {% endif -%}
    {{ packages | join(' ') }}
{%- else -%}
    true
{%- endif -%}
{% endmacro %}

{% macro configure_user(name, groups=None, shell=None, homedir=None) %}
{% set user=users[name] %}
{%- if not homedir %}
{% set homedir='/var/lib/' + name %}
{%- endif %}
RUN usermod --append --home {{ homedir }} --groups kolla {{ name }} \
    {%- if groups %}
    && usermod --append --groups {{ groups }} {{ name }} \
    {%- endif %}
    {%- if shell %}
    && chsh --shell {{ shell }} {{ name }} \
    {%- endif %}
    && mkdir -p {{ homedir }} \
    && chown -R {{ user.uid }}:{{ user.gid }} {{ homedir }}
{% endmacro %}

{% macro debian_fix_existing_user(package, lines) %}
RUN apt-get update \
    && apt-get -y install --no-install-recommends {{ package }} \
    || sed -i '/adduser/,+{{ lines }} d' /var/lib/dpkg/info/{{ package }}.postinst \
    && echo "configuring packages" \
    && dpkg --configure -a \
    && echo "done" \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*
{% endmacro %}

{% macro debian_haproxy_existing_user_fix() %}
{# NOTE(SamYaple): The postinst script breaks if the user 'haproxy' already exists #}
    {{ debian_fix_existing_user('haproxy', 1) }}
{% endmacro %}

{% macro debian_mongodb_existing_user_fix() %}
{# NOTE(hrw): The postinst script breaks if the user 'mongodb' already exists #}
{# TODO(hrw): Version in Debian 'testing' checks does user exists #}
    {{ debian_fix_existing_user('mongodb-server', 3) }}
{% endmacro %}

{% macro debian_opendaylight_existing_user_fix() %}
{# NOTE(egonzalez): The postinst script breaks if the user 'odl' already exists #}
    {{ debian_fix_existing_user('opendaylight', 1) }}
{% endmacro %}

{% macro install_kubectl() %}
    # TODO(mandre) check for file integrity instead of downloading from an HTTPS source
    RUN curl -o /usr/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/v1.11.0/bin/linux/{{debian_arch}}/kubectl \
        && chmod 755 /usr/bin/kubectl
{% endmacro %}

{% macro install_fluent_plugins(plugins, chain=False) -%}
{% if plugins is defined and plugins|length > 0 -%}
    {% if not chain -%} RUN {% endif -%}
    {%- if base_distro in ['centos', 'oraclelinux', 'rhel'] -%}
        ulimit -n 65536 && gem install --minimal-deps {{ plugins | join(' ') }}
    {%- elif base_distro in ['debian', 'ubuntu'] -%}
        {%- if base_arch == 'x86_64' -%}
            ulimit -n 65536 && td-agent-gem install {{ plugins | join(' ') }}
        {%- else -%}
            ulimit -n 65536 && gem install --minimal-deps {{ plugins | join(' ') }}
        {%- endif %}
    {%- endif %}
{%- endif %}
{%- endmacro %}

{% macro install_rabbitmq_plugins(plugins, version) -%}
    ENV PLUGINS_DIR /usr/lib/rabbitmq/plugins
{% if plugins is defined and plugins|length > 0 -%}
    {% for item in plugins %}
         RUN curl -L -o ${PLUGINS_DIR}/{{ item }} https://github.com/deadtrickster/prometheus_rabbitmq_exporter/releases/download/{{ version }}/{{ item }}
    {% endfor %}
{%- endif %}
{%- endmacro %}