CircleCI DynamoDB 本地

CircleCI DynamoDB Local

我正在尝试设置它,以便 CircleCI 可以在我的测试中使用 DynamoDB Local。我看到 this link 关于如何在 CircleCI 上安装 DynamoDB Local 但它看起来已经过时了,因为他们现在已经使用 CircleCI 2 迁移到新语法。

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

您可以使用构建步骤 'command' 将旧指令改编为新指令。由于我不熟悉该软件,您将不得不尝试一下才能使其正常工作:

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

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

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