Skip to content

Commit

Permalink
fix: nx image building
Browse files Browse the repository at this point in the history
Signed-off-by: Mirko Mollik <[email protected]>
  • Loading branch information
cre8 committed May 13, 2024
1 parent d927a22 commit de8679a
Show file tree
Hide file tree
Showing 28 changed files with 221 additions and 103 deletions.
10 changes: 9 additions & 1 deletion apps/holder-app/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
"sourceRoot": "apps/holder-app/src",
"tags": [],
"targets": {
"init": {
"executor": "nx:run-commands",
"options": {
"commands": [
"cp apps/holder-app/src/assets/config/config.example.js apps/holder-app/src/assets/config/config.js"
]
}
},
"build": {
"executor": "@angular-devkit/build-angular:application",
"outputs": ["{options.outputPath}"],
Expand Down Expand Up @@ -86,10 +94,10 @@
"dependsOn": ["build"],
"options": {
"engine": "docker",
"push": true,
"metadata": {
"images": ["ghcr.io/cre8/wallet/holder-app"],
"load": true,
"push": false,
"tags": ["latest"]
}
}
Expand Down
2 changes: 1 addition & 1 deletion apps/holder-backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM docker.io/node:lts-alpine as deps
RUN apk add --no-cache libc6-compat
WORKDIR /usr/src/app
COPY dist/apps/holder-backend/package*.json ./
COPY dist/apps/holder-backend/pnpm-lock.yaml ./
COPY pnpm-lock.yaml ./
COPY patches ./patches
RUN npm install -g [email protected]
RUN pnpm install --prod
Expand Down
11 changes: 11 additions & 0 deletions apps/holder-backend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"dependencies": {
"@sphereon/pex": "^3.3.3",
"pg": "^8.11.5"
},
"pnpm": {
"patchedDependencies": {
"@sphereon/[email protected]": "patches/@[email protected]"
}
}
}
20 changes: 11 additions & 9 deletions apps/holder-backend/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
"projectType": "application",
"tags": [],
"targets": {
"init": {
"executor": "nx:run-commands",
"options": {
"commands": [
"cp apps/holder-backend/.env.example apps/holder-backend/.env"
]
}
},
"serve": {
"executor": "@nx/js:node",
"defaultConfiguration": "development",
Expand All @@ -25,17 +33,11 @@
"dependsOn": ["build"],
"options": {
"engine": "docker",
"push": true,
"metadata": {
"images": ["holder-backend"],
"images": ["ghcr.io/cre8/wallet/holder-backend"],
"load": true,
"push": false,
"tags": [
"type=schedule",
"type=ref,event=branch",
"type=ref,event=tag",
"type=ref,event=pr",
"type=sha,prefix=sha-"
]
"tags": ["latest"]
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions apps/holder-backend/src/app/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { Controller, Get } from '@nestjs/common';
import { ApiOperation } from '@nestjs/swagger';
import { Public } from 'nest-keycloak-connect';

@Controller()
export class AppController {
/**
* Health check endpoint
* @returns
*/
@ApiOperation({ summary: 'Health check endpoint' })
@Public()
@Get('health')
health() {
//TODO: for a better health check, use https://docs.nestjs.com/recipes/terminus#setting-up-a-healthcheck
return 'ok';
}
}
1 change: 1 addition & 0 deletions apps/holder-backend/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'tslib';
import { ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
Expand Down
2 changes: 1 addition & 1 deletion apps/issuer-backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ DB_NAME=tmp/db.sqlite

CREDENTIALS_FOLDER=config/issuer-backend

KM_FOLDER=tmp/issuer/
KM_FOLDER=tmp/issuer/keys
6 changes: 3 additions & 3 deletions apps/issuer-backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ FROM docker.io/node:lts-alpine as deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /usr/src/app
COPY dist/apps/holder-backend/package*.json ./
COPY dist/apps/holder-backend/pnpm-lock.yaml ./
COPY dist/apps/issuer-backend/package.json ./
COPY pnpm-lock.yaml ./
COPY patches ./patches
RUN npm install -g [email protected]
RUN pnpm install --prod
Expand All @@ -17,7 +17,7 @@ ENV PORT 3000
WORKDIR /usr/src/app
COPY --from=deps /usr/src/app/node_modules ./node_modules
COPY --from=deps /usr/src/app/package.json ./package.json
COPY dist/apps/holder-backend .
COPY dist/apps/issuer-backend .
RUN chown -R node:node .
USER node
EXPOSE 3000
Expand Down
11 changes: 11 additions & 0 deletions apps/issuer-backend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"dependencies": {
"sqlite3": "^5.1.7",
"@sphereon/pex": "^3.3.3"
},
"pnpm": {
"patchedDependencies": {
"@sphereon/[email protected]": "patches/@[email protected]"
}
}
}
10 changes: 9 additions & 1 deletion apps/issuer-backend/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
"projectType": "application",
"tags": [],
"targets": {
"init": {
"executor": "nx:run-commands",
"options": {
"commands": [
"cp apps/issuer-backend/.env.example apps/issuer-backend/.env"
]
}
},
"serve": {
"executor": "@nx/js:node",
"defaultConfiguration": "development",
Expand All @@ -25,10 +33,10 @@
"dependsOn": ["build"],
"options": {
"engine": "docker",
"push": true,
"metadata": {
"images": ["ghcr.io/cre8/wallet/issuer-backend"],
"load": true,
"push": false,
"tags": ["latest"]
}
}
Expand Down
1 change: 1 addition & 0 deletions apps/issuer-backend/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'tslib';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app/app.module';
import { ValidationPipe } from '@nestjs/common';
Expand Down
1 change: 1 addition & 0 deletions apps/issuer-backend/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
assets: ['./src/assets'],
optimization: false,
outputHashing: 'none',
generatePackageJson: true,
transformers: [{ name: '@nestjs/swagger/plugin' }],
}),
],
Expand Down
2 changes: 1 addition & 1 deletion apps/issuer-frontend/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@
"dependsOn": ["build"],
"options": {
"engine": "docker",
"push": true,
"metadata": {
"images": ["ghcr.io/cre8/wallet/issuer-frontend"],
"load": true,
"push": false,
"tags": ["latest"]
}
}
Expand Down
2 changes: 1 addition & 1 deletion apps/verifier-backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ KEYCLOAK_CLIENT_ID=issuer

CREDENTIALS_FOLDER=config/verifier

KM_FOLDER=tmp/verifier/
KM_FOLDER=tmp/verifier/keys
6 changes: 3 additions & 3 deletions apps/verifier-backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ FROM docker.io/node:lts-alpine as deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /usr/src/app
COPY dist/apps/holder-backend/package*.json ./
COPY dist/apps/holder-backend/pnpm-lock.yaml ./
COPY dist/apps/verifier-backend/package.json ./
COPY pnpm-lock.yaml ./
COPY patches ./patches
RUN npm install -g [email protected]
RUN pnpm install --prod
Expand All @@ -17,7 +17,7 @@ ENV PORT 3000
WORKDIR /usr/src/app
COPY --from=deps /usr/src/app/node_modules ./node_modules
COPY --from=deps /usr/src/app/package.json ./package.json
COPY dist/apps/holder-backend .
COPY dist/apps/verifier-backend .
RUN chown -R node:node .
USER node
EXPOSE 3000
Expand Down
10 changes: 10 additions & 0 deletions apps/verifier-backend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"dependencies": {
"@sphereon/pex": "^3.3.3"
},
"pnpm": {
"patchedDependencies": {
"@sphereon/[email protected]": "patches/@[email protected]"
}
}
}
10 changes: 9 additions & 1 deletion apps/verifier-backend/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
"projectType": "application",
"tags": [],
"targets": {
"init": {
"executor": "nx:run-commands",
"options": {
"commands": [
"cp apps/verifier-backend/.env.example apps/verifier-backend/.env"
]
}
},
"serve": {
"executor": "@nx/js:node",
"defaultConfiguration": "development",
Expand All @@ -25,10 +33,10 @@
"dependsOn": ["build"],
"options": {
"engine": "docker",
"push": true,
"metadata": {
"images": ["ghcr.io/cre8/wallet/verifier-backend"],
"load": true,
"push": false,
"tags": ["latest"]
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Inject, Injectable } from '@nestjs/common';
import { ES256, digest } from '@sd-jwt/crypto-nodejs';
import {
EcdsaSignature,
JWK,
JWTPayload,
PassBy,
Expand Down
1 change: 1 addition & 0 deletions apps/verifier-backend/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'tslib';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app/app.module';
import { ValidationPipe } from '@nestjs/common';
Expand Down
2 changes: 1 addition & 1 deletion apps/verifier-frontend/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@
"dependsOn": ["build"],
"options": {
"engine": "docker",
"push": true,
"metadata": {
"images": ["ghcr.io/cre8/wallet/verifier-frontend"],
"load": true,
"push": false,
"tags": ["latest"]
}
}
Expand Down
5 changes: 0 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,6 @@ services:
image: ghcr.io/cre8/wallet/holder-backend
env_file:
- .env
build:
context: .
dockerfile: docker/node.Dockerfile
args:
- PROJECT=backend
ports:
- 3000:3000
healthcheck:
Expand Down
36 changes: 0 additions & 36 deletions docker/browser.Dockerfile

This file was deleted.

26 changes: 0 additions & 26 deletions docker/node.Dockerfile

This file was deleted.

16 changes: 13 additions & 3 deletions docs/development.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# Development

## Technical design decisions
Typescript as programming language: large community and good support for wallet related libraries. Of course it does not perform as good as Rust, but it's easier to write and maintain for the current state of the project. It is possible to write different parts of the project in Rust or any other language later on.

Angular as frontend framework: All frontend applications are written in Angular. There was no intention to build a react native application so far, but it is possible to do so. Since the client is primarily job is to render information and not to execute business actions, other clients like a react native app, vanilla js or even a flutter app can be implemented.

Nestjs as backend framework: Nestjs is one of the popular frameworks for nodejs. The build in database connection, the openAPI support and the easy validation of incoming requests are the main reasons to use it. It is also possible to write the backend in Rust or any other language later on.

NX as monorepo manager: NX is a great tool to manage a monorepo. It is possible to share code between the applications and to define the jobs for building, testing and linting in one place. It is also possible to define the dependencies between the applications and to run the jobs in the right order.

## Requirements
- node v20 (https://nodejs.org/en/download/package-manager)
- pnpm v9
- enabled corepack via `corepack enable` (comes with node)
- pnpm v8 (v9 has some issues with the nx workspace)

For an easy development setup, it is recommend to use vscode with the nx plugin to start tasks like building, testing and linting or to generate new code. You can also use Webstorm with the nx plugin, [see here](https://nx.dev/getting-started/editor-setup#official-integrations).


### Keycloak (OIDC provider)
Expand Down Expand Up @@ -46,4 +56,4 @@ To build the plugin for production, run `pnpm run build:extension`. The output w
## Backend
All endpoints are available via the `http://localhost:3000` address. A swagger endpoint is available at `http://localhost:3000/api` where you can authenticate with your keycloak user credentials. Don't forget to have an `.env` file in the folder to configure the application, it will not use the `.env` file in the root folder.

You can either use a postgres or sqlite database. In case of using postgres, there is one defined in the `docker-compose.yml` in the root folder. Don't forget to sync the credentials in the root `.env` file and the one in the backend folder to get a successful connection.
You can either use a postgres or sqlite database. In case of using postgres, there is one defined in the `docker-compose.yml` in the root folder. Don't forget to sync the credentials in the root `.env` file and the one in the backend folder to get a successful connection.
Loading

0 comments on commit de8679a

Please sign in to comment.