version: 2
jobs:
  build:
    docker:
      - image: circleci/golang:1-stretch-browsers-legacy
        environment:
          IMAGE_NAME: "sameersbn/gitlab"

    steps:
      - checkout

      - setup_remote_docker:
          version: 17.06.0-ce

      - run:
          name: Docker info
          command: |
            docker version
            docker info

      - restore_cache:
          keys:
            - cache-{{ .Branch }}
          paths:
            - /cache/layers.tar

      - run:
          name: Loading docker cache
          command: |
            if [[ -f /cache/layers.tar ]]; then
              docker load -i /cache/layers.tar
            fi

      - run:
          name: Build docker image
          command: |
            docker build --cache-from=${IMAGE_NAME} -t ${IMAGE_NAME} .

      - run:
          name: Launching container for testing
          command: |
            docker network create testnet
            docker run --name gitlab -d --net testnet ${IMAGE_NAME}

      - run:
          name: Testing image
          command: |
            echo "TODO"

      - run:
          name: Generate docker build image cache
          command: |
            mkdir -p /cache
            docker save -o /cache/layers.tar ${IMAGE_NAME}

      - save_cache:
          key: cache-{{ .Branch }}-{{ epoch }}
          paths:
            - /cache/layers.tar

workflows:
  version: 2
  build-and-test:
    jobs:
      - build

version: 2
jobs:
  build:
    docker:
      - image: circleci/golang:1-stretch-browsers-legacy
        environment:
          IMAGE_NAME: "sameersbn/gitlab"

    steps:
      - checkout

      - setup_remote_docker:
          version: 18.03.1-ce

      - run:
          name: Docker info
          command: |
            docker version
            docker info


      - restore_cache:
          keys:
            - cache-{{ .Branch }}
          paths:
            - /tmp/cache/layers.tar

      - run:
          name: Loading docker cache
          command: |
            if [[ -f /tmp/cache/layers.tar ]]; then
              echo "Loading cache ..."
              docker load -i /tmp/cache/layers.tar
              docker image ls
            else
              echo "Couldn't find any caches"
            fi

      - run:
          name: Build docker image
          command: |
            docker build --cache-from=${IMAGE_NAME} -t ${IMAGE_NAME} .

      - run:
          name: Launching container for testing
          command: |
            docker-compose up -d
            sleep 10

      - run:
          name: Testing image
          command: |
            docker run --network container:$(docker-compose ps -q gitlab) \
              appropriate/curl --retry 12 --retry-delay 5 --retry-connrefused http://localhost/explore

      - run:
          name: Generate docker build image cache
          command: |
            mkdir -p /tmp/cache/
            docker save -o /tmp/cache/layers.tar ${IMAGE_NAME}

      - save_cache:
          key: cache-{{ .Branch }}-{{ epoch }}
          paths:
            - /tmp/cache/layers.tar

workflows:
  version: 2
  build-and-test:
    jobs:
      - build

Add simple test if gitlab starts after the changes
Add simple test if gitlab starts after the changes

Signed-off-by: solidnerd <387783e228a6a981e052f1b545e5a6a45a21cc6e@mietz.io>
