From 4eb9d9d3a58959f12273cb000d2ebac822506c08 Mon Sep 17 00:00:00 2001 From: marian-pritsak Date: Thu, 22 Dec 2016 14:28:29 +0200 Subject: [PATCH] [docker]: Change templating method to jinja2 (#115) Move from sed to jinja2 for more readability. --- .../{Dockerfile.template => Dockerfile.j2} | 9 ++++++--- .../docker-fpm/{Dockerfile.template => Dockerfile.j2} | 9 ++++++--- .../{Dockerfile.template => Dockerfile.j2} | 9 ++++++--- .../{Dockerfile.template => Dockerfile.j2} | 9 ++++++--- .../{Dockerfile.template => Dockerfile.j2} | 9 ++++++--- .../{Dockerfile.template => Dockerfile.j2} | 9 ++++++--- .../{Dockerfile.template => Dockerfile.j2} | 11 +++++++---- .../{Dockerfile.template => Dockerfile.j2} | 11 +++++++---- .../{Dockerfile.template => Dockerfile.j2} | 9 ++++++--- slave.mk | 10 ++++++---- 10 files changed, 62 insertions(+), 33 deletions(-) rename dockers/docker-database/{Dockerfile.template => Dockerfile.j2} (83%) rename dockers/docker-fpm/{Dockerfile.template => Dockerfile.j2} (67%) rename dockers/docker-lldp-sv2/{Dockerfile.template => Dockerfile.j2} (81%) rename dockers/docker-orchagent/{Dockerfile.template => Dockerfile.j2} (74%) rename dockers/docker-snmp-sv2/{Dockerfile.template => Dockerfile.j2} (92%) rename dockers/docker-team/{Dockerfile.template => Dockerfile.j2} (66%) rename platform/broadcom/docker-syncd-brcm/{Dockerfile.template => Dockerfile.j2} (53%) rename platform/mellanox/docker-syncd-mlnx/{Dockerfile.template => Dockerfile.j2} (61%) rename platform/p4/docker-sonic-p4/{Dockerfile.template => Dockerfile.j2} (87%) diff --git a/dockers/docker-database/Dockerfile.template b/dockers/docker-database/Dockerfile.j2 similarity index 83% rename from dockers/docker-database/Dockerfile.template rename to dockers/docker-database/Dockerfile.j2 index 5d26946acf0a..cc8cd9bb206a 100644 --- a/dockers/docker-database/Dockerfile.template +++ b/dockers/docker-database/Dockerfile.j2 @@ -2,17 +2,20 @@ FROM docker-base RUN apt-get update -COPY deps/ deps +COPY debs/ debs ## Install redis-tools dependencies ## TODO: implicitly install dependencies RUN apt-get -y install libjemalloc1 -SED_DPKG +RUN dpkg -i \ +{% for deb in docker_database_debs.split(' ') -%} +debs/{{ deb }}{{' '}} +{%- endfor %} ## Clean up RUN apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y -RUN rm -rf /deps +RUN rm -rf /debs RUN sed -ri 's/^daemonize yes$/daemonize no/; \ s/^logfile .*$/logfile ""/; \ diff --git a/dockers/docker-fpm/Dockerfile.template b/dockers/docker-fpm/Dockerfile.j2 similarity index 67% rename from dockers/docker-fpm/Dockerfile.template rename to dockers/docker-fpm/Dockerfile.j2 index 47d250fb15fb..3007d8e1e53c 100644 --- a/dockers/docker-fpm/Dockerfile.template +++ b/dockers/docker-fpm/Dockerfile.j2 @@ -4,13 +4,16 @@ RUN apt-get update RUN apt-get install -y libdbus-1-3 libdaemon0 libjansson4 -COPY deps/ deps +COPY debs/ debs -SED_DPKG +RUN dpkg -i \ +{% for deb in docker_fpm_debs.split(' ') -%} +debs/{{ deb }}{{' '}} +{%- endfor %} ## Clean up RUN apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y -RUN rm -rf /deps +RUN rm -rf /debs COPY ["start.sh", "/usr/bin/"] diff --git a/dockers/docker-lldp-sv2/Dockerfile.template b/dockers/docker-lldp-sv2/Dockerfile.j2 similarity index 81% rename from dockers/docker-lldp-sv2/Dockerfile.template rename to dockers/docker-lldp-sv2/Dockerfile.j2 index da1717f81918..833e4673733e 100644 --- a/dockers/docker-lldp-sv2/Dockerfile.template +++ b/dockers/docker-lldp-sv2/Dockerfile.j2 @@ -1,6 +1,6 @@ FROM docker-base -COPY deps /deps +COPY debs /debs COPY python-wheels /python-wheels RUN apt-get update && apt-get install -y python-pip supervisor libbsd0 libevent-2.0-5 libjansson4 libwrap0 libxml2 libpci3 libperl5.20 @@ -9,13 +9,16 @@ RUN apt-get update && apt-get install -y python-pip supervisor libbsd0 libevent- ## Install Python SSWSDK ## Install LLDP Sync Daemon -SED_DPKG +RUN dpkg -i \ +{% for deb in docker_lldp_sv2_debs.split(' ') -%} +debs/{{ deb }}{{' '}} +{%- endfor %} RUN pip install /python-wheels/sswsdk-2.0.1-py2-none-any.whl && \ pip install /python-wheels/sonic_d-2.0.0-py2-none-any.whl && \ apt-get remove -y python-pip && \ apt-get purge -y && apt-get autoclean -y && apt-get autoremove -y && \ - rm -rf /deps /python-wheels ~/.cache + rm -rf /debs /python-wheels ~/.cache COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf COPY reconfigure.sh /opt/reconfigure.sh diff --git a/dockers/docker-orchagent/Dockerfile.template b/dockers/docker-orchagent/Dockerfile.j2 similarity index 74% rename from dockers/docker-orchagent/Dockerfile.template rename to dockers/docker-orchagent/Dockerfile.j2 index c8c858bf2c2c..8b82102993dc 100755 --- a/dockers/docker-orchagent/Dockerfile.template +++ b/dockers/docker-orchagent/Dockerfile.j2 @@ -8,15 +8,18 @@ RUN apt-get install -f -y ifupdown bridge-utils libdbus-1-3 libdaemon0 libjansso ## TODO: implicitly install dependencies RUN apt-get -y install libjemalloc1 -COPY deps /deps +COPY debs /debs -SED_DPKG +RUN dpkg -i \ +{% for deb in docker_orchagent_debs.split(' ') -%} +debs/{{ deb }}{{' '}} +{%- endfor %} COPY start.sh /usr/bin/start.sh ## Clean up RUN apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y -RUN rm -rf /deps +RUN rm -rf /debs ENTRYPOINT ["/bin/bash"] CMD ["/usr/bin/start.sh"] diff --git a/dockers/docker-snmp-sv2/Dockerfile.template b/dockers/docker-snmp-sv2/Dockerfile.j2 similarity index 92% rename from dockers/docker-snmp-sv2/Dockerfile.template rename to dockers/docker-snmp-sv2/Dockerfile.j2 index 876a7aca3445..9d8c068064c5 100644 --- a/dockers/docker-snmp-sv2/Dockerfile.template +++ b/dockers/docker-snmp-sv2/Dockerfile.j2 @@ -1,6 +1,6 @@ FROM docker-base -COPY deps /deps +COPY debs /debs COPY python-wheels /python-wheels # enable -O for all Python calls @@ -12,9 +12,12 @@ ENV PYTHONOPTIMIZE 1 ## Clean up RUN apt-get update && apt-get install -y libmysqlclient-dev libmysqld-dev libperl-dev libpci-dev libpci3 libsensors4 libsensors4-dev libwrap0-dev -SED_DPKG +RUN dpkg -i \ +{% for deb in docker_snmp_sv2_debs.split(' ') -%} +debs/{{ deb }}{{' '}} +{%- endfor %} -RUN rm -rf /deps +RUN rm -rf /debs # install subagent RUN apt-get -y install build-essential wget libssl-dev openssl supervisor && \ diff --git a/dockers/docker-team/Dockerfile.template b/dockers/docker-team/Dockerfile.j2 similarity index 66% rename from dockers/docker-team/Dockerfile.template rename to dockers/docker-team/Dockerfile.j2 index 487ff3d0434e..27c5704234ea 100644 --- a/dockers/docker-team/Dockerfile.template +++ b/dockers/docker-team/Dockerfile.j2 @@ -2,14 +2,17 @@ FROM docker-base RUN apt-get update && apt-get install -f -y libdbus-1-3 libdaemon0 libjansson4 -COPY deps /deps +COPY debs /debs -SED_DPKG +RUN dpkg -i \ +{% for deb in docker_team_debs.split(' ') -%} +debs/{{ deb }}{{' '}} +{%- endfor %} COPY start.sh /usr/bin/start.sh RUN apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y -RUN rm -rf /deps +RUN rm -rf /debs ENTRYPOINT ["/bin/bash"] CMD ["/usr/bin/start.sh"] diff --git a/platform/broadcom/docker-syncd-brcm/Dockerfile.template b/platform/broadcom/docker-syncd-brcm/Dockerfile.j2 similarity index 53% rename from platform/broadcom/docker-syncd-brcm/Dockerfile.template rename to platform/broadcom/docker-syncd-brcm/Dockerfile.j2 index 958c0757b283..163e664f0dec 100755 --- a/platform/broadcom/docker-syncd-brcm/Dockerfile.template +++ b/platform/broadcom/docker-syncd-brcm/Dockerfile.j2 @@ -2,18 +2,21 @@ FROM docker-base RUN apt-get update -COPY deps /deps +COPY debs /debs -SED_DPKG +RUN dpkg -i \ +{% for deb in docker_syncd_brcm_debs.split(' ') -%} +debs/{{ deb }}{{' '}} +{%- endfor %} ## TODO: add kmod into Depends RUN apt-get install -f kmod -COPY ["deps/dsserve", "deps/bcmcmd", "start.sh", "/usr/bin/"] +COPY ["debs/dsserve", "debs/bcmcmd", "start.sh", "/usr/bin/"] ## Clean up RUN apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y -RUN rm -rf /deps +RUN rm -rf /debs ENTRYPOINT ["/bin/bash"] CMD ["/usr/bin/start.sh"] diff --git a/platform/mellanox/docker-syncd-mlnx/Dockerfile.template b/platform/mellanox/docker-syncd-mlnx/Dockerfile.j2 similarity index 61% rename from platform/mellanox/docker-syncd-mlnx/Dockerfile.template rename to platform/mellanox/docker-syncd-mlnx/Dockerfile.j2 index d71245dcd8e3..b5a58b0a0577 100755 --- a/platform/mellanox/docker-syncd-mlnx/Dockerfile.template +++ b/platform/mellanox/docker-syncd-mlnx/Dockerfile.j2 @@ -2,19 +2,22 @@ FROM docker-base RUN apt-get update -COPY deps /deps +COPY debs /debs RUN apt-get install -y libxml2 -SED_DPKG +RUN dpkg -i \ +{% for deb in docker_syncd_mlnx_debs.split(' ') -%} +debs/{{ deb }}{{' '}} +{%- endfor %} COPY ["start.sh", "/usr/bin/"] COPY ["mlnx-fw-upgrade.sh", "/usr/bin/"] -COPY ["/deps/fw-SPC.mfa", "/etc/mlnx/"] +COPY ["/debs/fw-SPC.mfa", "/etc/mlnx/"] ## Clean up RUN apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y -RUN rm -rf /deps +RUN rm -rf /debs ENTRYPOINT ["/bin/bash"] CMD ["/usr/bin/start.sh"] diff --git a/platform/p4/docker-sonic-p4/Dockerfile.template b/platform/p4/docker-sonic-p4/Dockerfile.j2 similarity index 87% rename from platform/p4/docker-sonic-p4/Dockerfile.template rename to platform/p4/docker-sonic-p4/Dockerfile.j2 index 357548591d1a..3cf775ea97f6 100644 --- a/platform/p4/docker-sonic-p4/Dockerfile.template +++ b/platform/p4/docker-sonic-p4/Dockerfile.j2 @@ -4,9 +4,12 @@ RUN apt-get update RUN apt-get install -y net-tools ethtool tcpdump ifupdown bridge-utils python-ply libqt5core5a libqt5network5 libboost-program-options1.55.0 libboost-system1.55.0 libboost-thread1.55.0 libgmp10 libjudydebian1 libnanomsg0 libdaemon0 libjansson4 libjemalloc1 -COPY deps /deps +COPY debs /debs -SED_DPKG +RUN dpkg -i \ +{% for deb in docker_sonic_p4_debs.split(' ') -%} +debs/{{ deb }}{{' '}} +{%- endfor %} ADD port_config.ini /port_config.ini ADD startup.sh /scripts/startup.sh @@ -15,7 +18,7 @@ ADD rsyslog.conf /etc/rsyslog.conf ## Clean up RUN apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y -RUN rm -rf /deps +RUN rm -rf /debs RUN sed -ri 's/^daemonize yes$/daemonize no/; \ s/^logfile .*$/logfile ""/; \ diff --git a/slave.mk b/slave.mk index cb7cc0371583..29b445f08d82 100644 --- a/slave.mk +++ b/slave.mk @@ -249,13 +249,15 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_SIMPLE_DOCKER_IMAGES)) : $(TARGET_PATH)/%.g $(FOOTER) # Targets for building docker images -$(addprefix $(TARGET_PATH)/, $(SONIC_DOCKER_IMAGES)) : $(TARGET_PATH)/%.gz : .platform docker-start $$(addprefix $(DEBS_PATH)/,$$($$*.gz_DEPENDS) $$($$*.gz_FILES)) $$(addprefix $(PYTHON_WHEELS_PATH)/,$$($$*.gz_PYTHON_WHEELS)) $$(addsuffix -load,$$(addprefix $(TARGET_PATH)/,$$($$*.gz_LOAD_DOCKERS))) +$(addprefix $(TARGET_PATH)/, $(SONIC_DOCKER_IMAGES)) : $(TARGET_PATH)/%.gz : .platform docker-start $$(addprefix $(DEBS_PATH)/,$$($$*.gz_DEPENDS) $$($$*.gz_FILES)) $$(addprefix $(PYTHON_WHEELS_PATH)/,$$($$*.gz_PYTHON_WHEELS)) $$(addsuffix -load,$$(addprefix $(TARGET_PATH)/,$$($$*.gz_LOAD_DOCKERS))) $$($$*.gz_PATH)/Dockerfile.j2 $(HEADER) - mkdir -p $($*.gz_PATH)/deps $(LOG) + mkdir -p $($*.gz_PATH)/debs $(LOG) mkdir -p $($*.gz_PATH)/python-wheels $(LOG) - sudo mount --bind $(DEBS_PATH) $($*.gz_PATH)/deps $(LOG) + sudo mount --bind $(DEBS_PATH) $($*.gz_PATH)/debs $(LOG) sudo mount --bind $(PYTHON_WHEELS_PATH) $($*.gz_PATH)/python-wheels $(LOG) - sed 's/SED_DPKG/RUN cd deps \&\& dpkg -i $(shell printf "$(subst $(SPACE),\n,$(call expand,$($*.gz_DEPENDS),RDEPENDS))\n" | awk '!a[$$0]++')/g' $($*.gz_PATH)/Dockerfile.template > $($*.gz_PATH)/Dockerfile + # Export variables for j2. Use path for unique variable names, e.g. docker_orchagent_debs + $(eval export $(subst -,_,$(notdir $($*.gz_PATH)))_debs=$(shell printf "$(subst $(SPACE),\n,$(call expand,$($*.gz_DEPENDS),RDEPENDS))\n" | awk '!a[$$0]++')) + j2 $($*.gz_PATH)/Dockerfile.j2 > $($*.gz_PATH)/Dockerfile docker build --no-cache -t $* $($*.gz_PATH) $(LOG) docker save $* | gzip -c > $@ $(FOOTER)