Skip to content

Commit

Permalink
optimization for paas-temaplate v42
Browse files Browse the repository at this point in the history
  • Loading branch information
ogrand committed Jul 1, 2019
1 parent c82b15f commit 068065c
Show file tree
Hide file tree
Showing 15 changed files with 334 additions and 266 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ USER root
ARG DEBIAN_FRONTEND=noninteractive

#--- Packages list
ENV START_SCRIPT="/usr/local/bin/supervisord.sh" \
INIT_PACKAGES="apt-utils ca-certificates sudo wget curl unzip openssh-server openssl apt-transport-https" \
ENV INIT_PACKAGES="apt-utils ca-certificates sudo wget curl unzip openssh-server openssl apt-transport-https" \
TOOLS_PACKAGES="supervisor git-core s3cmd bash-completion apg vim less mlocate nano screen tmux byobu silversearcher-ag colordiff" \
NET_PACKAGES="netbase net-tools iproute2 iputils-ping dnsutils ldap-utils netcat tcpdump mtr-tiny" \
DEV_PACKAGES="nodejs python-pip python-dev build-essential libffi-dev libssl-dev libxml2-dev libxslt1-dev libpq-dev libsqlite3-dev libmysqlclient-dev zlib1g-dev libcurl4-openssl-dev" \
Expand Down
52 changes: 52 additions & 0 deletions bosh-cli/init-git.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash
#===========================================================================
# Init git cli configuration
#===========================================================================

#--- Colors and styles
export YELLOW='\033[1;33m'
export STD='\033[0m'
export BOLD='\033[1m'
export REVERSE='\033[7m'

configureGit() {
flag=$(echo "${GIT_OPTIONS}" | grep " $1 ")
if [ "${flag}" = "" ] ; then
printf "\n%b- Set \"$1\" propertie...%b" "${YELLOW}" "${STD}"
git config --global $1 "$2"
fi
}

#--- List options
printf "\n%bSet git configuration%b\n" "${REVERSE}${YELLOW}" "${STD}"
GIT_OPTIONS=$(git config --name-only -l | sed -e "s+^+ +g" | sed -e "s+$+ +g")

#--- Config git options
configureGit "user.name" "$(hostname)"
configureGit "user.email" "$(hostname)@orange.com"

configureGit "alias.co" "checkout"
configureGit "alias.br" "branch"
configureGit "alias.lol" "log --graph --decorate --pretty=oneline --abbrev-commit"
configureGit "alias.lola" "log --graph --decorate --pretty=oneline --abbrev-commit --all"
configureGit "alias.st" "status"
configureGit "alias.uncommit" "reset --soft HEAD~1"

configureGit "color.ui" "auto"

configureGit "core.editor" "vi"
configureGit "core.eol" "lf"
configureGit "core.autocrlf" "input"
configureGit "core.preloadindex" "true"

configureGit "credential.helper" "cache --timeout=86400"

configureGit "http.postbuffer" "524288000"

configureGit "grep.linenumber" "true"

configureGit "push.default" "tracking"

#--- Display configurations
printf "\n\n%bGit configuration%b\n" "${REVERSE}${YELLOW}" "${STD}"
git config -l
2 changes: 1 addition & 1 deletion bosh-cli/config-mc.sh → bosh-cli/init-mc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ mc config host rm s3
s3_endpoint="http://private-s3.internal.paas:9000"
s3_access_key="private-s3"
s3_secret_key="$(getCredhubValue "/micro-bosh/minio-private-s3/s3_secretkey")"
configureHost "minio-s3" "${s3_endpoint}" "${s3_access_key}" "${s3_secret_key}"
configureHost "minio" "${s3_endpoint}" "${s3_access_key}" "${s3_secret_key}"

#--- Add host config for minio-prometheus
s3_endpoint="http://$(getValue ${PROMETHEUS_CREDENTIAL_FILE} /secrets/thanos_s3_endpoint)"
Expand Down
140 changes: 94 additions & 46 deletions bosh-cli/log-bosh.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
#!/bin/bash
#===========================================================================
# Log with Bosh cli V2
# Log with bosh cli V2
# Parameters :
# --target, -t : Bosh director target (micro, master, ops...)
# --deployment, -d : Bosh deployment name
#===========================================================================

#--- Unset bosh login credentials
unset BOSH_CLIENT
unset BOSH_CLIENT_SECRET

#--- Colors and styles
export RED='\033[1;31m'
export YELLOW='\033[1;33m'
Expand All @@ -11,75 +18,116 @@ export STD='\033[0m'
export BOLD='\033[1m'
export REVERSE='\033[7m'

unset BOSH_CLIENT
unset BOSH_CLIENT_SECRET

#--- Check Prerequisites
flagError=0
if [ ! -s "${BOSH_CA_CERT}" ] ; then
printf "\n%bERROR : CA cert file \"${BOSH_CA_CERT}\" unknown.%b\n\n" "${RED}" "${STD}"
else
#--- Identify BOSH director
flag=0
while [ ${flag} = 0 ] ; do
flag=1
printf "\n%bDirector BOSH :%b\n\n" "${REVERSE}${GREEN}" "${STD}"
printf "%b1%b : micro\n" "${GREEN}${BOLD}" "${STD}"
printf "%b2%b : master\n" "${GREEN}${BOLD}" "${STD}"
printf "%b3%b : ops\n" "${GREEN}${BOLD}" "${STD}"
printf "%b4%b : coab\n" "${GREEN}${BOLD}" "${STD}"
printf "%b5%b : kubo\n" "${GREEN}${BOLD}" "${STD}"
printf "%b6%b : ondemand\n" "${GREEN}${BOLD}" "${STD}"
printf "%b7%b : expe\n" "${GREEN}${BOLD}" "${STD}"
printf "\n%bYour choice :%b " "${GREEN}${BOLD}" "${STD}" ; read choice
case "${choice}" in
1) BOSH_TARGET="micro" ;;
2) BOSH_TARGET="master" ;;
3) BOSH_TARGET="ops" ;;
4) BOSH_TARGET="coab" ;;
5) BOSH_TARGET="kubo" ;;
6) BOSH_TARGET="ondemand" ;;
7) BOSH_TARGET="expe" ;;
*) flag=0 ; clear ;;
printf "\n%bERROR : CA cert file \"${BOSH_CA_CERT}\" unknown.%b\n\n" "${RED}" "${STD}" ; flagError=1
fi

#--- Check scripts options
usage() {
printf "\n%bUSAGE:" "${RED}${BOLD}"
printf "\n $(basename ${BASH_SOURCE[0]}) [OPTIONS]\n\nOPTIONS:"
printf "\n %-40s %s" "--target, t \"bosh target (micro...)\"" "Bosh director target"
printf "\n %-40s %s" "--deployment, -d \"deployment name\"" "Bosh deployment name"
printf "%b\n\n" "${STD}"
nbParameters=0 ; flagError=1
}

if [ ${flagError} = 0 ] ; then
flag_interactive=1
nbParameters=$#
while [ ${nbParameters} -gt 0 ] ; do
flag_interactive=0
case "$1" in
"-t"|"--target") BOSH_TARGET="$2" ; shift ; shift ; nbParameters=$#
if [ "${BOSH_TARGET}" = "" ] ; then
usage
fi ;;
"-d"|"--deployment") BOSH_DEPLOYMENT="$2" ; shift ; shift ; nbParameters=$#
if [ "${BOSH_DEPLOYMENT}" = "" ] ; then
usage
fi ;;
*) usage ;;
esac
done
fi

#--- Log to bosh director
if [ ${flagError} = 0 ] ; then
if [ ${flag_interactive} = 1 ] ; then
flag=0
while [ ${flag} = 0 ] ; do
flag=1
printf "\n%bDirector BOSH :%b\n\n" "${REVERSE}${GREEN}" "${STD}"
printf "%b1%b : micro\n" "${GREEN}${BOLD}" "${STD}"
printf "%b2%b : master\n" "${GREEN}${BOLD}" "${STD}"
printf "%b3%b : ops\n" "${GREEN}${BOLD}" "${STD}"
printf "%b4%b : coab\n" "${GREEN}${BOLD}" "${STD}"
printf "%b5%b : kubo\n" "${GREEN}${BOLD}" "${STD}"
printf "%b6%b : ondemand\n" "${GREEN}${BOLD}" "${STD}"
printf "%b7%b : expe\n" "${GREEN}${BOLD}" "${STD}"
printf "\n%bYour choice :%b " "${GREEN}${BOLD}" "${STD}" ; read choice
case "${choice}" in
1) BOSH_TARGET="micro" ;;
2) BOSH_TARGET="master" ;;
3) BOSH_TARGET="ops" ;;
4) BOSH_TARGET="coab" ;;
5) BOSH_TARGET="kubo" ;;
6) BOSH_TARGET="ondemand" ;;
7) BOSH_TARGET="expe" ;;
*) flag=0 ; clear ;;
esac
done
fi

#--- Check if bosh dns exists
export BOSH_ENVIRONMENT=$(host bosh-${BOSH_TARGET}.internal.paas | awk '{print $4}')
if [ "${BOSH_ENVIRONMENT}" = "found:" ] ; then
printf "\n\n%bERROR : Bosh director \"${BOSH_TARGET}\" unknown (no dns record).%b\n\n" "${RED}" "${STD}"
else
#--- Check if bosh director vm is available
#--- Check if bosh director instance is available
nc -vz -w 1 ${BOSH_ENVIRONMENT} 25250 > /dev/null 2>&1
if [ $? != 0 ] ; then
printf "\n\n%bERROR : Bosh director \"${BOSH_TARGET}\" unreachable.%b\n\n" "${RED}" "${STD}"
else
testToken=$(bosh env > /dev/null 2>&1)
#--- Check if token access expired, then log out
bosh env > /dev/null 2>&1
if [ $? != 0 ] ; then
#--- Token expired, log out
bosh log-out > /dev/null 2>&1
fi

userConnected=$(bosh env | grep "not logged in")
if [ "${userConnected}" != "" ] ; then
#--- Log into the director and list active deployments
bosh alias-env ${BOSH_TARGET} > /dev/null 2>&1
#--- Create bosh alias
bosh alias-env ${BOSH_TARGET} > /dev/null 2>&1

#--- Check if user is already connected
isUserConnected=$(bosh env | grep "not logged in")
if [ "${isUserConnected}" != "" ] ; then
printf "\n%bLDAP user and password :%b\n" "${REVERSE}${YELLOW}" "${STD}"
bosh log-in
if [ $? != 0 ] ; then
printf "\n\n%bERROR : Log to bosh director \"${BOSH_TARGET}\" failed.%b\n\n" "${RED}" "${STD}"
else
deployments=$(bosh deployments --column=Name | grep -vE "^Name$|^Succeeded$|^[0-9]* deployments$")
flagError=1
fi
fi

#--- Display selected bosh deployment status
if [ ${flagError} = 0 ] ; then
deployments=$(bosh deployments --column=Name | grep -vE "^Name$|^Succeeded$|^[0-9]* deployments$")
if [ ${flag_interactive} = 1 ] ; then
printf "\n%bSelect a specific deployment in the list, or suffix your bosh commands with -d <deployment_name>:%b\n%s" "${REVERSE}${YELLOW}" "${STD}" "${deployments}"
printf "\n\n%bYour choice (<Enter> to select none) :%b " "${GREEN}${BOLD}" "${STD}" ; read choice
if [ "${choice}" = "" ] ; then
printf "\n\n%bYour choice (<Enter> to select none) :%b " "${GREEN}${BOLD}" "${STD}" ; read BOSH_DEPLOYMENT
fi

if [ "${BOSH_DEPLOYMENT}" = "" ] ; then
unset BOSH_DEPLOYMENT
else
flag=$(echo "${deployments}" | grep "${BOSH_DEPLOYMENT}")
if [ "${flag}" = "" ] ; then
unset BOSH_DEPLOYMENT
else
flag=$(echo "${deployments}" | grep "${choice}")
if [ "${flag}" = "" ] ; then
unset BOSH_DEPLOYMENT
else
export BOSH_DEPLOYMENT="${choice}"
bosh instances
fi
export BOSH_DEPLOYMENT
bosh instances
fi
fi
fi
Expand Down
40 changes: 7 additions & 33 deletions bosh-cli/log-cf.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#===========================================================================
# Log with CF cli
# Log with cf cli
#===========================================================================

#--- Colors and styles
Expand All @@ -11,30 +11,6 @@ export STD='\033[0m'
export BOLD='\033[1m'
export REVERSE='\033[7m'

#--- Get a propertie value in credhub
getCredhubValue() {
value=$(credhub g -n $1 | grep 'value: ' | awk '{print $2}')
if [ $? = 0 ] ; then
echo "${value}"
else
printf "\n\n%bERROR : \"$2\" credhub value unknown.%b\n\n" "${RED}" "${STD}"
flagError=1
fi
}

#--- Log to credhub
flagError=0
flag=$(credhub f > /dev/null 2>&1)
if [ $? != 0 ] ; then
printf "\n%bEnter LDAP user and password :%b\n" "${REVERSE}${YELLOW}" "${STD}"
credhub api --server=https://credhub.internal.paas:8844 > /dev/null 2>&1
credhub login
if [ $? != 0 ] ; then
printf "\n%bERROR : Bad LDAP authentication.%b\n\n" "${RED}" "${STD}"
flagError=1
fi
fi

#--- Log to CF
if [ ${flagError} = 0 ] ; then
flag=0
Expand All @@ -47,13 +23,11 @@ if [ ${flagError} = 0 ] ; then
fi
done

SYSTEM_DOMAIN="$(getCredhubValue "/secrets/cloudfoundry_system_domain")"
if [ ${flagError} = 0 ] ; then
cf login -a https://api.${SYSTEM_DOMAIN} -u ${CF_USER}
if [ $? != 0 ] ; then
printf "\n%bERROR : Connexion failed.%b\n\n" "${RED}" "${STD}"
else
printf "\n\n"
fi
#--- Log to cf
cf login -a https://api.${SYSTEM_DOMAIN} -u ${CF_USER}
if [ $? = 0 ] ; then
printf "\n\n"
else
printf "\n%bERROR : Connexion failed.%b\n\n" "${RED}" "${STD}"
fi
fi
13 changes: 6 additions & 7 deletions bosh-cli/log-credhub.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@
#--- Colors and styles
export RED='\033[1;31m'
export YELLOW='\033[1;33m'
export GREEN='\033[1;32m'
export STD='\033[0m'
export BOLD='\033[1m'
export REVERSE='\033[7m'

#--- Log to credhub
flag=$(credhub f > /dev/null 2>&1)
if [ $? != 0 ] ; then
printf "%bEnter LDAP user and password :%b\n" "${REVERSE}${YELLOW}" "${STD}"
printf "\n%bEnter LDAP user and password :%b\n" "${REVERSE}${YELLOW}" "${STD}"
credhub api --server=https://credhub.internal.paas:8844 > /dev/null 2>&1
credhub login
if [ $? != 0 ] ; then
printf "\n%bERROR : Bad LDAP authentication.%b\n\n" "${RED}" "${STD}"
else
printf "username: " ; read LDAP_USER
credhub login -u ${LDAP_USER}
if [ $? = 0 ] ; then
printf "\n\n"
else
printf "\n%bERROR : Bad LDAP authentication with \"${LDAP_USER}\" account.%b\n\n" "${RED}" "${STD}"
fi
fi
Loading

0 comments on commit 068065c

Please sign in to comment.