0

I am new to docker and I am trying to set up a QA environment of airflow(I already have a production). This is how I defined in the entrypoint.sh

#!/usr/bin/env bash

TRY_LOOP="20"
SLUGIFY_USES_TEXT_UNIDECODE=yes

BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$BRANCH" == 'master' ]
then
   "${REDIS_HOST:="airflow-celery.xxxxx.0001.use1.cache.amazonaws.com"}"
else [ "$BRANCH" == 'QA' ]
   "${REDIS_HOST:="qa-airflow-celery.xxxx.ng.0001.use1.cache.amazonaws.com"}"
fi

: "${REDIS_PORT:="6379"}"

if [ "$BRANCH" == 'master' ]
then
  "${POSTGRES_HOST:="airflow-database.xxxxx.us-east-1.rds.amazonaws.com"}"
  "${POSTGRES_USER:="airflow"}"
else [ "$BRANCH" == 'QA' ]
  "${POSTGRES_HOST:="qa-airflow-database.xxxxx.us-east-1.rds.amazonaws.com"}"
  "${POSTGRES_USER:="airflow"}"
fi

The build runs successfully but it throws a following error when I try to run the docker container and it never starts

/entrypoint.sh: line 6: git: command not found
/entrypoint.sh: line 11: qa-airflow-celery.xxxxx.ng.0001.use1.cache.amazonaws.com: command not found
/entrypoint.sh: line 21: qa-airflow-database.xxxxxxx.us-east-1.rds.amazonaws.com: command not found

I'd really appreciate If i can some help with it.

NAB0815
  • 441
  • 4
  • 24

1 Answers1

1

The last 2 errors happens because you have double quotes inside double quotes.

/entrypoint.sh: line 11: qa-airflow-celery.xxxxx.ng.0001.use1.cache.amazonaws.com: command not found
/entrypoint.sh: line 21: qa-airflow-database.xxxxxxx.us-east-1.rds.amazonaws.com: command not found  

I think you can get rid of the outer quotes in all your bash file

#!/usr/bin/env bash

TRY_LOOP="20"
SLUGIFY_USES_TEXT_UNIDECODE=yes

BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$BRANCH" == 'master' ]
then
   ${REDIS_HOST:="airflow-celery.xxxxx.0001.use1.cache.amazonaws.com"}
else [ "$BRANCH" == 'QA' ]
   ${REDIS_HOST:="qa-airflow-celery.xxxx.ng.0001.use1.cache.amazonaws.com"}
fi

: ${REDIS_PORT:="6379"}

if [ "$BRANCH" == 'master' ]
then
  ${POSTGRES_HOST:="airflow-database.xxxxx.us-east-1.rds.amazonaws.com"}
  ${POSTGRES_USER:="airflow"}
else [ "$BRANCH" == 'QA' ]
  ${POSTGRES_HOST:="qa-airflow-database.xxxxx.us-east-1.rds.amazonaws.com"}
  ${POSTGRES_USER:="airflow"}
fi  

If this doesn't work, go with this solution
https://stackoverflow.com/a/35586785/7804876

The first error is because airflow's image does not contain git.

/entrypoint.sh: line 6: git: command not found

The easy way is to add to entrypoint.sh file the git installation command as the first line. For Debian distribution:

apt install -y git

If RHEL distribution:

yum -y install git

The downside of this approach is that the installation takes some time.
You better add git dependency to the image:

  1. Run the image with your docker run command but without --entrypoint entrypoint.sh.
  2. Check container-id
    docker ps
    For the sake of the example the container-id is c3f279d17e0a
  3. docker exec -it c3f279d17e0a bash
  4. Install git manually with apt/yum as mentioned above, then detach the bash by typing ctrl+p and ctrl+q after each other.
  5. Commit new image
    docker commit c3f279d17e0a airflow-git:version1

    It can be useful to commit a container’s file changes or settings into a new image. This allows you to debug a container by running an interactive shell, or to export a working dataset to another server. Generally, it is better to use Dockerfiles to manage your images in a documented and maintainable way.

https://docs.docker.com/engine/reference/commandline/commit/

Now your have the image airflow-git:version1, run it with your original run command with --entrypoint entrypoint.sh and it should work.

Ofek Hod
  • 3,544
  • 2
  • 15
  • 26