* New docker build (preliminary) for a development container

* Load clixon-clispec on start
This commit is contained in:
Olof hagsand 2021-12-07 20:01:14 +01:00
parent 854958b5e8
commit 8c5a5a0fb3
11 changed files with 303 additions and 9 deletions

View file

@ -16,12 +16,12 @@ jobs:
# 1) checkout and compile natively
- name: install cligen
run: (git clone https://github.com/clicon/cligen.git && cd cligen && ./configure && make && sudo make install)
- name: install libevent
- name: install libevent, ssl and nghttp2
run: sudo apt install -y libevent-dev libssl-dev libnghttp2-dev
- name: install libevhtp
run: (git clone https://github.com/clicon/clixon-libevhtp.git && cd clixon-libevhtp && ./configure && make && sudo make install)
- name: configure
run: ./configure --with-restconf=native
run: ./configure
# 2) Use docker for tests
- name: make test # this is docker test
run: make test

View file

@ -37,8 +37,9 @@ Planned: January, 2022
### Minor features
* Changed typo `configure --with-yang-standard-installdir` to `configure --with-yang-standard-dir
`
* New `clixon-dev` development container (Work-in-progress)
* New `clixon-clispec.yang` for controlling auto-cli (Work-in-progress)
* Changed typo `configure --with-yang-standard-installdir` to `configure --with-yang-standard-dir`
### Corrected Bugs

View file

@ -268,7 +268,12 @@ autocli_start(clicon_handle h,
/* If autocli disabled quit */
if ((autocli_model = clicon_cli_genmodel(h)) == 0)
goto ok;
yspec = clicon_dbspec_yang(h);
/* Load clispec for autocli */
if (yang_spec_parse_module(h, "clixon-clispec", NULL, yspec)< 0)
goto done;
/* Get the autocli type, ie HOW the cli is generated (could be much more here) */
/* Create show_treename cbuf */
if ((show_treename = cbuf_new()) == NULL){

5
configure vendored
View file

@ -5678,7 +5678,7 @@ _ACEOF
ac_config_files="$ac_config_files Makefile lib/Makefile lib/src/Makefile lib/clixon/Makefile apps/Makefile apps/cli/Makefile apps/backend/Makefile apps/netconf/Makefile apps/restconf/Makefile include/Makefile etc/Makefile etc/clixonrc example/Makefile example/main/Makefile example/main/example.xml extras/rpm/Makefile docker/Makefile docker/main/Makefile docker/base/Makefile util/Makefile yang/Makefile yang/clixon/Makefile yang/mandatory/Makefile doc/Makefile test/Makefile test/config.sh test/cicd/Makefile test/vagrant/Makefile"
ac_config_files="$ac_config_files Makefile lib/Makefile lib/src/Makefile lib/clixon/Makefile apps/Makefile apps/cli/Makefile apps/backend/Makefile apps/netconf/Makefile apps/restconf/Makefile include/Makefile etc/Makefile etc/clixonrc example/Makefile example/main/Makefile example/main/example.xml extras/rpm/Makefile docker/Makefile docker/base/Makefile docker/clixon-dev/Makefile docker/main/Makefile util/Makefile yang/Makefile yang/clixon/Makefile yang/mandatory/Makefile doc/Makefile test/Makefile test/config.sh test/cicd/Makefile test/vagrant/Makefile"
cat >confcache <<\_ACEOF
# This file is a shell script that caches the results of configure
@ -6389,8 +6389,9 @@ do
"example/main/example.xml") CONFIG_FILES="$CONFIG_FILES example/main/example.xml" ;;
"extras/rpm/Makefile") CONFIG_FILES="$CONFIG_FILES extras/rpm/Makefile" ;;
"docker/Makefile") CONFIG_FILES="$CONFIG_FILES docker/Makefile" ;;
"docker/main/Makefile") CONFIG_FILES="$CONFIG_FILES docker/main/Makefile" ;;
"docker/base/Makefile") CONFIG_FILES="$CONFIG_FILES docker/base/Makefile" ;;
"docker/clixon-dev/Makefile") CONFIG_FILES="$CONFIG_FILES docker/clixon-dev/Makefile" ;;
"docker/main/Makefile") CONFIG_FILES="$CONFIG_FILES docker/main/Makefile" ;;
"util/Makefile") CONFIG_FILES="$CONFIG_FILES util/Makefile" ;;
"yang/Makefile") CONFIG_FILES="$CONFIG_FILES yang/Makefile" ;;
"yang/clixon/Makefile") CONFIG_FILES="$CONFIG_FILES yang/clixon/Makefile" ;;

View file

@ -368,8 +368,9 @@ AC_OUTPUT(Makefile
example/main/example.xml
extras/rpm/Makefile
docker/Makefile
docker/base/Makefile
docker/clixon-dev/Makefile
docker/main/Makefile
docker/base/Makefile
util/Makefile
yang/Makefile
yang/clixon/Makefile

View file

@ -2,6 +2,8 @@
This directory contains sub-directories with examples of Clixon docker images:
* [base](base/README.md) Clixon base image
* [main](main/README.md) Main example and test application used in upstream CI
* [base](base/README.md) Clixon base image
* [clixon-dev](clixon-dev/README.md) Clixon development image
* [main](main/README.md) Main example and test application used in upstream CI

View file

@ -0,0 +1,86 @@
#
# ***** BEGIN LICENSE BLOCK *****
#
# Copyright (C) 2017-2019 Olof Hagsand
# Copyright (C) 2020-2021 Olof Hagsand and Rubicon Communications, LLC(Netgate)
#
# 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 curl-dev
# evhtp dependencies
RUN apk add --update libevent libevent-dev
# nghttp2 dependencies
RUN apk add --update nghttp2
# Create a directory to hold source-code, dependencies etc
RUN mkdir /clixon
# clone libevhtp
WORKDIR /clixon
RUN git clone https://github.com/clicon/clixon-libevhtp.git
WORKDIR /clixon/clixon-libevhtp
RUN ./configure
RUN make
RUN mkdir /usr/local/include
RUN make install
RUN mkdir /clixon/build
WORKDIR /clixon
# Clone cligen
RUN git clone https://github.com/clicon/cligen.git
# Build cligen
WORKDIR /clixon/cligen
RUN ./configure --prefix=/clixon/build
RUN make
RUN make install
# Need to add www user manually
RUN adduser -D -H -G www-data www-data
# Copy Clixon from local dir
RUN mkdir /clixon/clixon
WORKDIR /clixon/clixon
COPY clixon .
# Configure, build and install clixon
RUN ./configure --prefix=/clixon/build --with-cligen=/clixon/build --with-restconf=native --enable-nghttp2 --enable-evhtp
RUN make
RUN make install

View file

@ -0,0 +1,74 @@
#
# ***** BEGIN LICENSE BLOCK *****
#
# Copyright (C) 2017-2019 Olof Hagsand
# Copyright (C) 2020-2021 Olof Hagsand and Rubicon Communications, LLC(Netgate)
#
# 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@
# docker.hub image. CHANGE THIS IF YOU PUSH YOUR OWN
IMG = clixon/clixon-dev # base image
SHELL = /bin/sh
.PHONY: all clean distclean docker 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)
depend:
install-include:
install:
uninstall:

View file

@ -0,0 +1,21 @@
# Clixon base development docker image
This directory contains code for building a clixon base development
docker container that can be used as a stage 1 builder for clixon appplications
This clixon base container uses native http.
The clixon docker base image can be used to build clixon
applications. It has the whole code for a clixon release which it
downloads from git.
## Build
Perform the build by `make docker`. This copies the latest _committed_ clixon code into the container.
## Push
You may also do `make push` if you want to push the image, but you may then consider changing the image name (in the makefile:s).
(You may have to login for push with sudo docker login -u <username>)

102
test/test_cli_varonly.sh Executable file
View file

@ -0,0 +1,102 @@
#!/usr/bin/env bash
# test for cli when CLICON_CLI_VARONLY is 0
# I.e., INCLUDE keys
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example
# include err() and new() functions and creates $dir
cfg=$dir/conf.xml
fyang=$dir/example.yang
# Use yang in example
cat <<EOF > $cfg
<clixon-config xmlns="http://clicon.org/config">
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
<CLICON_YANG_DIR>/usr/local/share/clixon</CLICON_YANG_DIR>
<CLICON_YANG_DIR>$IETFRFC</CLICON_YANG_DIR>
<CLICON_YANG_DIR>$dir</CLICON_YANG_DIR>
<CLICON_YANG_MODULE_MAIN>example</CLICON_YANG_MODULE_MAIN>
<CLICON_BACKEND_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR>
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
<CLICON_CLI_VARONLY>0</CLICON_CLI_VARONLY>
<CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR>
<CLICON_SOCK>/usr/local/var/$APPNAME/$APPNAME.sock</CLICON_SOCK>
<CLICON_BACKEND_PIDFILE>/usr/local/var/$APPNAME/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
</clixon-config>
EOF
cat <<EOF > $fyang
module example {
yang-version 1.1;
namespace "urn:example:example";
prefix ex;
/* Generic config data */
container table{
list parameter{
key name;
leaf name{
type string;
}
leaf value{
type string;
}
}
}
}
EOF
new "test params: -f $cfg"
if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -z -f $cfg
if [ $? -ne 0 ]; then
err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
fi
new "wait backend"
wait_backend
new "cli set 42 include keys"
expectpart "$($clixon_cli -1 -o CLICON_CLI_VARONLY=0 -f $cfg set table parameter 42)" 0 "^$"
new "cli set 43 exclude keys"
expectpart "$($clixon_cli -1 -o CLICON_CLI_VARONLY=1 -f $cfg set table parameter 43)" 0 "^$"
new "cli show 42 43 include"
expectpart "$($clixon_cli -1 -o CLICON_CLI_VARONLY=0 -f $cfg show conf cli)" 0 "set table parameter 42" "set table parameter 43"
new "cli show 42 43 exclude"
expectpart "$($clixon_cli -1 -o CLICON_CLI_VARONLY=1 -f $cfg show conf cli)" 0 "set table parameter 42" "set table parameter 43"
new "cli expand include keys"
expectpart "$(echo "set table parameter ?" | $clixon_cli -o CLICON_CLI_VARONLY=0 -f $cfg 2>&1)" 0 42 43
new "cli expand exclude keys"
expectpart "$(echo "set table parameter ?" | $clixon_cli -o CLICON_CLI_VARONLY=1 -f $cfg 2>&1)" 0 42 43
if [ $BE -ne 0 ]; then
new "Kill backend"
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
fi
rm -rf $dir
new "endtest"
endtest

View file

@ -47,6 +47,7 @@ YANGSPECS += clixon-lib@2021-11-11.yang # 5.4
YANGSPECS += clixon-rfc5277@2008-07-01.yang
YANGSPECS += clixon-xml-changelog@2019-03-21.yang
YANGSPECS += clixon-restconf@2021-05-20.yang # 5.2
YANGSPECS += clixon-clispec@2021-12-05.yang
APPNAME = clixon # subdir ehere these files are installed