我想创建一个由Circle CI进行集成测试的数据库,这是.config.yml Circle CI配置
version: 2 # use CircleCI 2.0
jobs: # a collection of steps
build: # runs not using Workflows must have a `build` job as entry point
docker: # run the steps with Docker
- image: circleci/node:10.15.0
environment:
POSTGRES_HOST: 'postgresql://postgres:password@localhost:5432/testdb'
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: testdb
# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
- image: circleci/redis:latest
- image: mdillon/postgis
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: testdb
working_directory: ~/nodejs_typescript
steps: # a collection of executable commands
- checkout
- run:
name: update-npm
command: 'sudo npm install -g npm@latest'
# Download and cache dependencies
- restore_cache: # special step to restore the dependency cache
# Read about caching dependencies: https://circleci.com/docs/2.0/caching/
key: dependency-cache-{{ checksum "package.json" }}
- run:
name: install-npm-wee
command: npm install
- save_cache:
name: Save-Cache
paths:
- './node_modules'
key: dependency-cache-{{ checksum "package.json"}}
- run:
name: install-global-knex
command: sudo npm install -g knex
- run: sudo apt-get update
- run: sudo apt-get install postgresql-client-9.6 -y
- run:
name: Create database
command: psql -U postgres -h localhost -p 5432 -tc "SELECT 1 FROM pg_database WHERE datname = 'testdb'" | grep -q 1 || psql -U postgres -h localhost -p 5432 -c "CREATE DATABASE testdb"
- run:
name: Knex Migrations
command: knex migrate:latest --knexfile src/knexfile.ts --env test
environment:
NODE_ENV: test
- run:
name: Knex seeds
command: knex seed:run --knexfile src/knexfile.ts --env test
environment:
NODE_ENV: test
- run: # run tests
name: test
command: npm run test
environment:
NODE_ENV: test
但是运行命令knex migrate:latest --knexfile src/knexfile.ts --env test
时构建已损坏,这是错误
使用环境:测试 错误:getaddrinfo ENOTFOUND postgresql:// postgres:password @ localhost:5432 / testdb postgresql:// postgres:password @ localhost:5432 / testdb:5432 在GetAddrInfoReqWrap.onlookup上(作为完成时)(dns.js:57:26) 以代码1退出
我不知道为什么我不能从knex运行迁移,有人可以帮我吗