From c1bec161bef0aa29fc710dee95d7c94b1e0c56f1 Mon Sep 17 00:00:00 2001 From: Denis Zheleztsov Date: Thu, 10 Nov 2016 11:54:27 +0300 Subject: [PATCH] build a debian package --- README.en.md | 14 +++++++++ README.md | 16 +++++++++- build/build.sh | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+), 1 deletion(-) create mode 100755 build/build.sh diff --git a/README.en.md b/README.en.md index 29fdcfa..262bc3f 100644 --- a/README.en.md +++ b/README.en.md @@ -6,3 +6,17 @@ Service discovery for Apache Mesos. * Discovery over mesos-dns * Applications config reload +## Build + +build debian package +``` +cd build +./build build_package +``` +A deb-package will be placed in build/out + +build surok base docker image +``` +cd build +./build surok_image +``` diff --git a/README.md b/README.md index 5fee0f4..94bc495 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,22 @@ # Surok -Обнаружение сервисов для Apache Mesos. +Обнаружение сервисов для Apache Mesos. * Конфигурация на Jinja2 * Обнаружение через mesos-dns * Перезагрузка конфигурации приложения +## Сборка + +Сборка deb-пакета +``` +cd build +./build build_package +``` +deb-пакет будет лежать в build/out + +Сборка базового docker-образа surok +``` +cd build +./build surok_image +``` diff --git a/build/build.sh b/build/build.sh new file mode 100755 index 0000000..fd236ed --- /dev/null +++ b/build/build.sh @@ -0,0 +1,83 @@ +#!/bin/bash + +set -e + +function cleanup() { + echo 'Cleanup' + rm -rf ./surok + rm -rf ./out + rm -f ./Dockerfile* +} + +function build_builder() { + 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) + + cat > Dockerfile.builder < + +COPY surok /opt/surok_build + +# Install build depends +RUN apt-get update && apt-get -y install devscripts debhelper + +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() { + build_builder + build_package + + DEB=$(cd out && ls | grep .deb) + + cat > Dockerfile.surok < + +ADD out/${DEB} /tmp +RUN apt-get update && apt-get install -y ${SUROK_DEPS} +RUN dpkg -i /tmp/${DEB} + +ENTRYPOINT cd /opt/surok && python3 surok.py -c /etc/surok/conf/surok.json +EOF + docker build -t surok_base:latest -f Dockerfile.surok . +} + +function usage() { + echo "$0 " +} + +case $1 in clean) + cleanup + ;; + build_package) + build_builder + build_package + ;; + surok_image) + build_surok_base + ;; + *) + usage + ;; +esac