Skip to content

Commit

Permalink
[docker]: Change templating method to jinja2 (#115)
Browse files Browse the repository at this point in the history
Move from sed to jinja2 for more readability.
  • Loading branch information
marian-pritsak committed Dec 23, 2016
1 parent a11593a commit 4eb9d9d
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""/; \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/"]

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM docker-base

COPY deps /deps
COPY debs /debs
COPY python-wheels /python-wheels

# enable -O for all Python calls
Expand All @@ -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 && \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ""/; \
Expand Down
10 changes: 6 additions & 4 deletions slave.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4eb9d9d

Please sign in to comment.