Skip to content
Merged
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
8 changes: 8 additions & 0 deletions localenv/cloud-nine-wallet/dbinit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ CREATE USER happy_life_bank_auth WITH PASSWORD 'happy_life_bank_auth';
CREATE DATABASE happy_life_bank_auth;
ALTER DATABASE happy_life_bank_auth OWNER TO happy_life_bank_auth;

CREATE USER cloud_nine_wallet_pos WITH PASSWORD 'cloud_nine_wallet_pos';
CREATE DATABASE cloud_nine_wallet_pos;
ALTER DATABASE cloud_nine_wallet_pos OWNER TO cloud_nine_wallet_pos;

CREATE USER happy_life_bank_pos WITH PASSWORD 'happy_life_bank_pos';
CREATE DATABASE happy_life_bank_pos;
ALTER DATABASE happy_life_bank_pos OWNER TO happy_life_bank_pos;

CREATE USER happy_life_bank_card_service WITH PASSWORD 'happy_life_bank_card_service';
CREATE DATABASE happy_life_bank_card_service;
ALTER DATABASE happy_life_bank_card_service OWNER TO happy_life_bank_card_service;
32 changes: 32 additions & 0 deletions localenv/cloud-nine-wallet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,38 @@ services:
interval: 30s
retries: 1
timeout: 3s
cloud-nine-wallet-point-of-sale:
hostname: cloud-nine-wallet-point-of-sale
image: rafiki-point-of-sale
build:
context: ../..
dockerfile: ./packages/point-of-sale/Dockerfile.dev
restart: always
networks:
- rafiki
ports:
- '3008:3008'
volumes:
- type: bind
source: ../../packages/point-of-sale/src
target: /home/rafiki/packages/point-of-sale/src
read_only: true
environment:
NODE_ENV: ${NODE_ENV:-development}
INSTANCE_NAME: CLOUD-NINE
TRUST_PROXY: ${TRUST_PROXY}
LOG_LEVEL: debug
PORT: 3008
DATABASE_URL: postgresql://cloud_nine_wallet_point_of_sale:cloud_nine_wallet_point_of_sale@shared-database/cloud_nine_wallet_point_of_sale
depends_on:
- shared-database
healthcheck:
test: ["CMD", "wget", "--spider", "http://localhost:3008/healthz"]
start_period: 60s
start_interval: 5s
interval: 30s
retries: 1
timeout: 3s
cloud-nine-mock-ase:
hostname: cloud-nine-wallet
image: rafiki-mock-ase
Expand Down
38 changes: 35 additions & 3 deletions localenv/happy-life-bank/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ services:
networks:
- rafiki
ports:
- '4007:3007'
- '4007:4007'
volumes:
- type: bind
source: ../../packages/card-service/src
target: /home/rafiki/packages/card-service/src
read_only: true
environment:
NODE_ENV: ${NODE_ENV:-development}
INSTANCE_NAME: CLOUD-NINE
INSTANCE_NAME: HAPPY-LIFE
TRUST_PROXY: ${TRUST_PROXY}
LOG_LEVEL: debug
CARD_SERVICE_PORT: 3007
CARD_SERVICE_PORT: 4007
DATABASE_URL: postgresql://happy_life_bank_card_service:happy_life_bank_card_service@shared-database/happy_life_bank_card_service
depends_on:
- shared-database
Expand All @@ -32,6 +32,38 @@ services:
interval: 30s
retries: 1
timeout: 3s
happy-life-bank-point-of-sale:
hostname: happy-life-bank-point-of-sale
image: rafiki-point-of-sale
build:
context: ../..
dockerfile: ./packages/point-of-sale/Dockerfile.dev
restart: always
networks:
- rafiki
ports:
- '4008:4008'
volumes:
- type: bind
source: ../../packages/point-of-sale/src
target: /home/rafiki/packages/point-of-sale/src
read_only: true
environment:
NODE_ENV: ${NODE_ENV:-development}
INSTANCE_NAME: HAPPY-LIFE
TRUST_PROXY: ${TRUST_PROXY}
LOG_LEVEL: debug
PORT: 4008
DATABASE_URL: postgresql://happy_life_bank_point_of_sale:happy_life_bank_point_of_sale@shared-database/happy_life_bank_point_of_sale
depends_on:
- shared-database
healthcheck:
test: ["CMD", "wget", "--spider", "http://localhost:4008/healthz"]
start_period: 60s
start_interval: 5s
interval: 30s
retries: 1
timeout: 3s
happy-life-mock-ase:
hostname: happy-life-bank
image: rafiki-mock-ase
Expand Down
35 changes: 35 additions & 0 deletions packages/point-of-sale/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM node:20-alpine3.20

RUN adduser -D rafiki
WORKDIR /home/rafiki

# Install Corepack and pnpm as the Rafiki user
USER rafiki
RUN mkdir -p /home/rafiki/.local/bin
ENV PATH="/home/rafiki/.local/bin:$PATH"
RUN corepack enable --install-directory ~/.local/bin
RUN corepack prepare [email protected] --activate
COPY pnpm-lock.yaml package.json pnpm-workspace.yaml .npmrc tsconfig.json tsconfig.build.json ./

# Fetch the pnpm dependencies, but use a local cache.
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"

# Copy the source code and chown the relevant folders back to the Rafiki user
USER root
COPY . ./
RUN chown -v -R rafiki:rafiki /home/rafiki/localenv
RUN chown -v -R rafiki:rafiki /home/rafiki/packages
RUN chown -v -R rafiki:rafiki /home/rafiki/test

# As the Rafiki user, install the rest of the dependencies and build the source code
USER rafiki
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm install \
--recursive \
--offline \
--frozen-lockfile
RUN pnpm --filter point-of-sale build:deps

CMD pnpm --filter point-of-sale dev
68 changes: 68 additions & 0 deletions packages/point-of-sale/Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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/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 \
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/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 \
--recursive \
--offline \
--frozen-lockfile
RUN pnpm --filter point-of-sale 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/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
43 changes: 43 additions & 0 deletions packages/point-of-sale/knexfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Update with your config settings.

/**
* @type { Object.<string, import("knex").Knex.Config> }
*/
module.exports = {
development: {
client: 'postgresql',
connection: {
database: 'pos',
user: 'postgres',
password: 'password'
}
},

testing: {
client: 'postgresql',
connection: {
database: 'pos_testing',
user: 'postgres',
password: 'password'
},
pool: {
min: 2,
max: 10
},
migrations: {
tableName: 'pos_knex_migrations'
}
},

production: {
client: 'postgresql',
connection: process.env.POS_DATABASE_URL,
pool: {
min: 2,
max: 10
},
migrations: {
tableName: 'pos_knex_migrations'
}
}
}
38 changes: 38 additions & 0 deletions packages/point-of-sale/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "point-of-sale",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"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",
"clean": "rm -fr dist/"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@adonisjs/fold": "^8.2.0",
"@apollo/server": "^4.11.2",
"@koa/cors": "^5.0.0",
"@koa/router": "^12.0.2",
"dotenv": "^16.4.7",
"knex": "^3.1.0",
"koa": "^3.0.0",
"koa-bodyparser": "^4.4.1",
"objection": "^3.1.5",
"objection-db-errors": "^1.1.2",
"pg": "^8.11.3",
"pino": "^8.19.0",
"ts-node-dev": "^2.0.0"
},
"devDependencies": {
"@types/koa": "2.15.0",
"@types/koa-bodyparser": "^4.3.12",
"@types/koa__cors": "^5.0.0",
"@types/koa__router": "^12.0.4"
}
}
Loading