Skip to content
This repository was archived by the owner on Sep 9, 2024. It is now read-only.

Commit e9a8d36

Browse files
committed
ci: build, start, test
Signed-off-by: Stephan Renatus <[email protected]>
1 parent c93a113 commit e9a8d36

File tree

7 files changed

+115
-15
lines changed

7 files changed

+115
-15
lines changed

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.git
2+
.gitignore
3+
Dockerfile
4+
.dockerignore
5+
dist
6+
node_modules
7+
.env
8+
README.md

.github/workflows/pull-request.yaml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,21 @@ concurrency:
99
cancel-in-progress: true
1010

1111
jobs:
12-
test:
13-
name: Test
12+
api:
13+
name: Test API
1414
runs-on: ubuntu-22.04
1515
steps:
1616
- uses: actions/checkout@v4
17-
- uses: actions/setup-node@v4
17+
- name: setup
18+
run: docker compose up --quiet-pull --wait --wait-timeout 300
19+
- name: hurl
20+
run: docker compose run --quiet-pull integration-tests
21+
- name: dump logs
22+
run: docker compose logs
23+
if: failure()
24+
- name: Publish Test Report
25+
uses: mikepenz/action-junit-report@v4
26+
if: always()
1827
with:
19-
node-version: 21
20-
- name: build
21-
run: npm ci
28+
check_name: Results
29+
report_paths: tests/api/report.xml

Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM node:lts-alpine AS builder
2+
USER node
3+
WORKDIR /opt/app
4+
COPY package*.json .
5+
RUN npm ci
6+
COPY --chown=node:node . .
7+
RUN npm run build && npm prune --omit=dev
8+
9+
FROM node:lts-alpine
10+
11+
ENV NODE_ENV production
12+
USER node
13+
WORKDIR /home/node
14+
15+
COPY --from=builder --chown=node:node /opt/app/package*.json .
16+
COPY --from=builder --chown=node:node /opt/app/node_modules ./node_modules
17+
COPY --from=builder --chown=node:node /opt/app/dist ./dist
18+
19+
# COPY package*.json .
20+
# COPY node_modules ./node_modules
21+
# COPY dist ./dist
22+
ARG PORT
23+
EXPOSE ${PORT:-3000}
24+
25+
CMD ["node", "dist/main.js"]

docker-compose.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
services:
2+
server:
3+
build: .
4+
environment:
5+
- OPA_URL=http://opa:8181
6+
depends_on:
7+
- opa
8+
expose:
9+
- 3000
10+
11+
opa:
12+
image: openpolicyagent/opa:latest
13+
ports:
14+
- '8181:8181'
15+
command:
16+
- run
17+
- --server
18+
- --addr=:8181
19+
- --log-level=debug
20+
- --bundle
21+
- --disable-telemetry
22+
- /policies
23+
volumes:
24+
- ./policies:/policies
25+
26+
integration-tests:
27+
image: ghcr.io/orange-opensource/hurl:latest
28+
volumes:
29+
- ./tests:/tests:rw
30+
entrypoint: sh
31+
command:
32+
- -c
33+
- 'hurl --test --retry=10 --verbose --report-junit=tests/api/report.xml /tests/api/*.hurl'
34+
environment:
35+
- HURL_host=server:3000
36+
depends_on:
37+
- server
38+
profiles:
39+
- tools

basic.hurl renamed to tests/api/basic.hurl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
1-
GET http://127.0.0.1:3000/hello
1+
GET http://{{host}}/hello
22
Content-Type: application/json
33
HTTP 200
44
{"hello":"world"}
55

6-
POST http://127.0.0.1:3000/auth/login
6+
POST http://{{host}}/auth/login
77
Content-Type: application/json
88
{"username": "john", "password": "changeme"}
99
HTTP 201
1010
[Captures]
1111
access_token: jsonpath "$['access_token']"
1212

13-
GET http://127.0.0.1:3000/profile
13+
GET http://{{host}}/profile
1414
Content-Type: application/json
1515
Authorization: Bearer {{access_token}}
1616
HTTP 200
1717
{"id":1,"username":"john"}
1818

19-
GET http://127.0.0.1:3000/cats
19+
GET http://{{host}}/cats
2020
Content-Type: application/json
2121
Authorization: Bearer {{access_token}}
2222
HTTP 200
2323
[]
2424

25-
POST http://127.0.0.1:3000/cats
25+
POST http://{{host}}/cats
2626
Content-Type: application/json
2727
Authorization: Bearer {{access_token}}
2828
{"name": "garfield", "age": 5, "breed": "unknown"}
2929
HTTP 403
3030

3131
# Try as admin (maria)
32-
POST http://127.0.0.1:3000/auth/login
32+
POST http://{{host}}/auth/login
3333
Content-Type: application/json
3434
{"username": "maria", "password": "guess"}
3535
HTTP 201
3636
[Captures]
3737
access_token: jsonpath "$['access_token']"
3838

39-
POST http://127.0.0.1:3000/cats
39+
POST http://{{host}}/cats
4040
Content-Type: application/json
4141
Authorization: Bearer {{access_token}}
4242
{"name": "garfield", "age": 5, "breed": "unknown"}
4343
HTTP 201
4444

45-
GET http://127.0.0.1:3000/cats
45+
GET http://{{host}}/cats
4646
Content-Type: application/json
4747
Authorization: Bearer {{access_token}}
4848
HTTP 200
4949
[{"name":"garfield","age":5,"breed":"unknown"}]
5050

51-
GET http://127.0.0.1:3000/cats/garfield
51+
GET http://{{host}}/cats/garfield
5252
Content-Type: application/json
5353
Authorization: Bearer {{access_token}}
5454
HTTP 200

tests/api/cats.hurl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
POST http://{{host}}/auth/login
2+
Content-Type: application/json
3+
{"username": "maria", "password": "guess"}
4+
HTTP 201
5+
[Captures]
6+
access_token: jsonpath "$['access_token']"
7+
8+
POST http://{{host}}/cats
9+
Content-Type: application/json
10+
Authorization: Bearer {{access_token}}
11+
{"name": "garfield", "age": 5, "breed": "unknown"}
12+
HTTP 201
13+
14+
GET http://{{host}}/cats/garfield
15+
Content-Type: application/json
16+
Authorization: Bearer {{access_token}}
17+
x-user: stephan
18+
HTTP 200
19+
{"name":"garfield","age":5,"breed":"unknown"}

tests/api/report.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite tests="2" errors="0" failures="0"><testcase id="/tests/api/basic.hurl" name="/tests/api/basic.hurl" time="0.135" /><testcase id="/tests/api/cats.hurl" name="/tests/api/cats.hurl" time="0.018" /></testsuite></testsuites>

0 commit comments

Comments
 (0)