Added Clixon example full system docker container, see [docker/system].
This commit is contained in:
parent
ae8d28fae8
commit
2b596591f1
24 changed files with 439 additions and 124 deletions
74
docker/system/Dockerfile
Normal file
74
docker/system/Dockerfile
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
#
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
#
|
||||
# Copyright (C) 2009-2019 Olof Hagsand and Benny Holmgren
|
||||
#
|
||||
# This file is part of CLIXON
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# the GNU General Public License Version 3 or later (the "GPL"),
|
||||
# in which case the provisions of the GPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of the GPL, and not to allow others to
|
||||
# use your version of this file under the terms of Apache License version 2,
|
||||
# indicate your decision by deleting the provisions above and replace them with
|
||||
# the notice and other provisions required by the GPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the Apache License version 2 or the GPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
#
|
||||
|
||||
FROM olofhagsand/clixon
|
||||
MAINTAINER Olof Hagsand <olof@hagsand.se>
|
||||
|
||||
RUN apt-get update && apt-get install -y nginx
|
||||
RUN apt-get update && apt-get install -y procps curl # ps for debugging
|
||||
|
||||
# The example uses "clicon" group
|
||||
RUN groupadd clicon
|
||||
RUN usermod -a -G clicon www-data
|
||||
|
||||
# Create a directory to hold source-code, dependencies etc
|
||||
RUN mkdir /example
|
||||
WORKDIR /example
|
||||
|
||||
# Clone clixon (again) since example application is there.
|
||||
# Replace this with your application
|
||||
RUN git clone https://github.com/clicon/clixon.git
|
||||
|
||||
# Build clixon
|
||||
WORKDIR /example/clixon
|
||||
RUN ./configure
|
||||
WORKDIR /example/clixon/example
|
||||
RUN make
|
||||
RUN make install
|
||||
RUN install example.xml /usr/local/etc/clixon.xml
|
||||
|
||||
# Copy startscript
|
||||
WORKDIR /
|
||||
COPY startsystem.sh startsystem.sh
|
||||
RUN install startsystem.sh /usr/local/bin/
|
||||
|
||||
# Expose nginx port for restconf
|
||||
EXPOSE 80
|
||||
|
||||
# Log to stderr.
|
||||
CMD /usr/local/bin/startsystem.sh
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
68
docker/system/Makefile.in
Normal file
68
docker/system/Makefile.in
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
#
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
#
|
||||
# Copyright (C) 2009-2019 Olof Hagsand and Benny Holmgren
|
||||
#
|
||||
# This file is part of CLIXON
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# the GNU General Public License Version 3 or later (the "GPL"),
|
||||
# in which case the provisions of the GPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of the GPL, and not to allow others to
|
||||
# use your version of this file under the terms of Apache License version 2,
|
||||
# indicate your decision by deleting the provisions above and replace them with
|
||||
# the notice and other provisions required by the GPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the Apache License version 2 or the GPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
#
|
||||
VPATH = @srcdir@
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
CC = @CC@
|
||||
CFLAGS = @CFLAGS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBS = @LIBS@
|
||||
|
||||
# Example docker image. PLEASE CHANGE THIS IF YOU PUSH
|
||||
IMG_SYSTEM = clixon/clixon-system
|
||||
|
||||
SHELL = /bin/sh
|
||||
|
||||
.PHONY: all clean depend install docker push clixon-system
|
||||
|
||||
all:
|
||||
echo "Run make docker to build docker image"
|
||||
|
||||
clean:
|
||||
|
||||
distclean: clean
|
||||
rm -f Makefile *~ .depend
|
||||
|
||||
docker: Dockerfile
|
||||
sudo docker build -t $(IMG_SYSTEM) . # --no-cache
|
||||
|
||||
push:
|
||||
|
||||
depend:
|
||||
|
||||
install-include:
|
||||
|
||||
install:
|
||||
|
||||
uninstall:
|
||||
|
||||
31
docker/system/README.md
Normal file
31
docker/system/README.md
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# Clixon example container
|
||||
|
||||
This directory show how to build a "monolithic" clixon docker
|
||||
container containing the example application with both restconf,
|
||||
netconf, cli and backend.
|
||||
The directory contains the following files:
|
||||
cleanup.sh kill containers
|
||||
Dockerfile Docker build instructions
|
||||
lib.sh script library functions
|
||||
Makefile.in "make docker" builds the container
|
||||
README.md This file
|
||||
start.sh Start containers
|
||||
startsystem.sh Internal start script copied to inside the container
|
||||
stat.sh Shows container status
|
||||
|
||||
How to build and start the container:
|
||||
```
|
||||
$ make docker
|
||||
$ ./start.sh
|
||||
```
|
||||
|
||||
Once running you can access it as follows:
|
||||
* CLI: `sudo docker exec -it ef62ccfe1782 clixon_cli`
|
||||
* Netconf: `sudo docker exec -it ef62ccfe1782 clixon_netconf`
|
||||
* Restconf: `curl -G http://localhost/restconf`
|
||||
|
||||
To check status and then kill it:
|
||||
```
|
||||
$ ./stat.sh
|
||||
$ ./cleanup.sh
|
||||
```
|
||||
13
docker/system/cleanup.sh
Executable file
13
docker/system/cleanup.sh
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
#!/bin/sh
|
||||
|
||||
# include err(), stat() and other functions
|
||||
. ./lib.sh
|
||||
|
||||
# Kill all controller containers (optionally do `make clean`)
|
||||
echo "You may want run make clean as well"
|
||||
|
||||
kill1 clixon/clixon-system
|
||||
|
||||
|
||||
|
||||
|
||||
38
docker/system/lib.sh
Executable file
38
docker/system/lib.sh
Executable file
|
|
@ -0,0 +1,38 @@
|
|||
#!/bin/sh
|
||||
# Lib functions like err(), stat() and others
|
||||
|
||||
# Error function
|
||||
# usage: err $msg
|
||||
err(){
|
||||
echo "\e[31m\n[Error $1]"
|
||||
echo "\e[0m"
|
||||
exit 1
|
||||
}
|
||||
|
||||
#json field XXX notused?
|
||||
jf(){
|
||||
sed -e 's/[{}]/''/g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | grep key | awk -F : '{gsub(/"/,"",$3); print $3}'
|
||||
}
|
||||
|
||||
# Status function
|
||||
# usage: stat $name
|
||||
stat(){
|
||||
name=$1
|
||||
ps=$(sudo docker ps -f ancestor=$name|tail -n +2|grep $name|awk '{print $1}')
|
||||
if [ -n "$ps" ]; then
|
||||
ip=$(sudo docker inspect -f '{{.NetworkSettings.IPAddress }}' $ps)
|
||||
echo "$name \t$ps $ip"
|
||||
else
|
||||
err "$name failed"
|
||||
fi
|
||||
}
|
||||
|
||||
# Kill function
|
||||
kill1(){
|
||||
name=$1
|
||||
ps=$(sudo docker ps -f ancestor=$name|tail -n +2|grep $name|awk '{print $1}')
|
||||
if [ -n "$ps" ]; then
|
||||
echo -n "$name\t" && sudo docker kill $ps
|
||||
fi
|
||||
}
|
||||
|
||||
55
docker/system/start.sh
Executable file
55
docker/system/start.sh
Executable file
|
|
@ -0,0 +1,55 @@
|
|||
#!/bin/bash
|
||||
# Build grideye containers, start all containers, setup networking
|
||||
# Usage: ./startup.sh
|
||||
# Debug: DBG=1 ./startup.sh
|
||||
# See also cleanup.sh
|
||||
|
||||
>&2 echo "Running script: $0"
|
||||
|
||||
# include err(), stat() and other functions
|
||||
. ./lib.sh
|
||||
|
||||
# Turn on debug in containers (restconf, backend)
|
||||
DBG=${DBG:-1}
|
||||
|
||||
CONFIG0=$(cat <<EOF
|
||||
<config>
|
||||
<CLICON_CONFIGFILE>/usr/local/etc/example.xml</CLICON_CONFIGFILE>
|
||||
<CLICON_FEATURE>*:*</CLICON_FEATURE>
|
||||
<CLICON_YANG_DIR>/usr/local/share/clixon</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_MODULE_MAIN>clixon-example</CLICON_YANG_MODULE_MAIN>
|
||||
<CLICON_CLI_MODE>example</CLICON_CLI_MODE>
|
||||
<CLICON_BACKEND_DIR>/usr/local/lib/example/backend</CLICON_BACKEND_DIR>
|
||||
<CLICON_NETCONF_DIR>/usr/local/lib/example/netconf</CLICON_NETCONF_DIR>
|
||||
<CLICON_RESTCONF_DIR>/usr/local/lib/example/restconf</CLICON_RESTCONF_DIR>
|
||||
<CLICON_CLI_DIR>/usr/local/lib/example/cli</CLICON_CLI_DIR>
|
||||
<CLICON_CLISPEC_DIR>/usr/local/lib/example/clispec</CLICON_CLISPEC_DIR>
|
||||
<CLICON_SOCK>/usr/local/var/example/example.sock</CLICON_SOCK>
|
||||
<CLICON_BACKEND_PIDFILE>/usr/local/var/example/example.pidfile</CLICON_BACKEND_PIDFILE>
|
||||
<CLICON_CLI_GENMODEL_COMPLETION>1</CLICON_CLI_GENMODEL_COMPLETION>
|
||||
<CLICON_CLI_GENMODEL_TYPE>VARS</CLICON_CLI_GENMODEL_TYPE>
|
||||
<CLICON_XMLDB_DIR>/usr/local/var/example</CLICON_XMLDB_DIR>
|
||||
<CLICON_XMLDB_PLUGIN>/usr/local/lib/xmldb/text.so</CLICON_XMLDB_PLUGIN>
|
||||
<CLICON_CLI_LINESCROLLING>0</CLICON_CLI_LINESCROLLING>
|
||||
<CLICON_STARTUP_MODE>init</CLICON_STARTUP_MODE>
|
||||
<CLICON_NACM_MODE>disabled</CLICON_NACM_MODE>
|
||||
</config>
|
||||
EOF
|
||||
)
|
||||
|
||||
CONFIG=${CONFIG:-$CONFIG0}
|
||||
STORE=${STORE:-}
|
||||
|
||||
# Start clixon-example backend
|
||||
# -p 4535 to access via cli from host
|
||||
>&2 echo -n "Starting Backend..."
|
||||
sudo docker run -p 80:80 --rm -e DBG=$DBG -e CONFIG="$CONFIG" -e STORE="$STORE" -td clixon/clixon-system || err "Error starting clixon-system"
|
||||
|
||||
>&2 echo "clixon-system started"
|
||||
|
||||
name=clixon/clixon-system
|
||||
ps=$(sudo docker ps -f ancestor=$name|tail -n +2|grep $name|awk '{print $1}')
|
||||
echo "sudo docker exec -it $ps clixon_cli # example command"
|
||||
|
||||
|
||||
|
||||
65
docker/system/startsystem.sh
Executable file
65
docker/system/startsystem.sh
Executable file
|
|
@ -0,0 +1,65 @@
|
|||
#!/bin/sh
|
||||
# This script is copied into the container on build time and runs
|
||||
# _inside_ the container at start in runtime. It gets environment variables
|
||||
# from the start.sh script.
|
||||
# It starts a backend, a restconf daemon and a nginx daemon and exposes ports
|
||||
# for restconf.
|
||||
# See also Dockerfile of the example
|
||||
# Log msg, see with docker logs
|
||||
|
||||
>&2 echo "$0"
|
||||
|
||||
DBG=${DBG:-0}
|
||||
|
||||
# Initiate clixon configuration (env variable)
|
||||
echo "$CONFIG" > /usr/local/etc/clixon.xml
|
||||
|
||||
# Initiate running db (env variable)
|
||||
echo "$STORE" > /usr/local/var/example/running_db
|
||||
|
||||
>&2 echo "Write nginx config files"
|
||||
# nginx site config file
|
||||
cat <<EOF > /etc/nginx/sites-enabled/default
|
||||
#
|
||||
server {
|
||||
listen 80 default_server;
|
||||
listen localhost:80 default_server;
|
||||
listen [::]:80 default_server;
|
||||
server_name localhost;
|
||||
server_name _;
|
||||
location / {
|
||||
root /usr/share/nginx/html/restconf;
|
||||
fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
|
||||
include fastcgi_params;
|
||||
}
|
||||
location /restconf {
|
||||
fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
|
||||
include fastcgi_params;
|
||||
}
|
||||
location /streams {
|
||||
fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
|
||||
include fastcgi_params;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Connection "";
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# Start nginx
|
||||
#/usr/sbin/nginx -g 'daemon off;' -c /etc/nginx/nginx.conf
|
||||
/usr/sbin/nginx -c /etc/nginx/nginx.conf
|
||||
>&2 echo "nginx started"
|
||||
|
||||
# Start clixon_restconf
|
||||
su -c "/www-data/clixon_restconf -l f/www-data/restconf.log -D $DBG" -s /bin/sh www-data &
|
||||
>&2 echo "clixon_restconf started"
|
||||
|
||||
# Start clixon backend
|
||||
>&2 echo "start clixon_backend:"
|
||||
/usr/local/sbin/clixon_backend -FD $DBG -s running -l e # logs on docker logs
|
||||
|
||||
|
||||
# Start clixon cli in foreground
|
||||
#/usr/local/bin/clixon_cli -D $DBG
|
||||
|
||||
#/bin/sleep 100000000
|
||||
10
docker/system/stat.sh
Executable file
10
docker/system/stat.sh
Executable file
|
|
@ -0,0 +1,10 @@
|
|||
#!/bin/sh
|
||||
# Show stats (IP address etc) about the clixon containers
|
||||
# include err(), stat() and other functions
|
||||
. ./lib.sh
|
||||
|
||||
stat clixon/clixon-system
|
||||
|
||||
name=clixon/clixon-system
|
||||
ps=$(sudo docker ps -f ancestor=$name|tail -n +2|grep $name|awk '{print $1}')
|
||||
echo "sudo docker exec -it $ps clixon_cli # example command"
|
||||
Loading…
Add table
Add a link
Reference in a new issue