Skip to content

Commit 70f596b

Browse files
chore: containerize contract test
1 parent 986b90e commit 70f596b

File tree

8 files changed

+51
-20
lines changed

8 files changed

+51
-20
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
.git
21
.github
32
.nyc_output
43
dist/

.github/workflows/continuous_delivery.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,9 @@ jobs:
130130

131131
steps:
132132
- uses: actions/checkout@v2
133-
- name: Node.js Setup
134-
uses: actions/setup-node@v2
135-
- name: Installation of Node.js dependencies
136-
run: npm ci
133+
- run: docker-compose build test-contract
137134
- name: Run contract test
138-
run: npm run test:contract
135+
run: make test-contract
139136
env:
140137
PACT_BROKER_BASE_URL: https://paulogoncalves.pactflow.io
141138
PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }}
@@ -174,8 +171,9 @@ jobs:
174171
DOCKER_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
175172
DOCKER_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}
176173
run: npx semantic-release
174+
- run: docker-compose build test-contract
177175
- name: Run contract test
178-
run: npm run test:contract
176+
run: make test-contract
179177
env:
180178
PACT_BROKER_BASE_URL: https://paulogoncalves.pactflow.io
181179
PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }}

.github/workflows/continuous_integration.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,9 @@ jobs:
138138
- uses: actions/checkout@v2
139139
with:
140140
ref: ${{ github.event.pull_request.head.sha }}
141-
- name: Node.js Setup
142-
uses: actions/setup-node@v2
143-
- name: Installation of Node.js dependencies
144-
run: npm ci
145141
- uses: EthanSK/git-branch-name-action@v1
142+
- run: docker-compose build test-contract
146143
- name: Run contract test
147-
run: npm run test:contract
144+
run: make test-contract
148145
env:
149146
GITHUB_BRANCH: ${{ env.GIT_BRANCH_NAME }}

.github/workflows/contract_test_by_dispatch.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@ jobs:
1111

1212
steps:
1313
- uses: actions/checkout@v2
14-
- name: Node.js Setup
15-
uses: actions/setup-node@v2
16-
- name: Installation of Node.js dependencies
17-
run: npm ci
14+
- run: docker-compose build test-contract
1815
- name: Run contract test
19-
run: npm run test:contract
16+
run: make test-contract
2017
env:
2118
PACT_URL: ${{ github.event.client_payload.pactUrl }}
2219
PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }}

Dockerfile.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM node:lts-alpine3.12
2+
3+
ENV TERM xterm-256color
4+
5+
RUN apk add --no-cache git
6+
RUN apk --no-cache add ca-certificates wget bash \
7+
&& wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
8+
&& wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.29-r0/glibc-2.29-r0.apk \
9+
&& apk add glibc-2.29-r0.apk
10+
11+
COPY package.json /tmp/package.json
12+
COPY package-lock.json /tmp/package-lock.json
13+
RUN cd /tmp && npm ci --silent
14+
RUN mkdir -p /app && cp -a /tmp/node_modules /app/
15+
16+
WORKDIR /app
17+
18+
COPY . .

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: build build\run run stop clean
1+
.PHONY: build build\run run stop clean test-contract
22
# serverest
33

44
NAME_IMAGE=serverest
@@ -16,4 +16,7 @@ stop:
1616
@docker stop -t 0 $$(docker ps -q --filter ancestor=${NAME_IMAGE}/${NAME_IMAGE})
1717

1818
clean:
19-
@docker rmi -f serverest/serverest
19+
@docker rmi -f serverest/serverest
20+
21+
test-contract:
22+
@docker-compose run --rm test-contract

docker-compose.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: '2.1'
2+
3+
services:
4+
test-contract:
5+
build:
6+
context: .
7+
dockerfile: ./Dockerfile.test
8+
environment:
9+
- NODE_ENV=serverest-test
10+
- CONSUMER_VERSION_TAG
11+
- PACT_BROKER_TOKEN
12+
- GITHUB_BRANCH
13+
- PACT_URL
14+
- TRIGGERED_BY_PACT_CHANGE
15+
- PACT_BROKER_BASE_URL
16+
- GITHUB_ACTIONS
17+
command: npm run test:contract
18+
volumes:
19+
- ./test:/app/test

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"lint": "standard",
4040
"lint:fix": "standard --fix",
4141
"lint:staged": "lint-staged",
42-
"test:contract": "cross-env NODE_ENV=serverest-test mocha test/contract --timeout 60000"
42+
"test:contract": "mocha test/contract --timeout 60000"
4343
},
4444
"dependencies": {
4545
"colors": "^1.4.0",

0 commit comments

Comments
 (0)