Added docker/base as minimal clixon container and docker/system as full clixon system.

This commit is contained in:
Olof Hagsand 2019-02-11 14:17:29 +01:00
parent 7e38dc57e3
commit 66d8573c00
23 changed files with 222 additions and 138 deletions

View file

@ -31,34 +31,57 @@
# ***** END LICENSE BLOCK *****
#
FROM olofhagsand/clixon
# This application could use the base image, but it does not at this point.
#FROM olofhagsand/clixon
FROM debian
MAINTAINER Olof Hagsand <olof@hagsand.se>
# Clixon dependenies (not needed if build from base)
RUN apt-get update && apt-get install -y \
git make gcc flex bison \
libfcgi-dev \
libcurl4-openssl-dev
# Application-specific
RUN apt-get update && apt-get install -y nginx
RUN apt-get update && apt-get install -y procps curl # ps for debugging
# Test-specific
RUN apt-get update && apt-get install -y sudo curl procps # for test scripts
# 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
RUN mkdir /clixon
WORKDIR /clixon
# 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
# Clone and build cligen (not necessary if use base image)
RUN git clone https://github.com/olofhagsand/cligen.git
WORKDIR /clixon/cligen
RUN ./configure
WORKDIR /example/clixon/example
RUN make
RUN make install
# Copy Clixon from local dir
RUN mkdir /clixon/clixon
WORKDIR /clixon/clixon
COPY clixon .
RUN ./configure
RUN make
RUN make install
RUN make install-include
WORKDIR /clixon/clixon/example
RUN make
RUN make install
RUN install example.xml /usr/local/etc/clixon.xml
RUN ldconfig
# Copy startscript
WORKDIR /
WORKDIR /clixon
COPY startsystem.sh startsystem.sh
RUN install startsystem.sh /usr/local/bin/

View file

@ -39,7 +39,7 @@ LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
# Example docker image. PLEASE CHANGE THIS IF YOU PUSH
IMG_SYSTEM = clixon/clixon-system
IMG = clixon/clixon-system
SHELL = /bin/sh
@ -48,13 +48,18 @@ SHELL = /bin/sh
all:
echo "Run make docker to build docker image"
# (recursively) clone the repo from top-level - NOTE changes must be committed
clixon:
git clone file://$(realpath ${top_srcdir})
clean:
rm -rf clixon # clone of top-srcdir
distclean: clean
rm -f Makefile *~ .depend
docker: Dockerfile
sudo docker build -t $(IMG_SYSTEM) . # --no-cache
docker: clixon Dockerfile
sudo docker build -t $(IMG) . # --no-cache
push:

View file

@ -1,31 +1,50 @@
# 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.
container exporting port 80 and contains the example application with
both restconf, netconf, cli and backend.
Note that the container is built from scratch instead of using the
base image. And it differs from the base image in that it builds the
code from the local git locally (regardless of status and branch)
wheras the base image pulls from remote github master branch.
Note that it could use the base image, and may in the future, see
comments in the Dockerfile.
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
startsystem.sh Internal start script copied to inside the container (dont run from shell)
How to build and start the container:
How to build and start the container (called clixon-system):
```
$ make docker
$ ./start.sh
```
The start.sh has a number of environment variables to alter the default behaviour:
* PORT - Nginx exposes port 80 per default. Set `PORT=8080` for example to access restconf using 8080.
* DBG - Set debug. The clixon_backend will be shown on docker logs.
* CONFIG - Set XML configuration file other than the default example.
* STORE - Set running datastore content to other than default.
Example:
```
$ DBG=1 PORT=8080 ./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`
* CLI: `sudo docker exec -it clixon-system clixon_cli`
* Netconf: `sudo docker exec -it clixon-system clixon_netconf`
* Restconf: `curl -G http://localhost/restconf`
* Run tests: `sudo docker exec -it clixon-system bash -c 'cd /clixon/clixon/test; exec ./all.sh'`
To check status and then kill it:
```
$ ./stat.sh
$ sudo docker ps --all
$ ./cleanup.sh
```
```

View file

@ -1,13 +1,7 @@
#!/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
sudo docker kill clixon-system

View file

@ -1,38 +0,0 @@
#!/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
}

View file

@ -6,11 +6,24 @@
>&2 echo "Running script: $0"
# include err(), stat() and other functions
. ./lib.sh
pwd
# Error function
# usage: err $msg
err(){
echo "\e[31m\n[Error $1]"
echo "\e[0m"
exit 1
}
# Turn on debug in containers (restconf, backend)
DBG=${DBG:-1}
DBG=${DBG:-0}
# Expose other host port than port 80
PORT=${PORT:-80}
# Initial running datastore content (other than empty)
STORE=${STORE:-}
CONFIG0=$(cat <<EOF
<config>
@ -38,18 +51,14 @@ 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"
sudo docker run -p $PORT:80 --name clixon-system --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"

View file

@ -45,6 +45,15 @@ server {
}
EOF
# This is a clixon site test file. Disable all model testing.
cat <<EOF > /clixon/clixon/test/site.sh
# Add your local site specific env variables (or tests) here.
MODELS=0 # Dont run yangmodels/openconfig tests
IETFRFC=/clixon/clixon/yang/standard
EOF
# Start nginx
#/usr/sbin/nginx -g 'daemon off;' -c /etc/nginx/nginx.conf
/usr/sbin/nginx -c /etc/nginx/nginx.conf
@ -58,8 +67,6 @@ su -c "/www-data/clixon_restconf -l f/www-data/restconf.log -D $DBG" -s /bin/sh
>&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
# Alt: let backend be in foreground, but test scripts may
# want to restart backend
/bin/sleep 100000000

View file

@ -1,10 +0,0 @@
#!/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"