5 Commits

Author SHA1 Message Date
a4de9872f7 Hlæja concept v0.5.0 2025-02-07 17:50:43 +01:00
e2b0c475fc Hlæja concept v0.4.0 2025-01-21 12:43:46 +01:00
4052404120 Hlæja concept v0.3.0 2024-12-28 08:46:05 +01:00
614abcb272 add redis and cleanup
- add doc/global_settings.md
- docker_database.md
- update dependency.md
- extrack hlaeja from  development-compose.yml to hlaeja-compose.yml
- rename compose.yml to development-compose.yml
- extract text from readme.md
  - databases to doc/docker_database.md
  - hlaeja service to doc/docker_hlaeja.md
- move and rename structure.md to doc/dependency.md
- move and rename identity.md to doc/rsa_key.mk
- move and rename certificate.md to doc/keystore.md
2024-12-27 23:44:50 +01:00
5dc1e91ce2 add RegistryApi 2024-12-20 00:56:52 +01:00
11 changed files with 575 additions and 215 deletions

View File

@@ -1,11 +0,0 @@
# Generate Keystore
### Generate Keystores
```shell
keytool -genkeypair -alias <service> -keyalg RSA -keysize 2048 -validity 3650 -dname "CN=<domain>" -keypass <password> -keystore ./keys/<keystore>.p12 -storetype PKCS12 -storepass <password>
```
### Export the public certificate
```shell
keytool -export -alias <service> -keystore ./keys/<keystore>.p12 -storepass <password> -file ./keys/<domain>.cer -rfc
```

131
README.md
View File

@@ -2,127 +2,74 @@
Services and networks, to shape and to steer, Containers in harmony, their roles made clear. Each config declared, each volume in place, Through Compose they unite, to streamline the space. Compose pathways, structured and strong, Linking apps to environments, where they belong. Bound by one purpose, to simplify all, Empowering development, answering the call.
## Version Catalog
## Setup
### Databases
Hlæja using different databases read [Database setup](./doc/docker_database.md)
### Hlæja Services
Hlæja consists of services read [service setup](./doc/docker_hlaeja.md)
## Repositories
Hlæja is a system build from Gradle plugins, libraries, and services, look at [dependencies](./doc/dependency.md) visualisation
### Version Catalog
Control all dependencies from a central location. GitHub [Hlæja Version Catalog](https://github.com/swordsteel/hlaeja-version-catalog)
## Gradle Plugin
### Gradle Plugin
### Core Plugin
#### Core Plugin
Plugin containing basic function ust in all repositories. GitHub [Hlæja Core Plugin](https://github.com/swordsteel/hlaeja-core-plugin)
### Common Plugin
#### Common Plugin
Plugin containing gradle task and setting used by common, library, and service repositories. GitHub [Hlæja Common Plugin](https://github.com/swordsteel/hlaeja-common-plugin)
## Library
### Library
### Common Messages
#### Common Messages
Library containing all internal messages for services. GitHub [Hlæja Common Messages](https://github.com/swordsteel/hlaeja-common-messages)
## Services
#### JWT
### Device Data
Library containing JWT for services. GitHub [Hlæja JWT](https://github.com/swordsteel/hlaeja-jwt)
#### Test
Library containing test assertion extension and test container annotation. GitHub [Hlæja Test](https://github.com/swordsteel/hlaeja-test)
### Services
#### Device Data
Store measurement from electronic devices. GitHub [Hlæja Device Data](https://github.com/swordsteel/hlaeja-device-data)
#### Environment
```text
SPRING_PROFILES_ACTIVE: docker
INFLUXDB_TOKEN: influxdbToken==
```
### Device Registry
#### Device Registry
Store device information. GitHub [Hlæja Device Data](https://github.com/swordsteel/hlaeja-device-registry)
#### Environment
```text
SPRING_R2DBC_URL: r2dbc:postgresql://localhost:5432/device_registry
SPRING_R2DBC_USERBAME: services
SPRING_R2DBC_PASSWORD: password
JWT_PRIVATE_KEY: cert/private_key.pem
```
#### Volume
This will allow you to mount a local private key `identity_private_key.pem` into the container. Read `IDENTITY.md` for how to generate.
```text
volumes:
- ./cert/identity_private_key.pem:/app/resources/cert/private_key.pem
```
### Device API
#### Device API
Api for electronic devices. GitHub [Hlæja Device Data](https://github.com/swordsteel/hlaeja-device-api)
#### Environment
```text
SPRING_PROFILES_ACTIVE: docker
```
#### Volume
This will allow you to mount a local keystore `device_api_keystore.p12`, and local public key `identity_public_key.pem` into the container. Read `CERTIFICATE.md`, and `IDENTITY.md` for how to generate.
```text
volumes:
- ./keys/identity_public_key.pem:/app/resources/cert/public_key.pem
- ./keys/device_api_keystore.p12:/app/resources/cert/keystore.p12
```
### Device Configuration
#### Device Configuration
Store configurations for electronic devices. GitHub [Hlæja Device Configuration](https://github.com/swordsteel/hlaeja-device-configuration)
#### Environment
#### Registry API
```text
SPRING_PROFILES_ACTIVE: docker
```
API for register devices when flashed. GitHub [Hlæja Registry API](https://github.com/swordsteel/hlaeja-registry-api)
#### Account Registry
## Databases
Store Information of accounts. GitHub [Hlæja Account Registry](https://github.com/swordsteel/hlaeja-account-registry)
### InfluxDB
#### Management
InfluxDB is a high-performance time series database designed to handle large volumes of time-stamped data. It is commonly used for monitoring, analytics, and IoT applications, where data points are associated with timestamps (e.g., sensor readings, system metrics).
#### Environment
```text
DOCKER_INFLUXDB_INIT_MODE: setup
DOCKER_INFLUXDB_INIT_USERNAME: influx
DOCKER_INFLUXDB_INIT_PASSWORD: password
DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: influxdbToken==
DOCKER_INFLUXDB_INIT_ORG: hlaeja_ltd
DOCKER_INFLUXDB_INIT_BUCKET: device-data
```
### PostgreSQL
PostgreSQL is a powerful, open-source relational database management system (RDBMS). Known for its reliability and advanced features, it supports SQL for querying and managing data, along with extensive functionality for scalability and extensibility.
#### Environment
```text
POSTGRES_USER: postgres
POSTGRES_PASSWORD : password
```
### PostgreSQL
Apache Cassandra is a distributed NoSQL database designed for handling large amounts of data across many commodity servers with no single point of failure. It is optimized for high availability, scalability, and fault tolerance.
#### Environment
```text
CASSANDRA_USER: cassandra
CASSANDRA_PASSWORD: password
```
Management ui. GitHub [Hlæja Account Registry](https://github.com/swordsteel/hlaeja-management)

View File

@@ -1,112 +0,0 @@
name: hlaeja-development
networks:
develop:
name: develop
volumes:
cassandra:
influx-config:
influx-data:
postgres:
services:
device-data:
image: hlaeja-device-data:0.1.1
container_name: DeviceData
restart: unless-stopped
environment:
SPRING_PROFILES_ACTIVE: docker
INFLUXDB_TOKEN: influxdbToken==
networks:
- develop
ports:
- "9020:8080"
device-registry:
image: hlaeja-device-registry:0.2.0
container_name: DeviceRegistry
restart: unless-stopped
environment:
SPRING_PROFILES_ACTIVE: docker
networks:
- develop
ports:
- "9010:8080"
# mount a local `identity_private_key.pem` into the container.
volumes:
- ./cert/identity_private_key.pem:/app/resources/cert/private_key.pem
device-api:
image: hlaeja-device-api:0.2.0
container_name: DeviceApi
restart: unless-stopped
environment:
SPRING_PROFILES_ACTIVE: docker
networks:
- develop
ports:
- "9000:8443"
# mount a local `identity_public_key.pem` into the container.
volumes:
- ./cert/identity_public_key.pem:/app/resources/cert/public_key.pem
- ./cert/device_api_keystore.p12:/app/resources/cert/keystore.p12
device-configuration:
image: hlaeja-device-configuration:0.1.0
container_name: DeviceConfiguration
restart: unless-stopped
environment:
SPRING_PROFILES_ACTIVE: docker
networks:
- develop
ports:
- "9030:8080"
influxdb:
image: influxdb:2.7.10-alpine
container_name: InfluxDB
restart: unless-stopped
environment:
DOCKER_INFLUXDB_INIT_MODE: setup
DOCKER_INFLUXDB_INIT_USERNAME: influx
DOCKER_INFLUXDB_INIT_PASSWORD: password
DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: influxdbToken==
DOCKER_INFLUXDB_INIT_ORG: hlaeja_ltd
DOCKER_INFLUXDB_INIT_BUCKET: device-data
networks:
- develop
ports:
- "8086:8086"
volumes:
- influx-data:/var/lib/influxdb2
- influx-config:/etc/influxdb2
postgres:
image: postgres:17.1-alpine
container_name: PostgreSQL
restart: unless-stopped
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD : password
ports:
- "5432:5432"
networks:
- develop
volumes:
- postgres:/var/lib/postgresql/data
cassandra:
image: cassandra:5.0.2
container_name: Cassandra
restart: unless-stopped
environment:
CASSANDRA_USER: cassandra
CASSANDRA_PASSWORD: password
networks:
- develop
ports:
- "9042:9042"
volumes:
- cassandra:/var/lib/cassandra

75
development-compose.yml Normal file
View File

@@ -0,0 +1,75 @@
name: development
networks:
develop:
name: develop
external: true
volumes:
cassandra:
influx-config:
influx-data:
postgres:
redis:
services:
influxdb:
image: influxdb:2.7.10-alpine
container_name: InfluxDB
restart: unless-stopped
environment:
DOCKER_INFLUXDB_INIT_MODE: setup
DOCKER_INFLUXDB_INIT_USERNAME: influx
DOCKER_INFLUXDB_INIT_PASSWORD: password
DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: influxdbToken==
DOCKER_INFLUXDB_INIT_ORG: hlaeja_ltd
DOCKER_INFLUXDB_INIT_BUCKET: device-data
networks:
- develop
ports:
- 8086:8086
volumes:
- influx-data:/var/lib/influxdb2
- influx-config:/etc/influxdb2
postgres:
image: postgres:17.1-alpine
container_name: PostgreSQL
restart: unless-stopped
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD : password
ports:
- 5432:5432
networks:
- develop
volumes:
- postgres:/var/lib/postgresql/data
cassandra:
image: cassandra:5.0.2
container_name: Cassandra
restart: unless-stopped
environment:
CASSANDRA_USER: cassandra
CASSANDRA_PASSWORD: password
networks:
- develop
ports:
- 9042:9042
volumes:
- cassandra:/var/lib/cassandra
redis:
image: redis:7.4.1-alpine
container_name: Redis
restart: unless-stopped
environment:
REDIS_PASSWORD: password
networks:
- develop
ports:
- 6379:6379
volumes:
- redis:/data

120
doc/dependency.md Normal file
View File

@@ -0,0 +1,120 @@
# Hlæja dependency
## Service dependency
```mermaid
graph TD
;
subgraph BE[Backend Services]
subgraph HDR[Hlæja Device Registry]
HDRS[Service] --> HDRD[(Postgres)]
end
subgraph HDD[Hlæja Device Data]
HDDS[Service] --> HDDD[(InfluxDB)]
end
subgraph HDC[Hlæja Device Configuration]
HDCS[Service] --> HDCD[(Cassandra)]
end
subgraph HAR[Hlæja Account Registry]
HARS[Service] --> HARD[(Postgres)]
end
end
subgraph HDA[Hlæja Device API]
HDAS[Service] --> HDAD[(Redis)]
end
subgraph HRA[Hlæja Registry API]
HRAS[Service]
end
subgraph HM[Hlæja Management]
HMS[Service]
end
HM --> HAR
HM -.-> HDR
HM -.-> HDC
HDA --> HDR
HDA --> HDC
HDA --> HDD
HRA --> HAR
HRA --> HDR
```
## Library and Gradle plugin dependency
```mermaid
graph RL
;
CP[Core Plugin]
subgraph SCP [Common Plugin]
PL[Plugin Library]
PLM[Plugin Library Manifest]
PLP[Plugin Library Publish]
PCo[Plugin Common]
PCoD[Plugin Common Detekt]
PCoK[Plugin Common Ktlint]
PCe[Plugin Certificate]
PS[Plugin Service]
PSC[Plugin Service Container]
PSIT[Plugin Service Integration Test]
PSPR[Plugin Service Process Resource]
end
PLM --> PL
PLP --> PL
PCo ---> PL
PCoD --> PCo
CP ---> PCo
PCoK --> PCo
PCo ---> PS
PSC --> PS
PSIT --> PS
PSPR --> PS
CML[Common Messages Library]
PL --> CML
JL[JWT Library]
PL --> JL
TL[Test Library]
PL --> TL
DRS[Device Registry Service]
PS --> DRS
PCe --> DRS
CML --> DRS
JL --> DRS
DDS[Device Data Service]
PS --> DDS
CML --> DDS
DCS[Device Configuration Service]
PS --> DCS
CML --> DCS
DAS[Device API Service]
CML --> DAS
JL --> DAS
PS --> DAS
PCe --> DAS
RAS[Registry API Service]
CML --> RAS
JL --> RAS
PS --> RAS
PCe --> RAS
AS[Account Service]
CML --> AS
JL --> AS
TL --> AS
PS --> AS
PCe --> AS
MUS[Management UI Service]
CML --> MUS
JL --> MUS
PS --> MUS
PCe -.-> MUS
```

48
doc/docker_database.md Normal file
View File

@@ -0,0 +1,48 @@
# Hlæja databases
## InfluxDB
InfluxDB is a high-performance time series database designed to handle large volumes of time-stamped data. It is commonly used for monitoring, analytics, and IoT applications, where data points are associated with timestamps (e.g., sensor readings, system metrics).
### Environment
```text
DOCKER_INFLUXDB_INIT_MODE: setup
DOCKER_INFLUXDB_INIT_USERNAME: influx
DOCKER_INFLUXDB_INIT_PASSWORD: password
DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: influxdbToken==
DOCKER_INFLUXDB_INIT_ORG: hlaeja_ltd
DOCKER_INFLUXDB_INIT_BUCKET: device-data
```
## PostgreSQL
PostgreSQL is a powerful, open-source relational database management system (RDBMS). Known for its reliability and advanced features, it supports SQL for querying and managing data, along with extensive functionality for scalability and extensibility.
### Environment
```text
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
```
## Apache Cassandra
Apache Cassandra is a distributed NoSQL database designed for handling large amounts of data across many commodity servers with no single point of failure. It is optimized for high availability, scalability, and fault tolerance.
### Environment
```text
CASSANDRA_USER: cassandra
CASSANDRA_PASSWORD: password
```
## Redis
Redis is an in-memory data store that can be used as a database, message broker, or cache layer. It is designed for high performance and low latency, making it suitable for real-time web applications.
### Environment
```text
REDIS_PASSWORD: password
```

116
doc/docker_hlaeja.md Normal file
View File

@@ -0,0 +1,116 @@
# Hlæja Services
## Device Data
### Environment
```text
SPRING_PROFILES_ACTIVE: docker
INFLUXDB_TOKEN: influxdbToken==
```
## Device Registry
### Environment
```text
SPRING_R2DBC_URL: r2dbc:postgresql://localhost:5432/device_registry
SPRING_R2DBC_USERBAME: services
SPRING_R2DBC_PASSWORD: password
JWT_PRIVATE_KEY: cert/private_key.pem
```
### Volume
Mount a local private key into the container. Read [`rsa_key.md`](./rsa_key.md) for how to generate.
```text
volumes:
- ./cert/device_private_key.pem:/app/resources/cert/private_key.pem
```
## Device API
### Environment
```text
SPRING_PROFILES_ACTIVE: docker
```
### Volume
Mount a local public key into the container. Read [rsa_key.md](./rsa_key.md) for how to generate.
Mount a local keystore into the container. Read [keystore.md](./keystore.md) for how to generate.
```text
volumes:
- ./cert/device_public_key.pem:/app/resources/cert/public_key.pem
- ./cert/device_api_keystore.p12:/app/resources/cert/keystore.p12
```
## Device Configuration
### Environment
```text
SPRING_PROFILES_ACTIVE: docker
```
## Registry API
### Environment
```text
SPRING_PROFILES_ACTIVE: docker
```
### Volume
Mount a local public key into the container. Read [rsa_key.md](./rsa_key.md) for how to generate.
Mount a local keystore into the container. Read [keystore.md](./keystore.md) for how to generate.
```text
volumes:
- ./cert/account_public_key.pem:/app/resources/cert/public_key.pem
- ./cert/registry_api_keystore.p12:/app/resources/cert/keystore.p12
```
## Account Registry
### Environment
```text
SPRING_R2DBC_URL: r2dbc:postgresql://localhost:5432/account_registry
SPRING_R2DBC_USERBAME: services
SPRING_R2DBC_PASSWORD: password
JWT_PRIVATE_KEY: cert/private_key.pem
```
### Volume
Mount a local private key into the container. Read [`rsa_key.md`](./rsa_key.md) for how to generate.
```text
volumes:
- ./cert/account_private_key.pem:/app/resources/cert/private_key.pem
```
## Management
### Environment
```text
SPRING_PROFILES_ACTIVE: docker
```
### Volume
Mount a local public key into the container. Read [rsa_key.md](./rsa_key.md) for how to generate.
```text
volumes:
- ./cert/account_public_key.pem:/app/resources/cert/public_key.pem
```

26
doc/global_settings.md Normal file
View File

@@ -0,0 +1,26 @@
# Global settings
Hlaeja services utilize Gradle options or environment variables to configure development settings, ensuring our configurations remain organized and secure.
## Overview
By using these methods, we can easily manage access to restricted resources and maintain a consistent configuration across our services. This approach enables us to keep sensitive information separate from our codebase.
## Gradle properties
To access repositories that require authentication, we set `repository.user` and `repository.token` properties in the `gradle.properties` file. To do this:
1. Open or create the `gradle.properties` file in your Gradle user home directory:
- On Unix-like systems (Linux, macOS), this is typically located at `~/.gradle/`.
- On Windows, this is typically located at `C:\Users\<YourUsername>\.gradle\`.
2. Add the following settings to the `gradle.properties` file:
```properties
repository.user=your_user
repository.token=your_token_value
```
## Environment variables
Alternatively, you can use `REPOSITORY_USER` and `REPOSITORY_TOKEN` environment variables to pass credentials to the application. These variables can be set in your system environment or through your IDE.

46
doc/keystore.md Normal file
View File

@@ -0,0 +1,46 @@
# Generate Keystore
### Generate Keystores
To generate a keystore for our API's and web manager, which is used to enable HTTPS, you can use the following command:
```shell
keytool -genkeypair -alias <service> -keyalg RSA -keysize 2048 -validity 3650 -dname "CN=<domain>" -keypass <password> -keystore ./cert/<keystore>.p12 -storetype PKCS12 -storepass <password>
```
This command generates a keystore with the following properties:
* \<service>: The alias for the service (e.g. device-api)
* \<domain>: The domain name for the service (e.g. deviceapi)
* \<password>: The password for the keystore and private key
* ./cert/\<keystore>.p12: The file path and name for the generated keystore
### Export the public certificate
Once you have generated a keystore, you can export the public certificate using the following command:
```shell
keytool -export -alias <service> -keystore ./cert/<keystore>.p12 -storepass <password> -file ./cert/<domain>.cer -rfc
```
This command exports the public certificate with the following properties:
* \<service>: The alias for the service (e.g. device-api)
* \<keystore>: The keystore file containing the private key and certificate (e.g. ./cert/deviceapi.p12)
* \<password>: The password for the keystore
* \<domain>: The domain name for the exported certificate file (e.g. deviceapi.cer)
* ./cert/\<domain>.cer: The file path and name for the exported public certificate
The exported public certificate is then used on devices to establish a secure connection to our API. Specifically, the certificate is installed on devices to enable them to trust our API's SSL/TLS connection, allowing for encrypted communication between the device and our API.
Note: Make sure to update your hosts file with an entry for the domain name (e.g. 127.0.0.1 deviceapi) to enable local development.
1. Open `hosts` file:
* On Unix-like systems (Linux, macOS), this directory is typically `/etc/hosts`.
* On Windows, this directory is typically `%SystemRoot%\System32\drivers\etc\hosts`.
2. Add the following lines to the `hosts` file:
```text
127.0.0.1 deviceapi # Hlæja Device API
```

105
hlaeja-compose.yml Normal file
View File

@@ -0,0 +1,105 @@
name: hlaeja-development
networks:
develop:
name: develop
external: true
services:
device-registry:
image: hlaeja-device-registry:0.4.0
container_name: DeviceRegistry
restart: unless-stopped
environment:
SPRING_PROFILES_ACTIVE: docker
networks:
- develop
ports:
- 9010:8080
# mount a local `device_private_key.pem` into the container.
volumes:
- ./cert/device_private_key.pem:/app/resources/cert/private_key.pem
device-data:
image: hlaeja-device-data:0.1.1
container_name: DeviceData
restart: unless-stopped
environment:
SPRING_PROFILES_ACTIVE: docker
INFLUXDB_TOKEN: influxdbToken==
networks:
- develop
ports:
- 9020:8080
device-configuration:
image: hlaeja-device-configuration:0.1.0
container_name: DeviceConfiguration
restart: unless-stopped
environment:
SPRING_PROFILES_ACTIVE: docker
networks:
- develop
ports:
- 9030:8080
device-api:
image: hlaeja-device-api:0.4.0
container_name: DeviceApi
restart: unless-stopped
environment:
SPRING_PROFILES_ACTIVE: docker
MANAGEMENT_INFLUX_METRICS_EXPORT_TOKEN: influxdbToken==
networks:
- develop
ports:
- 9000:8443
# mount a local `device_public_key.pem` and `device_api_keystore.p12` into the container.
volumes:
- ./cert/device_public_key.pem:/app/resources/cert/public_key.pem
- ./cert/device_api_keystore.p12:/app/resources/cert/keystore.p12
registry-api:
image: hlaeja-registry-api:0.2.0
container_name: RegistryApi
restart: unless-stopped
environment:
SPRING_PROFILES_ACTIVE: docker
MANAGEMENT_INFLUX_METRICS_EXPORT_TOKEN: influxdbToken==
networks:
- develop
ports:
- 9040:8443
# mount a local `account_public_key.pem` and `registry_api_keystore.p12` into the container.
volumes:
- ./cert/registry_api_keystore.p12:/app/resources/cert/keystore.p12
- ./cert/account_public_key.pem:/app/resources/cert/public_key.pem
account-registry:
image: hlaeja-account-registry:0.2.0
container_name: AccountRegistry
restart: unless-stopped
environment:
SPRING_PROFILES_ACTIVE: docker
networks:
- develop
ports:
- 9050:8080
# mount a local `account_private_key.pem` into the container.
volumes:
- ./cert/account_private_key.pem:/app/resources/cert/private_key.pem
management:
image: hlaeja-management:0.1.0
container_name: Management
restart: unless-stopped
environment:
SPRING_PROFILES_ACTIVE: docker
networks:
- develop
ports:
- 9060:8080
# mount a local `account_public_key.pem` into the container.
volumes:
- ./cert/account_public_key.pem:/app/resources/cert/public_key.pem