Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion .github/workflows/node-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ jobs:
- uses: actions/checkout@v4
- uses: ./.github/workflows/rafiki/env-setup
- run: pnpm --filter card-service test:ci
- run: pnpm --filter card-service build
- name: AsyncAPI extension
run: |
echo "{\"extends\":[\"spectral:oas\",\"spectral:asyncapi\"]}" >> .spectral.json
- name: Validate Open API specs
run: |
npx @stoplight/spectral-cli lint ./packages/card-service/src/openapi/specs/*.yaml

point-of-sale:
runs-on: ubuntu-latest
Expand All @@ -100,7 +107,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/rafiki/env-setup
- run: pnpm --filter point-of-sale build:deps
- run: pnpm --filter point-of-sale build
- run: pnpm --filter point-of-sale test:ci

mock-account-servicing-entity:
Expand Down Expand Up @@ -426,6 +433,8 @@ jobs:
- auth
- backend
- frontend
- card-service
- point-of-sale
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -461,6 +470,8 @@ jobs:
- auth
- backend
- frontend
- card-service
- point-of-sale
steps:
- uses: actions/checkout@v4
- name: Fetch docker image from cache
Expand Down Expand Up @@ -497,6 +508,8 @@ jobs:
- auth
- backend
- frontend
- card-service
- point-of-sale
steps:
- uses: actions/checkout@v4
- name: Fetch docker image from cache
Expand Down Expand Up @@ -529,6 +542,8 @@ jobs:
- auth
- backend
- frontend
- card-service
- point-of-sale
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/image-push
Expand All @@ -550,6 +565,8 @@ jobs:
- auth
- backend
- frontend
- card-service
- point-of-sale
steps:
- uses: actions/checkout@v4
- name: Push manifest list
Expand Down
65 changes: 65 additions & 0 deletions packages/card-service/Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
FROM node:20-alpine3.20 AS base

WORKDIR /home/rafiki

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"

RUN corepack enable
RUN corepack prepare [email protected] --activate

COPY pnpm-lock.yaml ./

RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm fetch \
| grep -v "cross-device link not permitted\|Falling back to copying packages from store"

FROM base AS prod-deps

COPY package.json pnpm-workspace.yaml .npmrc ./
COPY packages/card-service/knexfile.js ./packages/card-service/knexfile.js
COPY packages/card-service/package.json ./packages/card-service/package.json
RUN pnpm clean
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm install \
--recursive \
--prefer-offline \
--frozen-lockfile \
--prod \
| grep -v "cross-device link not permitted\|Falling back to copying packages from store"

FROM base AS builder

COPY package.json pnpm-workspace.yaml .npmrc tsconfig.json tsconfig.build.json ./
COPY packages/card-service ./packages/card-service

RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm install \
--recursive \
--offline \
--frozen-lockfile
RUN pnpm --filter card-service build

FROM node:20-alpine3.20 AS runner

# Since this is from a fresh image, we need to first create the Rafiki user
RUN adduser -D rafiki
WORKDIR /home/rafiki

COPY --from=prod-deps /home/rafiki/node_modules ./node_modules
COPY --from=prod-deps /home/rafiki/packages/card-service/node_modules ./packages/card-service/node_modules
COPY --from=prod-deps /home/rafiki/packages/card-service/package.json ./packages/card-service/package.json
COPY --from=prod-deps /home/rafiki/packages/card-service/knexfile.js ./packages/card-service/knexfile.js

COPY --from=builder /home/rafiki/packages/card-service/migrations/ ./packages/card-service/migrations
COPY --from=builder /home/rafiki/packages/card-service/dist ./packages/card-service/dist
COPY --from=builder /home/rafiki/packages/card-service/knexfile.js ./packages/card-service/knexfile.js

USER root

# For additional paranoia, we make it so that the Rafiki user has no write access to the packages
RUN chown -R :rafiki /home/rafiki/packages
RUN chmod -R 750 /home/rafiki/packages
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are missing a CMD here to run the app, same thing for the pos-service one


USER rafiki
CMD ["node", "/home/rafiki/packages/card-service/dist/index.js"]
7 changes: 2 additions & 5 deletions packages/card-service/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{
"name": "card-service",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist/**/*"
],
"main": "index.js",
"scripts": {
"build": "pnpm clean && tsc --build tsconfig.json",
"clean": "rm -fr dist/",
Expand Down Expand Up @@ -37,6 +33,7 @@
"@types/koa-bodyparser": "^4.3.12",
"@types/koa__cors": "^5.0.0",
"@types/koa__router": "^12.0.4",
"@types/node": "^20.14.15",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed this so that the pipeline can recognise crypto library.

"@types/uuid": "^9.0.8",
"jest-environment-node": "^29.7.0",
"nock": "14.0.0-beta.19",
Expand Down
12 changes: 12 additions & 0 deletions packages/card-service/src/openapi/specs/card-server.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
openapi: 3.0.3

Check warning on line 1 in packages/card-service/src/openapi/specs/card-server.yaml

View workflow job for this annotation

GitHub Actions / card-service

oas3-api-servers
info:
title: Card Service API
version: 1.0.0
description: Card Service API specs
contact:
email: [email protected]
tags:
- name: payment
description: Operations related to payments
paths:
/payment:
post:
Expand Down Expand Up @@ -67,6 +73,9 @@
description: Card expired or invalid signature
'500':
description: Internal server error
description: 'POS service calls this endpoint to initiate a payment request.'
tags:
- payment
/payment-event:
post:
summary: Handle payment event result from backend
Expand Down Expand Up @@ -106,3 +115,6 @@
description: Malformed request body
'404':
description: Request not found
description: 'Rafiki backend calls this endpoint to send the payment result.'
tags:
- payment
8 changes: 3 additions & 5 deletions packages/point-of-sale/Dockerfile.prod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ FROM base AS prod-deps
COPY package.json pnpm-workspace.yaml .npmrc ./
COPY packages/point-of-sale/knexfile.js ./packages/point-of-sale/knexfile.js
COPY packages/point-of-sale/package.json ./packages/point-of-sale/package.json
COPY packages/token-introspection/package.json ./packages/token-introspection/package.json

RUN pnpm clean
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
Expand All @@ -34,7 +33,6 @@ FROM base AS builder

COPY package.json pnpm-workspace.yaml .npmrc tsconfig.json tsconfig.build.json ./
COPY packages/point-of-sale ./packages/point-of-sale
COPY packages/token-introspection ./packages/token-introspection

RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm install \
Expand All @@ -52,17 +50,17 @@ WORKDIR /home/rafiki
COPY --from=prod-deps /home/rafiki/node_modules ./node_modules
COPY --from=prod-deps /home/rafiki/packages/point-of-sale/node_modules ./packages/point-of-sale/node_modules
COPY --from=prod-deps /home/rafiki/packages/point-of-sale/package.json ./packages/point-of-sale/package.json
COPY --from=prod-deps /home/rafiki/packages/token-introspection/node_modules ./packages/token-introspection/node_modules
COPY --from=prod-deps /home/rafiki/packages/token-introspection/package.json ./packages/token-introspection/package.json
COPY --from=prod-deps /home/rafiki/packages/point-of-sale/knexfile.js ./packages/point-of-sale/knexfile.js

COPY --from=builder /home/rafiki/packages/point-of-sale/migrations/ ./packages/point-of-sale/migrations
COPY --from=builder /home/rafiki/packages/point-of-sale/dist ./packages/point-of-sale/dist
COPY --from=builder /home/rafiki/packages/token-introspection/dist ./packages/token-introspection/dist
COPY --from=builder /home/rafiki/packages/point-of-sale/knexfile.js ./packages/point-of-sale/knexfile.js

USER root

# For additional paranoia, we make it so that the Rafiki user has no write access to the packages
RUN chown -R :rafiki /home/rafiki/packages
RUN chmod -R 750 /home/rafiki/packages

USER rafiki
CMD ["node", "/home/rafiki/packages/point-of-sale/dist/index.js"]
5 changes: 2 additions & 3 deletions packages/point-of-sale/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"generate": "graphql-codegen --config codegen.yml",
"knex": "knex",
"dev": "ts-node-dev --inspect=0.0.0.0:9229 --respawn --transpile-only src/index.ts",
"build": "pnpm build:deps && pnpm clean && tsc --build tsconfig.json",
"build:deps": "pnpm --filter token-introspection build",
"build": "pnpm clean && tsc --build tsconfig.json",
"clean": "rm -fr dist/"
},
"keywords": [],
Expand All @@ -25,7 +24,7 @@
"@faker-js/faker": "^8.4.1",
"@koa/cors": "^5.0.0",
"@koa/router": "^12.0.2",
"axios": "1.8.2",
"axios": "1.12.0",
"dotenv": "^16.4.7",
"graphql": "^16.11.0",
"json-canonicalize": "^1.0.6",
Expand Down
Loading
Loading