surok/build/build.sh

117 lines
2.3 KiB
Bash
Raw Normal View History

2016-11-10 11:54:27 +03:00
#!/bin/bash
set -e
function cleanup() {
echo 'Cleanup'
rm -rf ./surok
rm -rf ./out
rm -f ./Dockerfile*
}
2016-11-11 17:34:29 +03:00
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)
}
2016-11-10 11:54:27 +03:00
2016-11-11 17:34:29 +03:00
function build_builder() {
copy_surok
cat > Dockerfile.builder <<EOF
2016-11-10 17:20:46 +03:00
FROM ubuntu:xenial
2016-11-10 11:54:27 +03:00
# Build debian package
MAINTAINER Denis Zheleztsov <difrex.punk@gmail.com>
# Install build depends
2016-11-10 13:24:36 +03:00
RUN apt-get update
RUN apt-get -y install devscripts debhelper
RUN apt-get clean
2016-11-10 11:54:27 +03:00
2016-11-10 17:20:46 +03:00
COPY surok /opt/surok_build
2016-11-10 11:54:27 +03:00
ENTRYPOINT cd /opt/surok_build && dpkg-buildpackage -uc -us && \
mv /opt/surok_*.deb /opt/out
EOF
}
2016-11-10 13:24:36 +03:00
2016-11-10 11:54:27 +03:00
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() {
2016-11-10 17:20:46 +03:00
if [[ $1 == 'rebuild' ]]; then
build_builder
build_package
fi
2016-11-10 11:54:27 +03:00
DEB=$(cd out && ls | grep .deb)
cat > Dockerfile.surok <<EOF
2016-11-10 17:20:46 +03:00
FROM ubuntu:xenial
2016-11-10 11:54:27 +03:00
MAINTAINER Denis Zheleztsov <difrex.punk@gmail.com>
ADD out/${DEB} /tmp
2016-11-11 12:15:33 +03:00
RUN apt-get update && apt-get install -y ${SUROK_DEPS} python3-memcache
2016-11-10 11:54:27 +03:00
RUN dpkg -i /tmp/${DEB}
2016-11-10 13:24:36 +03:00
RUN apt-get clean
RUN rm -rf /tmp/*
2016-11-10 11:54:27 +03:00
ENTRYPOINT cd /opt/surok && python3 surok.py -c /etc/surok/conf/surok.json
EOF
docker build -t surok_base:latest -f Dockerfile.surok .
}
2016-11-11 17:34:29 +03:00
function build_alpine() {
copy_surok
cat > Dockerfile.alpine << EOF
FROM alpine:latest
MAINTAINER Denis Zheleztsov <difrex.punk@gmail.com>
# 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 .
}
2016-11-10 11:54:27 +03:00
function usage() {
2016-11-11 17:34:29 +03:00
echo "$0 <clean|build_package|surok_image|alpine>"
2016-11-10 11:54:27 +03:00
}
2016-11-10 13:24:36 +03:00
case $1 in
clean) cleanup ;;
build_package)
build_builder
build_package
;;
2016-11-10 17:20:46 +03:00
build_deb) build_package ;;
surok_image) build_surok_base rebuild ;;
surok_image_no_rebuild) build_surok_base ;;
2016-11-11 17:34:29 +03:00
alpine) build_alpine ;;
2016-11-10 13:24:36 +03:00
*) usage ;;
2016-11-10 11:54:27 +03:00
esac