#!/bin/bash
if [ "$DATABASE" = "postgres" ]
then
echo "Waiting for postgres..."
while ! nc -z db 5432; do
sleep 0.1
done
echo "PostgreSQL started"
fi
if [ ! -d "/opt/app/thirdparty" ]
then
mkdir /opt/app/thirdparty
fi
if [ ! -d "/opt/app/tmp" ]
then
mkdir -p /opt/app/tmp/exports \
/opt/app/tmp/screenshots/thumbnails \
fi
if [ ! -d "/opt/app/thirdparty/EyeWitness" ]
then
echo "Cloning EyeWitness"
git clone https://github.com/FortyNorthSecurity/EyeWitness.git /opt/app/thirdparty/EyeWitness
fi
exec "$@"
I belive its because, when run this way git clone starts a sub process to download the files, and then exits the main process, and therefor runs your exec immediately, not sure how to fix it though.
This is how bash works. You can use multiline commands and in a Dockerfile you usually have to (there are other alternatives), but then you have to make sure it would be syntactically correct if you wrote it in one line. Letâs see, how that escaped part of the IF statement looks like in one line:
if [ ! -d "/opt/app/tmp" ]
then
mkdir -p /opt/app/tmp/exports /opt/app/tmp/screenshots/thumbnails fi
This way bash sees âfiâ as an other parameter for âmkdirâ.
If the entrypoint works for you, than you either use another script or you have a space after the last backslash so it does not escape the newline, but the space. The problem is I donât see space after that backslash here in the inserted code block (I tried to select the text to highlight it).
Then it is not your entrypoint. So there could be an & character somewhere after git clone so it runs in the background. This is why sharing the exact code is important. Or at least telling what part of the script is improvised and what part is not. Then we canât tell for sure what is wrong, but we can guess. One character could change everything.
appart of the sytax error that @rimelek pointed out, it should work. I do have entrypoint scripts that git pull repositories to keep them updated â it works like a charm. I would be surprised if git clone would be any different.
Overall, cloning a project appears like something you would rather want to do in your Dockerfile. The same is true for the folder creation. The only thing I would keep in the entrypoint script is the database availability check and of course the final exec "$@" command. Though, in case of postgres, you might be better off using pg_isready.