Skip to content

Commit

Permalink
Merge pull request #233 from sielaq/master
Browse files Browse the repository at this point in the history
PaaS update
  • Loading branch information
sielaq authored Nov 29, 2016
2 parents b91480c + e9123c7 commit 5734679
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ before_install:
- gem install marathon_deploy
- docker pull ubuntu:16.04
- docker ps
- ./build-docker-images.sh
- ./build-docker-image.sh
- export IP=$(/sbin/ifconfig eth0 | awk '/inet addr:/{gsub(/.*:/,"",$2);print $2;exit}')
- echo $IP
- export START_DNSMASQ=false
Expand Down
26 changes: 26 additions & 0 deletions build-docker-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

[ -f ./restricted/common ] && . ./restricted/common
[ -f ./restricted/host ] && . ./restricted/host

error_exit() {
echo "ERROR DURING BUILDING IMAGE"
exit 1
}

[ ${http_proxy} ] && PROXY="--build-arg http_proxy=${http_proxy}"
[ ${https_proxy} ] && PROXY="${PROXY} --build-arg https_proxy=${https_proxy}"

TAG=${PANTERAS_IMAGE_TAG:-$(cat infrastructure/version)}
IMAGE=${IMAGE:-"panteras/paas-in-a-box:${TAG}"}
docker version >/dev/null 2>&1 || {
sudo docker version >/dev/null 2>&1 && SUDO_NEEDED=1 || {
echo "Can't run docker"
exit 1
}
}

[ $SUDO_NEEDED ] && SUDO='sudo'

$SUDO docker build --rm=true ${PROXY} --tag=${REGISTRY}${IMAGE} infrastructure || error_exit
$SUDO docker tag ${REGISTRY}${IMAGE} ${IMAGE} || error_exit
23 changes: 0 additions & 23 deletions build-docker-images.sh

This file was deleted.

18 changes: 13 additions & 5 deletions generate_yml.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
#!/bin/bash
# docker-compose.yml generator
#

[ -f docker-compose.yml.tpl ] || {
echo "Error: docker-compose.yml.tpl need to be in CWD"
exit 1
}

mkdir -p ./restricted
touch ./restricted/env

[ -f /etc/default/panteras ] && . /etc/default/panteras
[ -f ./restricted/common ] && . ./restricted/common
[ -f ./restricted/host ] && . ./restricted/host
[ -f ./restricted/overwrite ] && . ./restricted/overwrite

echo "Keep in mind, to set free these ports on DOCKER HOST:"
echo "53, 80, 81, 2181, 2888, 3888, 4400, 5050, 5151, 8080, 8300 - 8302, 8400, 8500, 8600, 9000, 31000 - 32000"
echo "and be sure that your hostname is resolvable, if not, add entry to /etc/resolv.conf"
echo "and be sure that your hostname is resolvable, if not, configure dns in /etc/resolv.conf or add entry in /etc/hosts"

# Try to detect IP
# docker-machine / boot2docker
Expand All @@ -26,7 +37,7 @@ MASTER=${MASTER:-"true"}
SLAVE=${SLAVE:-"true"}

# allow to specify a specific docker image or a specific tag of the pass-in-a-box image
PANTERAS_IMAGE_TAG=${PANTERAS_IMAGE_TAG:-$(awk '{print $2}' infrastructure/version)} #'
PANTERAS_IMAGE_TAG=${PANTERAS_IMAGE_TAG:-$(cat infrastructure/version)} #'
echo $PANTERAS_IMAGE_TAG
PANTERAS_DOCKER_IMAGE=${PANTERAS_DOCKER_IMAGE:-${REGISTRY}panteras/paas-in-a-box:${PANTERAS_IMAGE_TAG}}

Expand Down Expand Up @@ -189,8 +200,5 @@ NETDATA_APP_PARAMS=${NETDATA_APP_PARAMS:-$NETDATA_PARAMS}
PANTERAS_HOSTNAME=${PANTERAS_HOSTNAME:-${HOSTNAME}}
PANTERAS_RESTART=${PANTERAS_RESTART:-"no"}

# Put your ENV varaible in ./restricted/env
mkdir -p ./restricted
touch ./restricted/env

eval "$(cat docker-compose.yml.tpl| sed 's/"/+++/g'|sed 's/^\(.*\)$/echo "\1"/')" |sed 's/+++/"/g'|sed 's;\\";";g' > docker-compose.yml
8 changes: 6 additions & 2 deletions infrastructure/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ RUN apt-get update \

ENV SUPERVISORD_APP_VERSION 3.2.3
ENV DOCKER_APP_VERSION 1.12.3-0~xenial
ENV CONSUL_APP_VERSION 0.7.0
ENV CONSUL_APP_VERSION 0.7.1
ENV CONSUL_TEMPLATE_APP_VERSION 0.16.0
ENV HAPROXY_APP_VERSION 1.6.3-1ubuntu0.1
ENV MESOS_APP_VERSION 1.0.1-2.0.94.ubuntu1604
ENV MARATHON_APP_VERSION 1.3.5-1.0.537.ubuntu1604
ENV MARATHON_APP_VERSION 1.3.6-1.0.540.ubuntu1604
ENV REGISTRATOR_APP_VERSION v7
ENV CHRONOS_APP_VERSION 2.4.0-0.1.20151007110204.ubuntu1404
ENV FABIO_APP_VERSION 1.3.4
Expand Down Expand Up @@ -201,7 +201,11 @@ ADD supervisord.conf /etc/supervisord.conf
ADD supervisord.sh /opt/
ADD panteras.http /etc/haproxy/errors/
ADD version /opt/

ADD logo.sh /etc/profile.d
ADD paas.sh /etc/profile.d
ADD bashrc /tmp

RUN cat /tmp/bashrc >> /root/.bashrc

WORKDIR /opt
Expand Down
46 changes: 1 addition & 45 deletions infrastructure/bashrc
Original file line number Diff line number Diff line change
@@ -1,45 +1 @@
paas-connect ()
{
if [ -z "$1" ]; then
echo "For connecting to service provide service_name/regex/substring as first parameter.";
else
for i in $(paas-list | tail -n+2 | awk '{print $1":"$2}');
do
name=$(echo $i | cut -d: -f2);
id=$(echo $i | cut -d: -f1);
if [[ $name =~ $1 ]]; then
echo "Connecting to ${id}...";
docker exec -ti $id bash;
fi;
done;
fi
}
paas-list ()
{
all_containers="$(docker inspect $(docker ps -q))";
count=$(echo "$all_containers"|jshon -l);
count=$(($count-1));
printf "%12s %-33s %-13s %6s %6s %-9s\n" "DOCKER-ID" "MARATHON_APP_ID" "HOST" "PORT" "MEM" "XMX";
for i in $(seq 0 $count);
do
unset MARATHON_APP_ID JAVA_XMX;
values=$(echo "$all_containers"|jshon -e $i -e Config -e Env -a -u);
id=$(echo "$all_containers"|jshon -e $i -e Id -u);
eval "${values}" > /dev/null 2>&1;
[ $MARATHON_APP_ID ] && printf "%-12s %-33s %-13s %6s %5sm %-9s\n" ${id:0:12} $MARATHON_APP_ID ${HOST%%.*} $PORT ${MARATHON_APP_RESOURCE_MEM%%.*} $JAVA_XMX;
done | sort -k2,2
}

toilet -f Elite PanteraS | /usr/games/lolcat -f
cat version | /usr/games/lolcat -f
echo
paas-list
echo
echo "Useful commands:"
echo " paas-list | to get the list of running marathon app"
echo " paas-connect <marathon_app_id> | to get the container's shell(s)"
echo " supervisorctl status | to get status of all PaaS services"
echo " mesos_consul_consistency_check [-d] | to check consistency"
echo " marathon_deploy | to deploy yaml plan from command line"

export PS1="\[\e[01;32m\]\u@\h\[\e[m\][\[\e[31m\]PanteraS\[\e[m\]]:\[\e[01;34m\]\w\[\e[m\]\$ "
[ $version ] || { . /etc/profile.d/logo.sh && . /etc/profile.d/paas.sh; }
4 changes: 4 additions & 0 deletions infrastructure/logo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export LC_ALL=en_US.utf8
version=$(cat version)
toilet -f Elite PanteraS | /usr/games/lolcat -f
echo "version $version"| /usr/games/lolcat -f
51 changes: 51 additions & 0 deletions infrastructure/paas.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
paas-connect ()
{
if [ -z "$1" ]; then
echo "For connecting to service provide service_name/regex/substring as first parameter.";
paas_image=$(sudo docker ps | awk '/panteras/{print $NF}')
[ $paas_image ] && {
echo "Connecting to PaaS image instead..."
sudo docker exec -ti $paas_image bash
}
else
for i in $(paas-list | awk 'NR>1 {print $1":"$2}');
do
name=${i##*:}
id=${i%%:*}
if [[ $name =~ $1 ]]; then
echo "Connecting to ${id}...";
sudo docker exec -ti $id bash;
fi;
done;
fi
}

paas-list ()
{
all_containers="$(docker inspect $(docker ps -q))";
count=$(echo "$all_containers"|jshon -l);
count=$(($count-1));
max_len_app_id=$(echo "$all_containers"|jshon -a -e Config -e Env -a -u | awk -F\= '/MARATHON_APP_ID/{print $2}'| wc -L)
printf "%12s %-${max_len_app_id}s %-13s %6s %6s %-9s\n" "DOCKER-ID" "MARATHON_APP_ID" "HOST" "PORT" "MEM" "XMX";
for i in $(seq 0 $count);
do
unset MARATHON_APP_ID JAVA_XMX;
values=$(echo "$all_containers"|jshon -e $i -e Config -e Env -a -u);
id=$(echo "$all_containers"|jshon -e $i -e Id -u);
eval "${values}" > /dev/null 2>&1;
[ $MARATHON_APP_ID ] && printf "%-12s %-${max_len_app_id}s %-13s %6s %5sm %-9s\n" ${id:0:12} $MARATHON_APP_ID ${HOST%%.*} $PORT ${MARATHON_APP_RESOURCE_MEM%%.*} $JAVA_XMX;
done | sort -k2,2
} 2>/dev/null

echo
paas-list
echo
echo "Useful commands:"
echo " paas-list | to get the list of running marathon app"
echo " paas-connect <marathon_app_id> | to get the container's shell(s)"
echo " supervisorctl status | to get status of all PaaS services"
echo " mesos_consul_consistency_check [-d] | to check consistency"
echo " marathon_deploy | to deploy yaml plan from command line"

# If inside container
[ -f /.dockerenv ] && export PS1="\[\e[01;32m\]\u@\h\[\e[m\][\[\e[31m\]PanteraS\[\e[m\]]:\[\e[01;34m\]\w\[\e[m\]\$ "
7 changes: 3 additions & 4 deletions infrastructure/supervisord.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/bin/bash

[ -z ${HOST_IP} ] || exec supervisord -c /etc/supervisord.conf
export LC_ALL=en_US.utf8
toilet -f Elite PanteraS | /usr/games/lolcat -f 2>/dev/null
version=$(cat version)
echo $version
. /etc/profile.d/logo.sh

cat << EOF
PanteraS - Platform as a Service
Usage:
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version 0.3.1
0.3.2
6 changes: 3 additions & 3 deletions provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

paas="PanteraS"
REPODIR=`dirname $0`
export PANTERAS_IMAGE_TAG=$(awk '/version/{print $2}' ${REPODIR}/infrastructure/version)
export PANTERAS_IMAGE_TAG=$(cat ${REPODIR}/infrastructure/version)
IMAGE="${REGISTRY}panteras/paas-in-a-box:$PANTERAS_IMAGE_TAG"

usage(){
Expand Down Expand Up @@ -128,7 +128,7 @@ case "$MODE" in
! hasDockerCompose && echo "error: docker-compose not detected" >&2 && exit 1
echo BUILDIMAGES
echo $BUILDIMAGES
[ "$BUILDIMAGES" == "true" ] && cd $REPODIR && . ./build-docker-images.sh \
[ "$BUILDIMAGES" == "true" ] && cd $REPODIR && . ./build-docker-image.sh \
|| docker pull ${IMAGE}

LOCALIP=${LOCALIP:-$(hostname --ip-address| awk '{ print $2}')}
Expand Down Expand Up @@ -189,7 +189,7 @@ case "$MODE" in

}

[ "$BUILDIMAGES" == "true" ] && cd $REPODIR && . ./build-docker-images.sh \
[ "$BUILDIMAGES" == "true" ] && cd $REPODIR && . ./build-docker-image.sh \
|| docker pull ${IMAGE}


Expand Down

0 comments on commit 5734679

Please sign in to comment.