version: 2
jobs:
  build:
    working_directory: ~/tmp
    docker:
      - image: adharaprojects/basic-docker-base:0.0.0
        restart: on-failure # Restart the container if it exits due to an error
        environment:
          MAX_HEAP_SIZE: 2048m
          HEAP_NEWSIZE: 512m
    steps:
      - checkout
      - setup_remote_docker

      - run:
          name: Build the the act-client image for the tests
          command: |
            docker build -t agmanchon/actimageclientdocker:1.0.0 .

      - run:
          name: Start supporting infrastructure
          command: |
            docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
            docker-compose -f ./docker/docker-compose.yml up -d

      - run:
          name: Wait for ACT is connected and then run the tests
          command: |
            sleep 200
            docker exec -it actcontainerclientdocker_1.0.0 npm test

      - run:
          name: Cleanup remote docker
          command: |
            docker stop actcontainerdockerfx_1.0.4_s1 actcontainerclientdocker_1.0.0
            docker rm actcontainerdockerfx_1.0.4_s1 actcontainerclientdocker_1.0.0

workflows:
  version: 2
  my-workflow:
    jobs:
      - build:
          context: cash_tokenizer_ci
