Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
docker-php-starterkit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
docker-php-starterkit
Commits
ddd6ba58
Commit
ddd6ba58
authored
9 months ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
show info if there is no database container; speedup replacements
parent
40d822d2
Branches
Branches containing commit
No related tags found
1 merge request
!12
show info if there is no database container; speedup replacements
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docker/init.sh
+40
-20
40 additions, 20 deletions
docker/init.sh
with
40 additions
and
20 deletions
docker/init.sh
+
40
−
20
View file @
ddd6ba58
...
...
@@ -17,6 +17,7 @@
# 2023-12-07 v1.10 <www.axel-hahn.de> simplyfy console command; add php linter
# 2024-07-01 v1.11 <www.axel-hahn.de> diff with colored output; suppress errors on port check
# 2024-07-19 v1.12 <axel.hahn@unibe.ch> apply shell fixes
# 2024-07-22 v1.13 <axel.hahn@unibe.ch> show info if there is no database container; speedup replacements
# ======================================================================
cd
"
$(
dirname
"
$0
"
)
"
||
exit
1
...
...
@@ -33,7 +34,7 @@ _self=$( basename "$0" )
# git@git-repo.iml.unibe.ch:iml-open-source/docker-php-starterkit.git
selfgitrepo
=
"docker-php-starterkit.git"
_version
=
"1.1
2
"
_version
=
"1.1
3
"
# ----------------------------------------------------------------------
# FUNCTIONS
...
...
@@ -169,6 +170,23 @@ function _fix_no-db(){
fi
}
# helper functiion to generate replacements using sed
# it loops over all vars in the config file
# used in _generateFiles
function
_getreplaces
(){
# loop over vars to make the replacement
grep
"^[a-zA-Z]"
"
$_self
.cfg"
|
while
read
-r
line
do
# echo replacement: $line
mykey
=
$(
echo
"
$line
"
|
cut
-f
1
-d
'='
)
myvalue
=
"
$(
eval echo
\"\$
"
$mykey
"
\"
)
"
# TODO: multiline values fail here in replacement with sed
echo
-e
"s#{{
$mykey
}}#
${
myvalue
}
#g"
done
}
# loop over all files in templates subdir make replacements and generate
# a target file.
# It skips if
...
...
@@ -176,14 +194,14 @@ function _fix_no-db(){
# - target file has no updated lines
function
_generateFiles
(){
# re-read config vars
# shellcheck source=/dev/null
.
"
${
_self
}
.cfg"
||
exit
1
params
=
$(
_getreplaces |
while
read
-r
line
;
do
echo
-n
"-e '
$line
' "
;
done
)
local
_tmpfile
=
/tmp/newfilecontent
$$
.tmp
h2
"generate files from templates..."
for
mytpl
in
templates/
*
time
for
mytpl
in
templates/
*
do
# h3 $mytpl
local
_doReplace
=
1
...
...
@@ -207,19 +225,7 @@ function _generateFiles(){
local
_md5
;
_md5
=
$(
md5sum
$_tmpfile
|
awk
'{ print $1 }'
)
sed
-i
"s#{{generator}}#GENERATED BY
$_self
- template:
$mytpl
-
$_md5
#g"
$_tmpfile
# loop over vars to make the replacement
grep
"^[a-zA-Z]"
"
$_self
.cfg"
|
while
read
-r
line
do
# echo replacement: $line
mykey
=
$(
echo
"
$line
"
|
cut
-f
1
-d
'='
)
myvalue
=
"
$(
eval echo
\"\$
"
$mykey
"
\"
)
"
if
grep
"{{
$mykey
}}"
$_tmpfile
>
/dev/null
;
then
# TODO: multiline values fail here in replacement with sed
sed
-i
-e
"s#{{
$mykey
}}#
${
myvalue
}
#g"
$_tmpfile
fi
done
eval sed
-i
"
$params
"
"
$_tmpfile
"
||
exit
_fix_no-db
$_tmpfile
...
...
@@ -229,12 +235,12 @@ function _generateFiles(){
mkdir
-p
"
$(
dirname
../
"
$target
"
)
"
||
exit
2
mv
"
$_tmpfile
"
"../
$target
"
||
exit
2
echo
OK
echo
else
rm
-f
$_tmpfile
echo
"SKIP:
$mytpl
- Nothing to do."
fi
fi
echo
done
}
...
...
@@ -265,12 +271,26 @@ function _removeGeneratedFiles(){
# show running containers
function
_showContainers
(){
local
bLong
=
$1
local
_out
h2 CONTAINERS
if
[
-z
"
$bLong
"
]
;
then
_out
=
$(
if
[
-z
"
$bLong
"
]
;
then
docker-compose
-p
"
$APP_NAME
"
ps
else
docker ps |
grep
"
$APP_NAME
"
fi
)
if
[
"
$(
wc
-l
<<<
"
$_out
"
)
"
-eq
1
]
;
then
if
[
"
$DB_ADD
"
=
"false"
]
;
then
echo
"The web container is <
$APP_NAME
> is not running. This app has no database container."
else
echo
"No container is running for <
$APP_NAME
>."
fi
else
echo
"
$_out
"
if
[
"
$DB_ADD
"
=
"false"
]
;
then
echo
"INFO: This app has no database container."
fi
fi
}
...
...
@@ -340,7 +360,7 @@ while true; do
if
[
-z
"
$action
"
]
;
then
echo
echo
-e
"
\e
[32m
=====
INITIALIZER FOR DOCKER
APP [
$APP_NAME
] v
$_version
=====
\e
[0m
\n\r
"
echo
-e
"
\e
[32m
----===###|
INITIALIZER FOR DOCKER
v
$_version
|
$APP_NAME
|###===---
\e
[0m"
_showContainers
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment