Checking the output of docker logs inside a bats script

490 Views Asked by At

I have a strange issue. I have a bats shell script which i am using for testing . In the script i build and image and then run the container and in my test command i am just running a dummy Python script.

Everything works as expected only i do not see the output of docker logs command . I am really puzzled as to what may be the issue.

This is my bats file contents:

#!/usr/bin/env bats

setup() {
  echo "-----STARTING THE SETUP PROCESS-----" >&3

  DOCKER_IMAGE=${DOCKER_IMAGE:="bats-test"}
  BATS_ENV_FILE=${BATS_ENV_FILE:="bats-env.env"}
  CONTAINER_NAME=${CONTAINER_NAME:="bats-test-container"}

  echo "Building image..." >&3
  docker build --build-arg PIP_EXTRA_INDEX_URL=$PIP_EXTRA_INDEX_URL -t ${DOCKER_IMAGE}:bats-test . >&3


  echo "Running docker container..." >&3
  docker container run --rm -itd --name ${CONTAINER_NAME} -p 8000:8000 --env-file ${BATS_ENV_FILE} bats-test:bats-test >&3

  docker ps >&3

  echo "Checking docker container logs..." >&3
  docker logs ${CONTAINER_NAME} 2>&1 >&3
}


@test "Test that docker service responds to requests" {
    python test.py >&3
    status=`echo $?`  
    echo "Status: $status" >&3
    [ "$status" -eq 0 ]
}

teardown() {
  echo "-----STARTING THE TEARDOWN PROCESS-----" >&3

  echo "Stopping docker container ..." >&3
  docker container stop $(docker container ls -aq) >&3

  echo "Remove the unused image..." >&3
  docker rmi bats-test:bats-test >&3

  if test -f "${BATS_ENV_FILE}"; then
      echo "${BATS_ENV_FILE} exists ... removing it." >&3
      rm ${BATS_ENV_FILE}
  fi
}

Can someone please help me here on where i am going wrong . Is there something special that i have to do to get the docker logs output out of a shell script.

Many thanks in advance.

0

There are 0 best solutions below