From 96a0efef35c599aba658e5006a9a873269c803dc Mon Sep 17 00:00:00 2001 From: Sumukha Tumkur Vani Date: Fri, 3 Jan 2020 10:07:29 -0800 Subject: [PATCH 1/3] Changes to build restapi docker --- .gitmodules | 4 +++ dockers/docker-sonic-restapi/Dockerfile.j2 | 30 +++++++++++++++++++ dockers/docker-sonic-restapi/start.sh | 10 +++++++ dockers/docker-sonic-restapi/supervisord.conf | 12 ++++++++ rules/docker-restapi.mk | 20 +++++++++++++ rules/restapi.mk | 9 ++++++ src/sonic-restapi | 1 + 7 files changed, 86 insertions(+) create mode 100644 dockers/docker-sonic-restapi/Dockerfile.j2 create mode 100755 dockers/docker-sonic-restapi/start.sh create mode 100644 dockers/docker-sonic-restapi/supervisord.conf create mode 100644 rules/docker-restapi.mk create mode 100644 rules/restapi.mk create mode 160000 src/sonic-restapi diff --git a/.gitmodules b/.gitmodules index 0cccf14a8e94..4fd4bd52be6c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -78,3 +78,7 @@ [submodule "src/sonic-ztp"] path = src/sonic-ztp url = https://github.com/Azure/sonic-ztp +[submodule "src/sonic-restapi"] + path = src/sonic-restapi + url = https://github.com/Azure/sonic-restapi.git + branch = master diff --git a/dockers/docker-sonic-restapi/Dockerfile.j2 b/dockers/docker-sonic-restapi/Dockerfile.j2 new file mode 100644 index 000000000000..5646e653fb69 --- /dev/null +++ b/dockers/docker-sonic-restapi/Dockerfile.j2 @@ -0,0 +1,30 @@ +{% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %} +FROM docker-config-engine-stretch + +ARG docker_container_name +RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%syslogtag%/;" /etc/rsyslog.conf + +## Make apt-get non-interactive +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update + +## Install redis-tools dependencies +## TODO: implicitly install dependencies +RUN apt-get -y install libjemalloc1 +RUN pip install setuptools + +{% if docker_sonic_restapi_debs.strip() -%} +# Copy locally-built Debian package dependencies +{{ copy_files("debs/", docker_sonic_restapi_debs.split(' '), "/debs/") }} + +# Install locally-built Debian packages and implicitly install their dependencies +{{ install_debian_packages( docker_sonic_restapi_debs.split(' ')) }} +{%- endif %} + +## Clean up +RUN apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y + +COPY ["supervisord.conf", "/etc/supervisor/conf.d/"] + +ENTRYPOINT ["/usr/bin/supervisord"] diff --git a/dockers/docker-sonic-restapi/start.sh b/dockers/docker-sonic-restapi/start.sh new file mode 100755 index 000000000000..015d246d1200 --- /dev/null +++ b/dockers/docker-sonic-restapi/start.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +mkdir -p /var/sonic +echo "# Config files managed by sonic-config-engine" > /var/sonic/config_status + +rm -f /var/run/rsyslogd.pid + +supervisorctl start rsyslogd + +supervisorctl start restapi diff --git a/dockers/docker-sonic-restapi/supervisord.conf b/dockers/docker-sonic-restapi/supervisord.conf new file mode 100644 index 000000000000..284c8aef423b --- /dev/null +++ b/dockers/docker-sonic-restapi/supervisord.conf @@ -0,0 +1,12 @@ +[supervisord] +logfile_maxbytes=1MB +logfile_backups=2 +nodaemon=true + +[program:restapi] +command=/usr/sbin/go-server-server -loglevel trace +priority=1 +autostart=true +autorestart=false +stdout_logfile=/tmp/rest-api.out.log +stderr_logfile=/tmp/rest-api.err.log diff --git a/rules/docker-restapi.mk b/rules/docker-restapi.mk new file mode 100644 index 000000000000..66d60205915a --- /dev/null +++ b/rules/docker-restapi.mk @@ -0,0 +1,20 @@ +# docker image for rest-api + +DOCKER_RESTAPI_STEM = docker-sonic-restapi +DOCKER_RESTAPI = $(DOCKER_RESTAPI_STEM).gz + +$(DOCKER_RESTAPI)_DEPENDS += $(LIBHIREDIS) $(LIBNL3) $(LIBNL_GENL3) \ + $(LIBNL_ROUTE3) $(LIBSWSSCOMMON) $(RESTAPI) + +$(DOCKER_RESTAPI)_PATH = $(DOCKERS_PATH)/$(DOCKER_RESTAPI_STEM) + +$(DOCKER_RESTAPI)_LOAD_DOCKERS += $(DOCKER_CONFIG_ENGINE_STRETCH) + +SONIC_DOCKER_IMAGES += $(DOCKER_RESTAPI) +SONIC_STRETCH_DOCKERS += $(DOCKER_RESTAPI) +SONIC_INSTALL_DOCKER_IMAGES += $(DOCKER_RESTAPI) + +$(DOCKER_RESTAPI)_CONTAINER_NAME = rest-api +$(DOCKER_RESTAPI)_RUN_OPT += --cap-add NET_ADMIN --privileged -t +$(DOCKER_RESTAPI)_RUN_OPT += -v /var/run/redis/redis.sock:/var/run/redis/redis.sock +$(DOCKER_RESTAPI)_RUN_OPT += -p=8090:8090/tcp diff --git a/rules/restapi.mk b/rules/restapi.mk new file mode 100644 index 000000000000..e66b4a1d976a --- /dev/null +++ b/rules/restapi.mk @@ -0,0 +1,9 @@ +# sonic-rest-api package + +RESTAPI = sonic-rest-api_1.0.1_amd64.deb +$(RESTAPI)_SRC_PATH = $(SRC_PATH)/sonic-restapi +$(RESTAPI)_DEPENDS += $(LIBHIREDIS_DEV) $(LIBNL3_DEV) $(LIBNL_GENL3_DEV) \ + $(LIBNL_ROUTE3_DEV) $(LIBSWSSCOMMON_DEV) $(LIBSWSSCOMMON) +$(RESTAPI)_RDEPENDS += $(LIBHIREDIS) $(LIBNL3) $(LIBNL_GENL3) \ + $(LIBNL_ROUTE3) $(LIBSWSSCOMMON) +SONIC_DPKG_DEBS += $(RESTAPI) diff --git a/src/sonic-restapi b/src/sonic-restapi new file mode 160000 index 000000000000..124efcad08ed --- /dev/null +++ b/src/sonic-restapi @@ -0,0 +1 @@ +Subproject commit 124efcad08ed0c58a0c1942d181728b163cbe7a6 From 19e2ff012ee4fb884bfe8ca862651590f2e432b1 Mon Sep 17 00:00:00 2001 From: Sumukha Tumkur Vani Date: Thu, 9 Jan 2020 14:19:06 -0800 Subject: [PATCH 2/3] Update submodule to the latest hash --- src/sonic-restapi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-restapi b/src/sonic-restapi index 124efcad08ed..163ee272ae99 160000 --- a/src/sonic-restapi +++ b/src/sonic-restapi @@ -1 +1 @@ -Subproject commit 124efcad08ed0c58a0c1942d181728b163cbe7a6 +Subproject commit 163ee272ae992f5885990dcca6552cd86b74391a From 95a3966816164e34f1f355633f08ce7e16dfefad Mon Sep 17 00:00:00 2001 From: Sumukha Tumkur Vani Date: Fri, 10 Jan 2020 10:24:51 -0800 Subject: [PATCH 3/3] Remove setuptools and libjemalloc1 --- dockers/docker-sonic-restapi/Dockerfile.j2 | 5 ----- 1 file changed, 5 deletions(-) diff --git a/dockers/docker-sonic-restapi/Dockerfile.j2 b/dockers/docker-sonic-restapi/Dockerfile.j2 index 5646e653fb69..de8080880fc7 100644 --- a/dockers/docker-sonic-restapi/Dockerfile.j2 +++ b/dockers/docker-sonic-restapi/Dockerfile.j2 @@ -9,11 +9,6 @@ ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update -## Install redis-tools dependencies -## TODO: implicitly install dependencies -RUN apt-get -y install libjemalloc1 -RUN pip install setuptools - {% if docker_sonic_restapi_debs.strip() -%} # Copy locally-built Debian package dependencies {{ copy_files("debs/", docker_sonic_restapi_debs.split(' '), "/debs/") }}