Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[dockers] Refactor Dockerfiles #3048

Merged
merged 1 commit into from
Jun 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 29 additions & 34 deletions dockers/docker-base-stretch/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %}
FROM debian:stretch

# Clean documentation in FROM image
RUN find /usr/share/doc -depth \( -type f -o -type l \) ! -name copyright | xargs rm || true

# Clean doc directories that are empty or only contain empty directories
RUN while [ -n "$(find /usr/share/doc -depth -type d -empty -print -exec rmdir {} +)" ]; do :; done
RUN rm -rf \
RUN while [ -n "$(find /usr/share/doc -depth -type d -empty -print -exec rmdir {} +)" ]; do :; done && \
rm -rf \
/usr/share/man/* \
/usr/share/groff/* \
/usr/share/info/* \
Expand All @@ -21,28 +22,22 @@ ENV DEBIAN_FRONTEND=noninteractive
COPY ["dpkg_01_drop", "/etc/dpkg/dpkg.cfg.d/01_drop"]
COPY ["sources.list", "/etc/apt/sources.list"]
COPY ["no_install_recommend_suggest", "/etc/apt/apt.conf.d"]
RUN apt-get update

# Pre-install fundamental packages
RUN apt-get -y install \
less \
perl \
procps \
python \
rsyslog \
vim-tiny

COPY ["etc/rsyslog.conf", "/etc/rsyslog.conf"]
COPY ["etc/rsyslog.d/*", "/etc/rsyslog.d/"]
COPY ["root/.vimrc", "/root/.vimrc"]

# Update apt cache and
# pre-install fundamental packages
RUN apt-get update && \
apt-get -y install \
less \
perl \
procps \
python \
rsyslog \
vim-tiny \
# Install dependencies of supervisor
RUN apt-get -y install python-pkg-resources python-meld3

RUN mkdir -p /etc/supervisor
RUN mkdir -p /var/log/supervisor
python-pkg-resources \
python-meld3

COPY ["etc/supervisor/supervisord.conf", "/etc/supervisor/"]
RUN mkdir -p /etc/supervisor /var/log/supervisor

RUN apt-get -y purge \
exim4 \
Expand All @@ -51,29 +46,29 @@ RUN apt-get -y purge \
exim4-daemon-light

{% if docker_base_stretch_debs.strip() -%}
# Copy built Debian packages
{%- for deb in docker_base_stretch_debs.split(' ') %}
COPY debs/{{ deb }} debs/
{%- endfor %}
# Copy locally-built Debian package dependencies
{{ copy_files("debs/", docker_base_stretch_debs.split(' '), "/debs/") }}

# Install built Debian packages and implicitly install their dependencies
{%- for deb in docker_base_stretch_debs.split(' ') %}
RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; }; dpkg_apt debs/{{ deb }}
{%- endfor %}
{{ install_debian_packages(docker_base_stretch_debs.split(' ')) }}
{%- endif %}

{% if docker_base_stretch_dbgs.strip() -%}
# Install common debug-packages
{%- for dbg_pkg in docker_base_stretch_dbgs.split(' ') %}
RUN apt-get -y install {{ dbg_pkg }}
{%- endfor %}
RUN apt-get -y install docker_base_stretch_dbgs.split(' ') | join(' ')
{% else %}
RUN ln /usr/bin/vim.tiny /usr/bin/vim
{%- endif %}

# Clean up apt
# Remove /var/lib/apt/lists/*, could be obsoleted for derived images
RUN apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y
RUN rm -rf /var/lib/apt/lists/*
RUN apt-get clean -y && \
apt-get autoclean -y && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/* /tmp/*

COPY ["etc/rsyslog.conf", "/etc/rsyslog.conf"]
COPY ["etc/rsyslog.d/*", "/etc/rsyslog.d/"]
COPY ["root/.vimrc", "/root/.vimrc"]

RUN rm -rf /tmp/*
COPY ["etc/supervisor/supervisord.conf", "/etc/supervisor/"]
64 changes: 33 additions & 31 deletions dockers/docker-config-engine-stretch/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
{% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %}
FROM docker-base-stretch

## Make apt-get non-interactive
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update

# Dependencies for sonic-cfggen
RUN apt-get install -y python-lxml python-yaml python-bitarray python-pip python-dev python-natsort python-setuptools
RUN apt-get update && \
apt-get install -y \
# Dependencies for sonic-cfggen
python-lxml \
python-yaml \
python-bitarray \
python-pip \
python-dev \
python-natsort \
python-setuptools

RUN pip install --upgrade pip

RUN pip install netaddr ipaddr jinja2 pyangbind==0.5.10
RUN pip install \
netaddr \
ipaddr \
jinja2 \
pyangbind==0.5.10

{% if docker_config_engine_stretch_debs.strip() %}
COPY \
{% for deb in docker_config_engine_stretch_debs.split(' ') -%}
debs/{{ deb }}{{' '}}
{%- endfor -%}
debs/
{%- endif -%}
# Copy locally-built Debian package dependencies
{{ copy_files("debs/", docker_config_engine_stretch_debs.split(' '), "/debs/") }}

{% if docker_config_engine_stretch_debs.strip() %}
RUN dpkg -i \
{% for deb in docker_config_engine_stretch_debs.split(' ') -%}
debs/{{ deb }}{{' '}}
{%- endfor %}
{%- endif -%}
# Install locally-built Debian packages and implicitly install their dependencies
{{ install_debian_packages(docker_config_engine_stretch_debs.split(' ')) }}
{% endif %}

{% if docker_config_engine_stretch_whls.strip() %}
COPY \
{% for whl in docker_config_engine_stretch_whls.split(' ') -%}
python-wheels/{{ whl }}{{' '}}
{%- endfor -%}
python-wheels/
{%- endif -%}
# Copy locally-built Python wheel dependencies
{{ copy_files("python-wheels/", docker_config_engine_stretch_whls.split(' '), "/python-wheels/") }}

{% if docker_config_engine_stretch_whls.strip() %}
RUN pip install \
{% for whl in docker_config_engine_stretch_whls.split(' ') -%}
python-wheels/{{ whl }}{{' '}}
{%- endfor %}
{%- endif -%}
# Install locally-built Python wheel dependencies
{{ install_python_wheels(docker_config_engine_stretch_whls.split(' ')) }}
{% endif %}

## Clean up
RUN apt-get purge -y python-pip python-dev; apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y
RUN rm -rf /debs /python-wheels
RUN apt-get purge -y \
python-pip \
python-dev && \
apt-get clean -y && \
apt-get autoclean -y && \
apt-get autoremove -y && \
rm -rf /debs /python-wheels
20 changes: 8 additions & 12 deletions dockers/docker-database/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %}
FROM docker-config-engine-stretch

ARG docker_container_name
Expand All @@ -11,23 +12,18 @@ RUN apt-get update

{% if docker_database_debs.strip() -%}
# Copy locally-built Debian package dependencies
{%- for deb in docker_database_debs.split(' ') %}
COPY debs/{{ deb }} /debs/
{%- endfor %}
{{ copy_files("debs/", docker_database_debs.split(' '), "/debs/") }}

# Install locally-built Debian packages and implicitly install their dependencies
{%- for deb in docker_database_debs.split(' ') %}
RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; }; dpkg_apt /debs/{{ deb }}
{%- endfor %}
{{ install_debian_packages(docker_database_debs.split(' ')) }}
{%- endif %}

# Clean up
RUN apt-get clean -y
RUN apt-get autoclean -y
RUN apt-get autoremove -y
RUN rm -rf /debs ~/.cache

RUN sed -ri 's/^(save .*$)/# \1/g; \
RUN apt-get clean -y && \
apt-get autoclean -y && \
apt-get autoremove -y && \
rm -rf /debs ~/.cache && \
sed -ri 's/^(save .*$)/# \1/g; \
s/^daemonize yes$/daemonize no/; \
s/^logfile .*$/logfile ""/; \
s/^# syslog-enabled no$/syslog-enabled no/; \
Expand Down
15 changes: 7 additions & 8 deletions dockers/docker-dhcp-relay/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %}
FROM docker-config-engine-stretch

ARG docker_container_name
Expand All @@ -11,19 +12,17 @@ RUN apt-get update

{% if docker_dhcp_relay_debs.strip() -%}
# Copy built Debian packages
{%- for deb in docker_dhcp_relay_debs.split(' ') %}
COPY debs/{{ deb }} debs/
{%- endfor %}
{{ copy_files("debs/", docker_dhcp_relay_debs.split(' '), "/debs/") }}

# Install built Debian packages and implicitly install their dependencies
{%- for deb in docker_dhcp_relay_debs.split(' ') %}
RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; }; dpkg_apt debs/{{ deb }}
{%- endfor %}
{{ install_debian_packages(docker_dhcp_relay_debs.split(' ')) }}
{%- endif %}

# Clean up
RUN apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y
RUN rm -rf /debs
RUN apt-get clean -y && \
apt-get autoclean -y && \
apt-get autoremove -y && \
rm -rf /debs

COPY ["docker_init.sh", "start.sh", "/usr/bin/"]
COPY ["docker-dhcp-relay.supervisord.conf.j2", "wait_for_intf.sh.j2", "/usr/share/sonic/templates/"]
Expand Down
37 changes: 21 additions & 16 deletions dockers/docker-fpm-frr/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %}
FROM docker-config-engine-stretch

ARG docker_container_name
Expand All @@ -10,33 +11,37 @@ RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%s
ENV DEBIAN_FRONTEND=noninteractive

# Update apt's cache of available packages
RUN apt-get update

# Install required packages
RUN apt-get install -y libdbus-1-3 libdaemon0 libjansson4 libc-ares2 iproute2 libpython2.7 libjson-c3 logrotate libunwind8

{% if docker_fpm_frr_debs.strip() -%}
# Copy locally-built Debian package dependencies
{%- for deb in docker_fpm_frr_debs.split(' ') %}
COPY debs/{{ deb }} /debs/
{%- endfor %}
RUN apt-get update && \
apt-get install -y \
libdbus-1-3 \
libdaemon0 \
libjansson4 \
libc-ares2 \
iproute2 \
libpython2.7 \
libjson-c3 \
logrotate \
libunwind8

RUN groupadd -g ${frr_user_gid} frr
RUN useradd -u ${frr_user_uid} -g ${frr_user_gid} -M -s /bin/false frr

{% if docker_fpm_frr_debs.strip() -%}
# Copy locally-built Debian package dependencies
{{ copy_files("debs/", docker_fpm_frr_debs.split(' '), "/debs/") }}

# Install locally-built Debian packages and implicitly install their dependencies
{%- for deb in docker_fpm_frr_debs.split(' ') %}
RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; }; dpkg_apt /debs/{{ deb }}
{%- endfor %}
{{ install_debian_packages(docker_fpm_frr_debs.split(' ')) }}
{%- endif %}

RUN chown -R ${frr_user_uid}:${frr_user_gid} /etc/frr/

# Clean up
RUN apt-get clean -y
RUN apt-get autoclean -y
RUN apt-get autoremove -y
RUN rm -rf /debs ~/.cache
RUN apt-get clean -y && \
apt-get autoclean -y && \
apt-get autoremove -y && \
rm -rf /debs ~/.cache

COPY ["bgpcfgd", "start.sh", "/usr/bin/"]
COPY ["*.j2", "/usr/share/sonic/templates/"]
Expand Down
30 changes: 12 additions & 18 deletions dockers/docker-lldp-sv2/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %}
FROM docker-config-engine-stretch

ARG docker_container_name
Expand All @@ -9,37 +10,30 @@ ENV DEBIAN_FRONTEND=noninteractive
# Update apt's cache of available packages
RUN apt-get update


{% if docker_lldp_sv2_debs.strip() -%}
# Copy locally-built Debian package dependencies
{%- for deb in docker_lldp_sv2_debs.split(' ') %}
COPY debs/{{ deb }} /debs/
{%- endfor %}
{{ copy_files("debs/", docker_lldp_sv2_debs.split(' '), "/debs/") }}

# Install locally-built Debian packages and implicitly install their dependencies
{%- for deb in docker_lldp_sv2_debs.split(' ') %}
RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; }; dpkg_apt /debs/{{ deb }}
{%- endfor %}
{{ install_debian_packages(docker_lldp_sv2_debs.split(' ')) }}
{%- endif %}

{% if docker_lldp_sv2_whls.strip() -%}
# Copy locally-built Python wheel dependencies
{%- for whl in docker_lldp_sv2_whls.split(' ') %}
COPY python-wheels/{{ whl }} /python-wheels/
{%- endfor %}
{{ copy_files("python-wheels/", docker_lldp_sv2_whls.split(' '), "/python-wheels/") }}

# Install locally-built Python wheel dependencies
{%- for whl in docker_lldp_sv2_whls.split(' ') %}
RUN pip install /python-wheels/{{ whl }}
{%- endfor %}
{{ install_python_wheels(docker_lldp_sv2_whls.split(' ')) }}
{% endif %}

# Clean up
RUN apt-get purge -y python-pip
RUN apt-get clean -y
RUN apt-get autoclean -y
RUN apt-get autoremove -y
RUN rm -rf /debs /python-wheels ~/.cache
RUN apt-get purge -y python-pip && \
apt-get clean -y && \
apt-get autoclean -y && \
apt-get autoremove -y && \
rm -rf /debs \
/python-wheels \
~/.cache

COPY ["start.sh", "/usr/bin/"]
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]
Expand Down
Loading