diff --git a/docker/init.sh b/docker/init.sh index 3a7a17fc32c808ede20e08dd7355b9fe83ccf984..125816324e3ee6be7f7bd425e57831e931af25f1 100755 --- a/docker/init.sh +++ b/docker/init.sh @@ -1,7 +1,7 @@ #!/bin/bash # ====================================================================== # -# DOCKER DEV ENVIRONMENT :: INIT +# DOCKER PHP DEV ENVIRONMENT :: INIT # (work in progress) # # ---------------------------------------------------------------------- @@ -11,24 +11,30 @@ cd $( dirname $0 ) . $( basename $0 ).cfg +# git@git-repo.iml.unibe.ch:iml-open-source/docker-php-starterkit.git +selfgitrepo="docker-php-starterkit.git" + # ---------------------------------------------------------------------- # FUNCTIONS # ---------------------------------------------------------------------- +# draw a headline 2 function h2(){ echo echo -e "\e[33m>>>>> $*\e[0m" } + +# draw a headline 3 function h3(){ echo echo -e "\e[34m----- $*\e[0m" } -function _gitinstall(){ - h2 "install/ update app from git repo ${gitrepo} in ${gittarget} ..." - test -d ${gittarget} && ( cd ${gittarget} && git pull ) - test -d ${gittarget} || git clone -b ${gitbranch} ${gitrepo} ${gittarget} -} +# function _gitinstall(){ +# h2 "install/ update app from git repo ${gitrepo} in ${gittarget} ..." +# test -d ${gittarget} && ( cd ${gittarget} && git pull ) +# test -d ${gittarget} || git clone -b ${gitbranch} ${gitrepo} ${gittarget} +# } # set acl on local directory function _setWritepermissions(){ @@ -38,7 +44,6 @@ function _setWritepermissions(){ typeset -i local _user_uid=0 test -f /etc/subuid && _user_uid=$( grep $_user /etc/subuid 2>/dev/null | cut -f 2 -d ':' )-1 typeset -i local DOCKER_USER_OUTSIDE=$_user_uid+$DOCKER_USER_UID - # echo $DOCKER_USER_OUTSIDE set -vx # remove current acl @@ -52,6 +57,23 @@ function _setWritepermissions(){ set +vx } +# cleanup starterkit git data +function _removeGitdata(){ + h2 "Remove git data from starterkit" + echo -n "Current git remote url: " + git config --get remote.origin.url + git config --get remote.origin.url 2>/dev/null | grep $selfgitrepo >/dev/null + if [ $? -eq 0 ]; then + echo + echo -n "Delete local .git and .gitignore? [y/N] > " + read answer + test "$answer" = "y" && ( echo "Deleting ... " && rm -rf ../.git ../.gitignore ) + else + echo "It was done already - $selfgitrepo was not found." + fi + +} + # helper function: cut a text file starting from database start marker # see _generateFiles() function _fix_no-db(){ @@ -88,10 +110,6 @@ function _generateFiles(){ echo SKIP: $mytpl - target was not found in 1st line _doReplace=0 fi - # if [ -f "../$target" ]; then - # echo SKIP: target file already exists: $target - # _doReplace=0 - #fi # write generated files to target if [ $_doReplace -eq 1 ]; then @@ -166,46 +184,34 @@ function _showContainers(){ docker ps | grep $APP_NAME fi } -function _showContainers__(){ - local line= - local bLong=$1 - # typeset -i iCounter=0 - h2 CONTAINERS - docker ps | grep $APP_NAME | while read line - do - # iCounter=$iCounter+1 - if [ -z "$bLong" ]; then - echo $line | awk '{ print "NAME [" $12 "] " $7" "$8" "$9 }' - else - # echo $line | awk '{ print "IMAGE " $2 " ID " $1 ": " $7" "$8" "$9 " | PORTS: " $10 " " $11 }' - echo $line | awk '{ print "NAME [" $12 "]" }' - echo $line | awk '{ print " STATUS: " $7" "$8" "$9 }' - echo $line | awk '{ print " IMAGE : " $2 }' - echo $line | awk '{ print " ID : " $1 }' - echo $line | awk '{ print " PORTS : " $10 " " $11 }' - echo - fi - done - # test $iCounter -eq 0 && echo "NO CONTAINER IS RUNNING" -} # a bit stupid ... i think I need to delete it. function _showInfos(){ _showContainers long h2 INFO + + h3 "processes" docker-compose top + + h3 "Check app port" + >/dev/tcp/localhost/${APP_PORT} 2>/dev/null && ( + echo "OK, app port ${APP_PORT} is reachable" + echo + echo "In a web browser open:" + echo " $frontendurl" + ) + h3 "Check database port" + >/dev/tcp/localhost/${DB_PORT} 2>/dev/null && ( + echo "OK, db port ${DB_PORT} is reachable" + echo + echo "In a local DB admin tool:" + echo " host : localhost" + echo " port : ${DB_PORT}" + echo " user : root" + echo " password: ${MYSQL_ROOT_PASS}" + ) echo - echo "In a web browser:" - echo -n " $frontendurl" - wget -O /dev/null -S $frontendurl 2>/dev/null && echo " ... OK, frontend is reachable" - echo - echo "In a local DB admin tool:" - echo " host : localhost" - echo " port : ${DB_PORT}" - echo " user : root" - echo " password: ${MYSQL_ROOT_PASS}" - echo } function _wait(){ @@ -216,8 +222,6 @@ function _wait(){ # MAIN # ---------------------------------------------------------------------- - - action=$1 while true; do @@ -229,16 +233,17 @@ while true; do _showContainers h2 MENU - echo " i - init application; set permissions" + echo " g - remove git data of starterkit" + echo + echo " i - init application: set permissions" echo " t - generate files from templates" echo " T - remove generated files" echo - echo " m - more infos" - echo echo " u - startup containers docker-compose up -d" echo " s - shutdown containers docker-compose stop" echo " r - remove containers docker-compose rm -f" echo + echo " m - more infos" echo " c - console (bash)" echo echo -n " select >" @@ -246,6 +251,9 @@ while true; do fi case "$action" in + g) + _removeGitdata + ;; i) # _gitinstall _setWritepermissions diff --git a/readme.md b/readme.md index 600dbe5ccdda18a9747eeae4a89550bbd917ddff..0b94813de1c7068625d3aadbdfb7462f27a44ba6 100755 --- a/readme.md +++ b/readme.md @@ -3,6 +3,8 @@ Free software and Open Source from University of Bern :: IML - Institute of Medical Education +Repo: <https://git-repo.iml.unibe.ch/iml-open-source/docker-php-starterkit> + - - - ## About this template ## @@ -21,7 +23,7 @@ The subdir ```./public_html/``` will be mounted as webroot that you can edit fil ### Create a new project folder ### -Copy folder to a new name: ```cp -r template-php my-new-php-app; cd my-new-php-app``` and remove the ```.git``` folder in it ```rm -rf .git -gitignore``` +Copy folder to a new name: ```cp -r template-php my-new-php-app; cd my-new-php-app``` The initial file structure looks like this: @@ -38,7 +40,7 @@ The initial file structure looks like this: │ ├── readme.md │ ├── vhost_app.conf │ └── web-server-Dockerfile -├── public_html # your webroot for your data +├── public_html # your webroot for your project │ └── index.php └── readme.md ``` @@ -58,9 +60,10 @@ The initial file structure looks like this: ### First start ### * start init script in the docker folder: ```./docker/init.sh``` + * use "g" to remove git data of the starterkit * use "i" for init ... it sets an ACL on the ./public_html/ subdir to allow write access for your current user and the apache user in the docker container * use "t" to generate config files from templates with the settings from ./docker/init.sh.cfg -* use "u" to bring up the container (OR run ```docker-compose up -d``` ) + * use "u" to bring up the container (OR run ```docker-compose up -d``` ) ### Edit files ###