diff --git a/build/build.sh b/build/build.sh index 2ef43e4..ed6612a 100755 --- a/build/build.sh +++ b/build/build.sh @@ -2,101 +2,7 @@ set -e -function cleanup() { - echo 'Cleanup' - rm -rf ./surok - rm -rf ./out - rm -f ./Dockerfile* -} - -function copy_surok() { - mkdir -p ./surok - for f in ../*; do - if [[ $f != '../.git' ]] && [[ $f != '../build' ]]; then - cp -r $f ./surok; - fi - done - - SUROK_DEPS=$(grep '^Depends:' surok/debian/control | awk -F': ' '{print $2}' | sed 's/,//g') - CUR_DIR=$(pwd) -} - -function build_builder() { - copy_surok - cat > Dockerfile.builder < - -# Install build depends -RUN apt-get update -RUN apt-get -y install devscripts debhelper -RUN apt-get clean - -COPY surok /opt/surok_build - -ENTRYPOINT cd /opt/surok_build && dpkg-buildpackage -uc -us && \ -mv /opt/surok_*.deb /opt/out -EOF -} - -function build_package() { - # run build - echo 'Build builder' - docker build -t surok_builder:latest -f Dockerfile.builder . - docker run -ti -v $CUR_DIR/out:/opt/out surok_builder:latest -} - -function build_surok_base() { - if [[ $1 == 'rebuild' ]]; then - build_builder - build_package - fi - - DEB=$(cd out && ls | grep .deb) - - cat > Dockerfile.surok < - -ADD out/${DEB} /tmp -RUN apt-get update && apt-get install -y ${SUROK_DEPS} python3-memcache -RUN dpkg -i /tmp/${DEB} -RUN apt-get clean -RUN rm -rf /tmp/* - -ENTRYPOINT cd /opt/surok && python3 surok.py -c /etc/surok/conf/surok.json -EOF - docker build -t surok_base:latest -f Dockerfile.surok . -} - -function build_alpine() { - copy_surok - cat > Dockerfile.alpine << EOF -FROM alpine:latest - -MAINTAINER Denis Zheleztsov - -# Install Python -RUN apk update && apk add python3 - -# Upgrade pip -RUN pip3 install --upgrade pip - -RUN pip3 install dnspython -RUN pip3 install jinja2 -RUN pip3 install requests -RUN pip3 install python-memcached - -COPY surok /opt/surok - -ENTRYPOINT cd /opt/surok && python3 surok.py -c /etc/surok/conf/surok.json -EOF -docker build -t surok_alpine -f Dockerfile.alpine . -} +. functions.sh function usage() { echo "$0 " diff --git a/build/functions.sh b/build/functions.sh new file mode 100644 index 0000000..406702c --- /dev/null +++ b/build/functions.sh @@ -0,0 +1,95 @@ +function cleanup() { + echo 'Cleanup' + rm -rf ./surok + rm -rf ./out + rm -f ./Dockerfile* +} + +function copy_surok() { + mkdir -p ./surok + for f in ../*; do + if [[ $f != '../.git' ]] && [[ $f != '../build' ]]; then + cp -r $f ./surok; + fi + done + + SUROK_DEPS=$(grep '^Depends:' surok/debian/control | awk -F': ' '{print $2}' | sed 's/,//g') + CUR_DIR=$(pwd) +} + +function build_builder() { + copy_surok + cat > Dockerfile.builder < + +# Install build depends +RUN apt-get update +RUN apt-get -y install devscripts debhelper +RUN apt-get clean + +COPY surok /opt/surok_build + +ENTRYPOINT cd /opt/surok_build && dpkg-buildpackage -uc -us && \ +mv /opt/surok_*.deb /opt/out +EOF +} + +function build_package() { + # run build + echo 'Build builder' + docker build -t surok_builder:latest -f Dockerfile.builder . + docker run -ti -v $CUR_DIR/out:/opt/out surok_builder:latest +} + +function build_surok_base() { + if [[ $1 == 'rebuild' ]]; then + build_builder + build_package + fi + + DEB=$(cd out && ls | grep .deb) + + cat > Dockerfile.surok < + +ADD out/${DEB} /tmp +RUN apt-get update && apt-get install -y ${SUROK_DEPS} python3-memcache +RUN dpkg -i /tmp/${DEB} +RUN apt-get clean +RUN rm -rf /tmp/* + +ENTRYPOINT cd /opt/surok && python3 surok.py -c /etc/surok/conf/surok.json +EOF + docker build -t surok_base:latest -f Dockerfile.surok . +} + +function build_alpine() { + copy_surok + cat > Dockerfile.alpine << EOF +FROM alpine:latest + +MAINTAINER Denis Zheleztsov + +# Install Python +RUN apk update && apk add python3 + +# Upgrade pip +RUN pip3 install --upgrade pip + +RUN pip3 install dnspython +RUN pip3 install jinja2 +RUN pip3 install requests +RUN pip3 install python-memcached + +COPY surok /opt/surok + +ENTRYPOINT cd /opt/surok && python3 surok.py -c /etc/surok/conf/surok.json +EOF + docker build -t surok_alpine -f Dockerfile.alpine . +} diff --git a/build/runtests.sh b/build/runtests.sh new file mode 100755 index 0000000..37cbbe7 --- /dev/null +++ b/build/runtests.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -e + +. functions.sh + +function run_tests() { + docker run -ti -v $(pwd)/tests.py:/opt/surok/tests.py \ + -v $(pwd)/tests_entrypoint.sh:/tests_entrypoint.sh \ + --entrypoint /tests_entrypoint.sh \ + surok_base:latest +} + +run_tests diff --git a/build/tests.py b/build/tests.py new file mode 100644 index 0000000..a194afc --- /dev/null +++ b/build/tests.py @@ -0,0 +1,23 @@ +import unittest +import json +import os + + +class TestLoadConfig(unittest.TestCase): + + + def test_main_conf(self): + # Load base configurations + surok_conf = '/etc/surok/conf/surok.json' + # Read config file + f = open(surok_conf, 'r') + conf = json.loads(f.read()) + f.close() + + self.assertIn('confd', conf) + self.assertTrue(os.path.isdir(conf['confd'])) + self.assertIn('domain', conf) + + +if __name__ == '__main__': + unittest.main() diff --git a/build/tests_entrypoint.sh b/build/tests_entrypoint.sh new file mode 100755 index 0000000..94a054c --- /dev/null +++ b/build/tests_entrypoint.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +cd /opt/surok && python3 tests.py