'command' is executed before 'entrypoint' is executed

my docker-compose.yml

  celery_worker:
    build:
      context: .
    restart: always
    entrypoint: /opt/app/celery_entrypoint.sh
    command: celery --config=app.celeryconfig -A app.celery_run.celery worker --loglevel=info --concurrency=5
    volumes:
      - .:/opt/app    
    env_file:
      - .env
    environment:
      - FLASK_APP=app
      - FLASK_ENV=development
      - CELERY_BROKER=redis://redis:6379/0
      - CELERY_BACKEND=redis://redis:6379/0
    depends_on:
      - redis
      - db

the ‘entrypoint’ contains the git clone which takes about 1 minute, but celery in ‘command’ starts without waiting for execution

how to fix this?

Hi

What is in your entrypoint script?

Because the command is arguments to the entrypoint script.

So what you’re doing is:

/opt/app/celery_entrypoint.sh celery --config=app.celeryconfig -A app.celery_run.celery worker --loglevel=info --concurrency=5
1 Like

hi
my entrypoint script

#!/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.

hm
thanks for the answer
I will think about it

Is “this way” related to running it from Docker Compose?

On a Mac without using Compose, a basic script running the following certainly waits for git clone to be done before running echo done:

echo start
git clone https://github.com/FortyNorthSecurity/EyeWitness.git
echo done

@fz11 just to be sure: you know for sure that the clone is started and still running?

I belive when you run it non-interactive, fx. if you add that script to cron, i dont think you will the same result.
But i can also be wrong! :smiley:

yep
check docker-compose logs -f

Are you sure this script you shared is what you use? Because it couldn’t work

if [ ! -d "/opt/app/tmp" ]
then
  mkdir -p /opt/app/tmp/exports \
  /opt/app/tmp/screenshots/thumbnails \
fi

There is a backslash escaping the newline before closing the “if” with “fi” and there is no “;” so it is a syntax error.

1 Like

sooo
it works fine.
why couldn’t you do it? are you sure you are using *nix like systems?

I will pretend I didn’t read it :slight_smile:

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).

I didn’t copy this code, I just wrote it here, ignore spaces and so on))

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.

1 Like

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.