version: 0.2

phases:
  pre_build:
    commands:
      #- echo Logging in to docker hub...
      - docker login -u $DOCKER_LOGIN_USERNAME -p $DOCKER_LOGIN_PASSWORD
  build:
    commands:
      - echo Build started on `date`
      - echo Building the Docker image...
      - docker pull $IMAGE_REPO_NAME:$IMAGE_TAG || true
      - docker build . -f ./Dockerfile -t $IMAGE_REPO_NAME:$IMAGE_TAG --cache-from $IMAGE_REPO_NAME:$IMAGE_TAG
      - docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $IMAGE_REPO_NAME:$IMAGE_TAG
      - printenv
  post_build:
    commands:
      - echo Build completed on `date`
      - echo Pushing the Docker image...
      - docker push $IMAGE_REPO_NAME:$IMAGE_TAG