version: 2.1

jobs:
  build_docker:
    environment:
      TZ: "America/New_York"
      SCRATCH: "/scratch"
    docker:
      - image: docker:18.06.1-ce-git
    working_directory: /tmp/src/ANTs
    steps:
      - checkout
      - setup_remote_docker
      - run:
          name: Build Docker image
          no_output_timeout: 3h
          command: |
            # Build docker image
            e=1 && for i in {1..5}; do
              docker build \
                --rm=false \
                --label version="CircleCI automated build of commit ${CIRCLE_SHA1}" \
                -t antsx/ants:latest . \
              && e=0 && break || sleep 15
            done && [ "$e" -eq "0" ]
      - run:
          name: Deploy to Docker Hub
          no_output_timeout: 40m
          command: |
            if [[ -n "$DOCKER_PASS" ]] && [[ "${CIRCLE_BRANCH}" == "master" ]] ; then
              docker login -u $DOCKER_USER -p $DOCKER_PASS
              docker push antsx/ants:latest
            fi


workflows:
  version: 2
  build_and_deploy:
    jobs:
      - build_docker:
          filters:
            tags:
              only: /.*/

version: 2.1

jobs:
  build_docker:
    docker:
      - image: docker:18.06.1-ce-git
    working_directory: /tmp/src/ANTs
    steps:
      - checkout
      - setup_remote_docker
      - run:
          name: Build Docker image
          no_output_timeout: 3h
          environment:
            TZ: "America/New_York"
            SCRATCH: "/scratch"
          command: |
            # Build docker image
            e=1 && for i in {1..5}; do
              docker build \
                --rm=false \
                --label version="CircleCI automated build of commit ${CIRCLE_SHA1}" \
                -t antsx/ants:latest . \
              && e=0 && break || sleep 15
            done && [ "$e" -eq "0" ]
      - run:
          name: Deploy to Docker Hub
          no_output_timeout: 40m
          command: |
            if [[ -n "$DOCKER_PASS" ]] && [[ "${CIRCLE_BRANCH}" == "master" ]] ; then
              docker login -u $DOCKER_USER -p $DOCKER_PASS
              docker push antsx/ants:latest
            fi


workflows:
  version: 2
  build_and_deploy:
    jobs:
      - build_docker:
          filters:
            tags:
              only: /.*/

Set Docker container creation timezone
ENH: Set Docker container creation timezone
