* A new "hello world" example is added
* The directory `docker/system` has been moved to `docker/main`
This commit is contained in:
parent
d46ca41c8b
commit
14d319dd9b
21 changed files with 382 additions and 11 deletions
124
docker/main/Dockerfile
Normal file
124
docker/main/Dockerfile
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
#
|
||||
# ***** 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 alpine
|
||||
MAINTAINER Olof Hagsand <olof@hagsand.se>
|
||||
|
||||
# For clixon and cligen
|
||||
RUN apk add --update git make build-base gcc flex bison fcgi-dev curl-dev
|
||||
|
||||
# Create a directory to hold source-code, dependencies etc
|
||||
RUN mkdir /clixon
|
||||
RUN mkdir /clixon/build
|
||||
WORKDIR /clixon
|
||||
|
||||
# Clone cligen
|
||||
RUN git clone https://github.com/olofhagsand/cligen.git
|
||||
|
||||
# Build cligen
|
||||
WORKDIR /clixon/cligen
|
||||
RUN ./configure --prefix=/clixon/build
|
||||
RUN make
|
||||
RUN make install
|
||||
|
||||
# Copy Clixon from local dir
|
||||
RUN mkdir /clixon/clixon
|
||||
WORKDIR /clixon/clixon
|
||||
COPY clixon .
|
||||
|
||||
# Need to add www user manually
|
||||
RUN adduser -D -H www-data
|
||||
# nginx adds group www-data
|
||||
RUN apk add --update nginx
|
||||
|
||||
# Configure, build and install clixon
|
||||
RUN ./configure --prefix=/clixon/build --with-cligen=/clixon/build --with-wwwuser=www-data
|
||||
RUN make
|
||||
RUN make install
|
||||
RUN make install-include
|
||||
|
||||
# Install utils
|
||||
WORKDIR /clixon/clixon/util
|
||||
RUN make
|
||||
RUN make install
|
||||
|
||||
# Build and install the clixon example
|
||||
WORKDIR /clixon/clixon/example/main
|
||||
RUN make
|
||||
RUN make install
|
||||
RUN install example.xml /clixon/build/etc/clixon.xml
|
||||
|
||||
# Copy tests
|
||||
WORKDIR /clixon/clixon/test
|
||||
RUN install -d /clixon/build/bin/test
|
||||
RUN install *.sh /clixon/build/bin/test
|
||||
|
||||
# Copy startscript
|
||||
WORKDIR /clixon
|
||||
COPY startsystem.sh startsystem.sh
|
||||
RUN install startsystem.sh /clixon/build/bin/
|
||||
|
||||
#
|
||||
# Stage 2
|
||||
#
|
||||
FROM alpine
|
||||
MAINTAINER Olof Hagsand <olof@hagsand.se>
|
||||
|
||||
# For clixon and cligen
|
||||
RUN apk add --update flex bison fcgi-dev
|
||||
|
||||
# need to add www user manually
|
||||
RUN adduser -D -H www-data
|
||||
# nginx adds group www-data
|
||||
RUN apk add --update nginx
|
||||
|
||||
# Test-specific (for test scripts)
|
||||
RUN apk add --update sudo curl procps grep make bash
|
||||
|
||||
# Expose nginx port for restconf
|
||||
EXPOSE 80
|
||||
|
||||
# Create clicon group
|
||||
RUN addgroup clicon
|
||||
RUN adduser nginx clicon
|
||||
RUN adduser www-data clicon
|
||||
|
||||
COPY --from=0 /clixon/build/ /usr/local/
|
||||
COPY --from=0 /www-data /www-data
|
||||
|
||||
# Manually created
|
||||
RUN chown www-data /www-data
|
||||
RUN chgrp www-data /www-data
|
||||
|
||||
# Log to stderr.
|
||||
CMD /usr/local/bin/startsystem.sh
|
||||
79
docker/main/Makefile.in
Normal file
79
docker/main/Makefile.in
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
#
|
||||
# ***** 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. CHANGE THIS IF YOU PUSH
|
||||
IMG = clixon/clixon-system
|
||||
|
||||
SHELL = /bin/sh
|
||||
|
||||
.PHONY: all clean distclean docker test push depend install-include install uninstall
|
||||
|
||||
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: clixon Dockerfile
|
||||
sudo docker build -t $(IMG) . # --no-cache
|
||||
|
||||
push:
|
||||
sudo docker push $(IMG)
|
||||
|
||||
# Start the clixon system container and run the test script
|
||||
test: docker
|
||||
./cleanup.sh ; PORT=8080 ./start.sh # kill (ignore error) and the start it
|
||||
sudo docker exec -it clixon-system bash -c 'cd /usr/local/bin/test && ./all.sh'
|
||||
|
||||
depend:
|
||||
|
||||
install-include:
|
||||
|
||||
install:
|
||||
|
||||
uninstall:
|
||||
|
||||
63
docker/main/README.md
Normal file
63
docker/main/README.md
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
# Clixon example test container
|
||||
|
||||
This directory show how to build a "monolithic" clixon docker
|
||||
container exporting port 80 and contains the example application with
|
||||
both restconf, netconf, cli and backend. It also includes packages to be able to run the [Clixon tests](../../test).
|
||||
|
||||
The directory contains the following files:
|
||||
cleanup.sh kill containers
|
||||
Dockerfile Docker build instructions
|
||||
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 (dont run from shell)
|
||||
|
||||
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 in different ways as follows:
|
||||
As CLI:
|
||||
```
|
||||
$ sudo docker exec -it clixon-system clixon_cli
|
||||
```
|
||||
As netconf via stdin/stdout:
|
||||
```
|
||||
$ sudo docker exec -it clixon-system clixon_netconf
|
||||
```
|
||||
As restconf using curl on exposed port 80:
|
||||
```
|
||||
$ curl -G http://localhost/restconf
|
||||
```
|
||||
Or run tests:
|
||||
```
|
||||
$ sudo docker exec -it clixon-system bash -c 'cd /usr/local/bin/test && ./all.sh'
|
||||
```
|
||||
|
||||
To check status and then kill it:
|
||||
```
|
||||
$ sudo docker ps --all
|
||||
$ ./cleanup.sh
|
||||
```
|
||||
|
||||
You trigger the test scripts inside the container using `make test`.
|
||||
|
||||
## Changing code
|
||||
|
||||
If you want to edit clixon code so it runs in the container?
|
||||
You either
|
||||
(1) "persistent": make your changes in the actual clixon code and commit; make clean to remove the local clone; make test again
|
||||
(2) "volatile" edit the local clone; make test.
|
||||
7
docker/main/cleanup.sh
Executable file
7
docker/main/cleanup.sh
Executable file
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Kill all controller containers (optionally do `make clean`)
|
||||
sudo docker kill clixon-system
|
||||
|
||||
|
||||
|
||||
59
docker/main/start.sh
Executable file
59
docker/main/start.sh
Executable file
|
|
@ -0,0 +1,59 @@
|
|||
#!/bin/bash
|
||||
# Usage: ./startup.sh
|
||||
# Debug: DBG=1 ./startup.sh
|
||||
# See also cleanup.sh
|
||||
|
||||
>&2 echo "Running script: $0"
|
||||
|
||||
# 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:-0}
|
||||
|
||||
# Expose other host port than port 80
|
||||
PORT=${PORT:-80}
|
||||
|
||||
# Initial running datastore content (other than empty)
|
||||
STORE=${STORE:-}
|
||||
|
||||
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_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}
|
||||
|
||||
# Start clixon-example backend
|
||||
>&2 echo -n "Starting Backend..."
|
||||
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"
|
||||
|
||||
|
||||
|
||||
|
||||
84
docker/main/startsystem.sh
Executable file
84
docker/main/startsystem.sh
Executable file
|
|
@ -0,0 +1,84 @@
|
|||
#!/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}
|
||||
|
||||
WWWUSER=${WWWUSER:-www-data}
|
||||
|
||||
# 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/conf.d/default.conf
|
||||
#
|
||||
server {
|
||||
listen 80 default_server;
|
||||
listen localhost:80 default_server;
|
||||
listen [::]:80 default_server;
|
||||
server_name localhost;
|
||||
server_name _;
|
||||
location / {
|
||||
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
|
||||
|
||||
# This is a clixon site test file.
|
||||
# Add to skiplist:
|
||||
# - all 3rd party model testing (you need to download the repos)
|
||||
# - test_install.sh since you dont have the make environment
|
||||
# - test_order.sh XXX this is a bug need debugging
|
||||
cat <<EOF > /usr/local/bin/test/site.sh
|
||||
# Add your local site specific env variables (or tests) here.
|
||||
SKIPLIST="test_yangmodels.sh test_openconfig.sh test_install.sh"
|
||||
#IETFRFC=
|
||||
EOF
|
||||
|
||||
chmod 775 /usr/local/bin/test/site.sh
|
||||
|
||||
if [ ! -d /run/nginx ]; then
|
||||
mkdir /run/nginx
|
||||
fi
|
||||
|
||||
# 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 $WWWUSER &
|
||||
>&2 echo "clixon_restconf started"
|
||||
|
||||
# Set grp write XXX do this when creating
|
||||
chmod g+w /www-data/fastcgi_restconf.sock
|
||||
|
||||
# Start clixon backend
|
||||
>&2 echo "start clixon_backend:"
|
||||
/usr/local/sbin/clixon_backend -FD $DBG -s running -l e # logs on docker logs
|
||||
|
||||
# Alt: let backend be in foreground, but test scripts may
|
||||
# want to restart backend
|
||||
/bin/sleep 100000000
|
||||
Loading…
Add table
Add a link
Reference in a new issue