我正在尝试通过对lambda函数的开玩笑的测试来设置gitlab,并且我可以使测试在我的本地docker中完全正常运行。当我在gitlab Runner上运行它时,即使它与dynamoDB通信,也会收到超时错误,即使它从数据库中获取所需的数据也可以在本地正常工作。有人能告诉我从工作的docker到不工作的gitlab-ci有什么区别吗?
这是我的docker-compose.yml
version: '3'
services:
dynamodb:
image: craftyx/dynamodb-inmemory
ports:
- 8000:8000
server:
build: .
depends_on:
- dynamodb
command:
- jest
这是我的Dockerfile
FROM node:8
WORKDIR /app
COPY package.json package.json
USER root
RUN npm install && npm install -g serverless jest
RUN serverless config credentials --provider aws --key 1 --secret 1
COPY serverless.yml serverless.yml
COPY resources resources
RUN serverless dynamodb install
COPY . .
相比之下,这是我的.gitlab-ci.yml文件。我将码头工人保持不变
image: node:8
services:
- name: craftyx/dynamodb-inmemory
alias: dynamodb
cache:
paths:
- backend/node_modules/
before_script:
- apt-get update -qq && apt-get install
- sudo npm install -g serverless
stages:
- build
- test
Build:
stage: build
before_script:
- cd backend
script:
- npm install -g serverless
- npm install
Test:
stage: test
before_script:
- cd backend
- npm install
- npm install -g jest serverless
- serverless config credentials --provider aws --key 1 --secret 2
- serverless dynamodb install
- sleep 5
script:
- jest
这是有问题的测试。我有一个beforeAll调用,该调用运行一个查询,该查询将测试数据批量插入dynamoDB中。
const checkQueryMutation = async ({ name, query, finResponse, finErrors }, aToken) => {
const header = {};
const event = genEvent(query, header);
const response = await handler(event, context);
const { procResp, procErrors } = getData(name, response);
expect(procResp).toEqual(finResponse);
expect(procErrors).toEqual(finErrors);
return procResp;
};
beforeAll(async done => {
await checkQueryMutation(cleanMigrate);
console.log('all done');
done();
});
describe('lambda integration tests', () => test('test', () => expect(1).toEqual(1)));