Skip to content
Snippets Groups Projects
Commit fb06b905 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

update init: remove git data

parent 4fde9876
No related branches found
No related tags found
No related merge requests found
#!/bin/bash #!/bin/bash
# ====================================================================== # ======================================================================
# #
# DOCKER DEV ENVIRONMENT :: INIT # DOCKER PHP DEV ENVIRONMENT :: INIT
# (work in progress) # (work in progress)
# #
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
...@@ -11,24 +11,30 @@ ...@@ -11,24 +11,30 @@
cd $( dirname $0 ) cd $( dirname $0 )
. $( basename $0 ).cfg . $( basename $0 ).cfg
# git@git-repo.iml.unibe.ch:iml-open-source/docker-php-starterkit.git
selfgitrepo="docker-php-starterkit.git"
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# FUNCTIONS # FUNCTIONS
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# draw a headline 2
function h2(){ function h2(){
echo echo
echo -e "\e[33m>>>>> $*\e[0m" echo -e "\e[33m>>>>> $*\e[0m"
} }
# draw a headline 3
function h3(){ function h3(){
echo echo
echo -e "\e[34m----- $*\e[0m" echo -e "\e[34m----- $*\e[0m"
} }
function _gitinstall(){ # function _gitinstall(){
h2 "install/ update app from git repo ${gitrepo} in ${gittarget} ..." # h2 "install/ update app from git repo ${gitrepo} in ${gittarget} ..."
test -d ${gittarget} && ( cd ${gittarget} && git pull ) # test -d ${gittarget} && ( cd ${gittarget} && git pull )
test -d ${gittarget} || git clone -b ${gitbranch} ${gitrepo} ${gittarget} # test -d ${gittarget} || git clone -b ${gitbranch} ${gitrepo} ${gittarget}
} # }
# set acl on local directory # set acl on local directory
function _setWritepermissions(){ function _setWritepermissions(){
...@@ -38,7 +44,6 @@ function _setWritepermissions(){ ...@@ -38,7 +44,6 @@ function _setWritepermissions(){
typeset -i local _user_uid=0 typeset -i local _user_uid=0
test -f /etc/subuid && _user_uid=$( grep $_user /etc/subuid 2>/dev/null | cut -f 2 -d ':' )-1 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 typeset -i local DOCKER_USER_OUTSIDE=$_user_uid+$DOCKER_USER_UID
# echo $DOCKER_USER_OUTSIDE
set -vx set -vx
# remove current acl # remove current acl
...@@ -52,6 +57,23 @@ function _setWritepermissions(){ ...@@ -52,6 +57,23 @@ function _setWritepermissions(){
set +vx 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 # helper function: cut a text file starting from database start marker
# see _generateFiles() # see _generateFiles()
function _fix_no-db(){ function _fix_no-db(){
...@@ -88,10 +110,6 @@ function _generateFiles(){ ...@@ -88,10 +110,6 @@ function _generateFiles(){
echo SKIP: $mytpl - target was not found in 1st line echo SKIP: $mytpl - target was not found in 1st line
_doReplace=0 _doReplace=0
fi fi
# if [ -f "../$target" ]; then
# echo SKIP: target file already exists: $target
# _doReplace=0
#fi
# write generated files to target # write generated files to target
if [ $_doReplace -eq 1 ]; then if [ $_doReplace -eq 1 ]; then
...@@ -166,45 +184,33 @@ function _showContainers(){ ...@@ -166,45 +184,33 @@ function _showContainers(){
docker ps | grep $APP_NAME docker ps | grep $APP_NAME
fi 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. # a bit stupid ... i think I need to delete it.
function _showInfos(){ function _showInfos(){
_showContainers long _showContainers long
h2 INFO h2 INFO
h3 "processes"
docker-compose top 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
echo "In a web browser:" echo "In a web browser open:"
echo -n " $frontendurl" echo " $frontendurl"
wget -O /dev/null -S $frontendurl 2>/dev/null && echo " ... OK, frontend is reachable" )
h3 "Check database port"
>/dev/tcp/localhost/${DB_PORT} 2>/dev/null && (
echo "OK, db port ${DB_PORT} is reachable"
echo echo
echo "In a local DB admin tool:" echo "In a local DB admin tool:"
echo " host : localhost" echo " host : localhost"
echo " port : ${DB_PORT}" echo " port : ${DB_PORT}"
echo " user : root" echo " user : root"
echo " password: ${MYSQL_ROOT_PASS}" echo " password: ${MYSQL_ROOT_PASS}"
)
echo echo
} }
...@@ -216,8 +222,6 @@ function _wait(){ ...@@ -216,8 +222,6 @@ function _wait(){
# MAIN # MAIN
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
action=$1 action=$1
while true; do while true; do
...@@ -229,16 +233,17 @@ while true; do ...@@ -229,16 +233,17 @@ while true; do
_showContainers _showContainers
h2 MENU 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 - generate files from templates"
echo " T - remove generated files" echo " T - remove generated files"
echo echo
echo " m - more infos"
echo
echo " u - startup containers docker-compose up -d" echo " u - startup containers docker-compose up -d"
echo " s - shutdown containers docker-compose stop" echo " s - shutdown containers docker-compose stop"
echo " r - remove containers docker-compose rm -f" echo " r - remove containers docker-compose rm -f"
echo echo
echo " m - more infos"
echo " c - console (bash)" echo " c - console (bash)"
echo echo
echo -n " select >" echo -n " select >"
...@@ -246,6 +251,9 @@ while true; do ...@@ -246,6 +251,9 @@ while true; do
fi fi
case "$action" in case "$action" in
g)
_removeGitdata
;;
i) i)
# _gitinstall # _gitinstall
_setWritepermissions _setWritepermissions
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
Free software and Open Source from University of Bern :: IML - Institute of Medical Education 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 ## ## About this template ##
...@@ -21,7 +23,7 @@ The subdir ```./public_html/``` will be mounted as webroot that you can edit fil ...@@ -21,7 +23,7 @@ The subdir ```./public_html/``` will be mounted as webroot that you can edit fil
### Create a new project folder ### ### 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: The initial file structure looks like this:
...@@ -38,7 +40,7 @@ The initial file structure looks like this: ...@@ -38,7 +40,7 @@ The initial file structure looks like this:
│ ├── readme.md │ ├── readme.md
│ ├── vhost_app.conf │ ├── vhost_app.conf
│ └── web-server-Dockerfile │ └── web-server-Dockerfile
├── public_html # your webroot for your data ├── public_html # your webroot for your project
│ └── index.php │ └── index.php
└── readme.md └── readme.md
``` ```
...@@ -58,6 +60,7 @@ The initial file structure looks like this: ...@@ -58,6 +60,7 @@ The initial file structure looks like this:
### First start ### ### First start ###
* start init script in the docker folder: ```./docker/init.sh``` * 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 "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 "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``` )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment