CircleCI DynamoDB Local

六眼飞鱼酱① 提交于 2021-02-08 04:29:12

问题


I'm trying to get it setup so CircleCI can use DynamoDB Local in my tests. I saw this link about how to install DynamoDB Local on CircleCI but it looks outdated since they have now moved to new syntax with CircleCI 2.

How can I achieve this on the latest versions of CircleCI?


回答1:


You can adapt the old instructions into the new, using the build step 'command'. You will have to play with it a bit to get it to work as I'm not familiar with the software:

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



回答2:


Here is a working end to end circleci config.yml file that works for a nodejs project version 8 and 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

Last up to date gist https://gist.github.com/HerveNivon/81563806680c9aab1e36c589e9ea7622



来源:https://stackoverflow.com/questions/45404898/circleci-dynamodb-local

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!