CircleCI DynamoDB Local

时间:2017-07-30 21:31:41

标签: amazon-dynamodb circleci

我试图让它设置好,所以CircleCI可以在我的测试中使用DynamoDB Local。我看到了关于如何在CircleCI上安装DynamoDB Local的this链接,但它看起来已经过时,因为它们现在已经转移到使用CircleCI 2的新语法。

如何在最新版本的CircleCI上实现这一目标?

2 个答案:

答案 0 :(得分:2)

您可以使用构建步骤'命令'将旧指令调整为新指令。由于我不熟悉该软件,您将不得不使用它来使其工作:

version: 2
jobs:
   build: 
     docker:
        - image: some-docker-image-that-has-java-or-even-dynamodb
     steps: 
        - stuff (usually 'checkout')  
        - run: 
           name: install java
           command: |
              apt-get update && apt-get install default-jre default-jdk
        - run:
           name: setup container
           command: |
              curl -k -L -o dynamodb-local.tgz http://dynamodb-local.s3-website-us-west-2.amazonaws.com/dynamodb_local_latest.tar.gz
              tar -xzf dynamodb-local.tgz
              java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb

答案 1 :(得分:1)

这是一个工作端到端的circleci config.yml文件,适用于nodejs项目版本8和dynamodb local:

version: 2

references:
  container_config: &container_config
    docker:
      - image: circleci/node:8

    working_directory: ~/repo

  restore_repo: &restore_repo
    restore_cache:
      keys:
        - repo-v1-{{ .Branch }}-{{ .Revision }}
        - repo-v1-{{ .Branch }}
        - repo-v1-

  restore_npm_install: &restore_npm_install
    restore_cache:
      keys:
        - node_modules-v1-cache-{{ checksum "package.json" }}
        # fallback to using the latest cache if no exact match is found
        - node_modules-v1-cache

  restore_dynamodb_local: &restore_dynamodb_local
    restore_cache:
      keys:
        - dynamodblocal-v1

jobs:
  checkout_code:
    <<: *container_config
    steps:
      - *restore_repo
      - checkout
      - save_cache:
          key: repo-v1-{{ .Branch }}-{{ .Revision }}
          paths:
            - .

  dynamodb_local_setup:
    <<: *container_config
    steps:
      - *restore_repo
      - *restore_dynamodb_local
      - run:
          name: "Downlad and install"
          command: |
            mkdir -p dynamodb_local
            cd dynamodb_local
            curl -k -L -o dynamodb-local.tgz http://dynamodb-local.s3-website-us-west-2.amazonaws.com/dynamodb_local_latest.tar.gz
            tar -xzf dynamodb-local.tgz
            cd ..
      - save_cache:
          key: dynamodblocal-v1
          paths:
            - ./dynamodb_local


  npm_install:
    <<: *container_config
    steps:
      - *restore_repo
      - *restore_npm_install
      - run:
          name: "npm install"
          command: npm install --update-binary
      - save_cache:
          key: node_modules-v1-cache-{{ checksum "package.json" }}
          paths:
            - ./node_modules

  lint:
    <<: *container_config
    steps:
      - *restore_repo
      - *restore_npm_install
      - run:
          name: "Linting"
          command: npm run lint -- --format junit -o reports/junit/js-lint-results.xml

  test:
    <<: *container_config
    steps:
      - *restore_repo
      - *restore_npm_install
      - *restore_dynamodb_local
      - run:
          name: "Test suite execution"
          # Because "CredentialsError: Missing credentials in config"
          # AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are mandatory to access dynamodblocal, you can set fake ones on circleci project configuration
          command: |
            sudo apt-get install default-jre --assume-yes
            java -Djava.library.path=./dynamodb_local/DynamoDBLocal_lib -jar ./dynamodb_local/DynamoDBLocal.jar -port 2018 -inMemory &
            ./node_modules/jest/bin/jest.js --ci --testResultsProcessor="jest-junit" --collectCoverage --coverageReporters="lcov"
          environment:
            JEST_JUNIT_OUTPUT: "reports/junit/js-test-results.xml"
      - run:
          name: "Report to codecov.io"
          command: ./node_modules/codecov/bin/codecov

      - store_test_results: #along with linting results
          path: reports/junit

      - store_artifacts:
          path: reports/junit

      - store_artifacts:
          path: coverage

workflows:
  version: 2
  main:
    jobs:
      - checkout_code
      - dynamodb_local_setup:
          requires:
            - checkout_code
      - npm_install:
          requires:
            - checkout_code
      - lint:
          requires:
            - npm_install
      - test:
          requires:
            - npm_install
            - dynamodb_local_setup

最新的要点https://gist.github.com/HerveNivon/81563806680c9aab1e36c589e9ea7622