version: 2
jobs:
  build:
    working_directory: ~/tdnm

    docker:
      - image: circleci/ruby:2.5-node
        environment:
          DATABASE_URL: postgres://postgres@127.0.0.1:5432/tdnm_test
          RAILS_ENV: test

      - image: circleci/postgres:10-alpine
        environment:
          POSTGRES_USER: postgres
          POSTGRES_DB: tdnm_test
          POSTGRES_PASSWORD: ''

    steps:
      - checkout

      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "Gemfile.lock" }}

      - run:
          name: Install dependencies
          command: bundle install --jobs=4 --retry=3 --path=vendor/bundle

      - save_cache:
          paths:
            - ./vendor/bundle
          key: v1-dependencies-{{ checksum "Gemfile.lock" }}

      - run:
          name: Wait for DB
          command: dockerize -wait tcp://localhost:5432 -timeout 1m

      - run:
          name: Setup Database
          command: bin/rails db:setup

      - run:
          name: Run tests
          command: bundle exec rake test

version: 2
jobs:
  build:
    working_directory: ~/tdnm

    docker:
      - image: circleci/ruby:2.5-node
        environment:
          DATABASE_URL: postgres://postgres@127.0.0.1:5432/tdnm_test
          RAILS_ENV: test

      - image: circleci/postgres:10-alpine
        environment:
          POSTGRES_USER: postgres
          POSTGRES_DB: tdnm_test
          POSTGRES_PASSWORD: ''

    steps:
      - checkout

      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "Gemfile.lock" }}

      - run:
          name: Install dependencies
          command: bundle install --jobs=4 --retry=3 --path=vendor/bundle

      - save_cache:
          paths:
            - ./vendor/bundle
          key: v1-dependencies-{{ checksum "Gemfile.lock" }}

      - run:
          name: Wait for DB
          command: dockerize -wait tcp://localhost:5432 -timeout 1m

      - run:
          name: Setup Database
          command: bin/rails db:setup

      - run:
          name: Run tests
          command: bundle exec rake test

  publish_docker_image:
    working_directory: ~/tdnm

    machine:
      docker_layer_caching: true

    steps:
      - checkout
      - run:
          command: docker build -t kenchan/tdnm:latest .
      - run:
          command: docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
      - run:
          command: docker push kenchan/tdnm:latest

workflows:
  version: 2
  build_and_publish:
    jobs:
      - build
      - publish_docker_image:
          requires:
            - build
#          filters:
#            branches:
#              only:
#                - master

Create docker image publish workflow
Create docker image publish workflow
