Skip to content

Commit

Permalink
Merge branch 'main' into feature/intro-documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mala1180 authored Sep 18, 2024
2 parents 87bab59 + 936a630 commit b5459a6
Show file tree
Hide file tree
Showing 51 changed files with 662 additions and 444 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
LICENSE
README.md
docs
kubernetes
**/tsconfig.tsbuildinfo
**/Dockerfile
**/docker-compose.yml
Expand Down
20 changes: 10 additions & 10 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -117,29 +117,29 @@ MEDIA_SERVER_RTSP_PORT=8554
FRONTEND_PORT=8080
FRONTEND_HOST=revue-frontend

VITE_AUTH_HOST=auth.localhost
VITE_AUTH_HOST=auth
VITE_AUTH_PORT=${AUTH_PORT}

VITE_USER_HOST=user.localhost
VITE_USER_HOST=user
VITE_USER_PORT=${USER_PORT}

VITE_LOCATION_HOST=location.localhost
VITE_LOCATION_HOST=location
VITE_LOCATION_PORT=${LOCATION_PORT}

VITE_ALARM_HOST=alarm.localhost
VITE_ALARM_HOST=alarm
VITE_ALARM_PORT=${ALARM_PORT}

VITE_DEVICE_HOST=device.localhost
VITE_DEVICE_HOST=device
VITE_DEVICE_PORT=${DEVICE_PORT}

VITE_MONITORING_HOST=monitoring.localhost
VITE_MONITORING_HOST=monitoring
VITE_MONITORING_PORT=${MONITORING_PORT}

VITE_NOTIFICATION_HOST=notification.localhost
VITE_NOTIFICATION_HOST=notification
VITE_NOTIFICATION_PORT=${NOTIFICATION_PORT}

VITE_LOG_HOST=log.localhost
VITE_LOG_HOST=log
VITE_LOG_PORT=${LOG_PORT}

VITE_MEDIA_SERVER_HOST=media-server.localhost

VITE_MEDIA_SERVER_HOST=media-server
VITE_MEDIA_SERVER_PORT=8554
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "kubernetes"]
path = kubernetes
url = https://github.com/revue-org/revue-kubernetes.git
358 changes: 358 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

68 changes: 40 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ the [revue-sample-thing](https://github.com/revue-org/revue-sample-thing) reposi

## Getting Started

- Download the latest version from [Releases](https://github.com/Mala1180/revue/releases)
- Unzip the archive
- Clone the repository including the submodules: `git clone --recurse-submodules [email protected]:revue-org/revue.git`
- Modify the `.env` file to fit your needs, e.g., the ports and the credentials to be used (the default ones should be
fine)

Expand All @@ -84,62 +83,75 @@ and stop it by running
./undeploy.sh --docker
```

### Going to Production
This running mode includes the deployment of a (WoT) containerised thing.
To see more details about it, check the [revue-sample-thing](https://github.com/revue-org/revue-sample-thing)
repository.

You can deploy the system on a Kubernetes cluster by running
### Running with Kubernetes

In a Kubernetes cluster, on your master node, run the following command to deploy the system:

```bash
./deploy.sh --k8s --driver=<driver>
./deploy.sh --k8s
```

where `<driver>` is the driver to be used by Minikube (e.g., `docker`, `qemu`, `virtualbox`, etc.).
See the [Minikube documentation](https://minikube.sigs.k8s.io/docs/drivers/) for more information.

Note that to make the `LoadBalancer` work, the `deploy.sh` script will run the `minikube tunnel` command that requires
root
privileges. It is also required to keep the terminal open to keep the tunneling active.

To stop the system, you have to interrupt the tunneling process and then run
And similarly, to stop the system

```bash
./undeploy.sh --k8s
```

Once the system is up and running, you have to set up your own WoT device (E.g. [revue-sample-thing](https://github.com/revue-org/revue-sample-thing)).

## Interacting with the system

### Web interfaces

- **Revue Web Interface**: The interface through which you can interact with the
system ([https://frontend.localhost](https://frontend.localhost) or [https://localhost:8080](https://localhost:8080))
- The default credentials for the login are `user` and `user` (editable
in [auth/db/auth-init.js](auth/db/auth-init.js)
file).
- **API Gateway**: Traefik dashboard ([https://localhost:8081](https://localhost:8081))
system. The default credentials for the login are `user` and `user` (editable
in [auth/db/auth-init.js](auth/db/auth-init.js)
file).
- [https://frontend.localhost](https://frontend.localhost) or [https://localhost:8080](https://localhost:8080) if
running with Docker Compose
- [https://revue-frontend](https://revue-frontend) if running with Kubernetes
- **Reverse Proxy**: Traefik dashboard
- [https://localhost:8081](https://localhost:8081) if running with Docker Compose
- [https://revue-traefik/dashboard/#/](https://revue-traefik/dashboard/#/) if running with Kubernetes
- **Kafka UI**: The interface to monitor the Kafka topics, messages and
consumers ([https://localhost:8082](https://localhost:8082))
- In production mode, you have to access it by running `minikube service kafka-ui`
- **Prometheus and Grafana**: The interfaces to monitor the system **(only in production mode)**
- Prometheus Server dashboard: accessible by running `minikube service prometheus-server`
- Grafana dashboard: accessible by running `minikube service grafana`
consumers
- [https://localhost:8082](https://localhost:8082) if running with Docker Compose
- [https://revue-kafka-ui](https://revue-kafka-ui) if running with Kubernetes,

#### On Kubernetes environment

- **Prometheus and Grafana**: The interfaces to monitor the system
- Prometheus Server dashboard: accessible at [https://revue-prometheus](https://192.168.5.206:9090)
- Grafana dashboard: accessible at [https://revue-grafana](https://revue-grafana)
- Credentials:
- Username: _admin_
- Password: Get the password by
running `kubectl get secret --namespace default grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo`
- Accessing to the dashboard clicking on _Dashboards_ (there are some pre-configured dashboards)

Note that kubernetes IPs depend on your cluster's network-specific configuration.
Edit configuration files in [kubernetes/specifications/metallb/](kubernetes/specifications/metallb/) folder
to adhere to your case.
### Monitoring with devices (WoT)

Go to the [revue-sample-thing](https://github.com/revue-org/revue-sample-thing) repository and follow the instructions
in the README to set up your own WoT device.
Note that if you are running the system with Docker Compose, a sample containerised device is already deployed.
Once the device is up and running, you can add it to the system through the Revue Web Interface.

- Go to [https://frontend.localhost](https://frontend.localhost) and log in
- Go to [Revue Web Interface](#web-interfaces) and log in
- Go to the _Devices_ section
- Click on the _Add Device_ button
- Fill in the form with the device URL (`localhost` if it is running on the same machine as the system) and test the
connection.
If the connection is successful, it will automatically retrieve the device capabilities.
Eventually, give a description and click _Ok_ to add the device to the system.
- Fill in the form with the device URI
- `<container-name>:<exposed-port>` if revue is running with Docker Compose
- The already deployed sample device is exposed at `revue-thing:6000`
- Test the connection.
- If the connection is successful, it will automatically retrieve the device's capabilities.
Eventually, give a description and click _Ok_ to add the device to the system.
- Monitor the device data through the various sections depending on the device capabilities.

## Authors
Expand Down
2 changes: 1 addition & 1 deletion alarm/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# syntax = docker/dockerfile:1.9
# syntax = docker/dockerfile:1.10

FROM gradle AS build
LABEL maintainer="[email protected], [email protected]"
Expand Down
1 change: 0 additions & 1 deletion alarm/src/application/services/impl/AlarmServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ export class AlarmServiceImpl implements AlarmService {
}

private checkIfDateIsInRange = (date: Date, from: Date, to: Date): boolean => {
// TODO: unit testing this function could be a good idea :D
date.setHours(date.getHours() + 1) // correction due to timezone
return (
(date.getHours() > from.getHours() ||
Expand Down
2 changes: 1 addition & 1 deletion auth/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# syntax = docker/dockerfile:1.9
# syntax = docker/dockerfile:1.10

FROM gradle AS build
LABEL maintainer="[email protected], [email protected]"
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ repositories {
}

dependencies {
implementation("io.github.kelvindev15:npm-gradle-plugin:3.2.1")
implementation("io.github.kelvindev15:npm-gradle-plugin:3.2.3")
}
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/configure-npm.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ packageJson {
"prettier" version "^3.0.3"
"supertest" version "^7.0.0"
"tsc-alias" version "^1.8.8"
"typescript" version "5.5.4"
"typescript" version "5.6.2"
"vite" version "^5.0.0"
"vitest" version "^2.0.0"
}
Expand Down
2 changes: 1 addition & 1 deletion common/src/infrastructure/events/KafkaConsumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default class KafkaConsumer {
const kafka: Kafka = new Kafka({
clientId: this.kafkaOptions.clientId,
brokers: this.kafkaOptions.brokers.map(broker => `${broker.host}:${broker.port}`),
logLevel: logLevel.INFO //getLogLevel() TODO: remove comment
logLevel: logLevel.INFO
})
return kafka.consumer({ groupId: this.kafkaOptions.groupId! })
}
Expand Down
5 changes: 4 additions & 1 deletion common/src/utils/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ const getDatabaseConfig = (serviceName: string): DatabaseConfig => {
export const mongoConnect = async (mongoose: Mongoose, serviceName: string): Promise<void> => {
const { host, port, name } = getDatabaseConfig(serviceName)
const { username, password } = getDatabaseCredentials(serviceName)
const connectionString: string = `mongodb://${username}:${password}@${host}:${port}/${name}?authSource=admin`
const connectionString: string =
process.env.NODE_ENV === 'develop'
? `mongodb://${username}:${password}@${host}:${port}/${name}?authSource=admin`
: `mongodb://${username}:${password}@${host}/${name}?authSource=admin`
console.log(connectionString)
await mongoose
.connect(connectionString)
Expand Down
74 changes: 20 additions & 54 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,81 +2,47 @@

# Function to display usage information
usage() {
echo "Usage: $0 --docker [--build] | --k8s [--driver=<driver>]"
echo "Usage: $0 --docker [--build] | --k8s"
exit 1
}

# Function to check if Minikube is running
check_minikube() {
status=$(minikube status --format='{{.Host}}')

if [ "$status" == "Running" ]; then
return 0
else
return 1
fi
}

# Function to start Minikube with a specified driver
start_minikube() {
driver=$1
if [ -z "$driver" ]; then
minikube start
else
minikube start --driver="$driver"
fi
}

# Check if no arguments were provided
if [ $# -eq 0 ]; then
usage
fi

# Initialize variables
driver="docker"

# Parse arguments
while [ $# -gt 0 ]; do
case "$1" in
--docker)
if [ "$2" == "--build" ]; then
./scripts/compose-all.sh --up -d --build
exit 0
elif [ -z "$2" ]; then
./scripts/compose-all.sh --up -d
exit 0
else
usage
fi
source .env
docker run -d \
--name revue-thing \
--restart on-failure \
--network revue-network \
--env THING_ID=thing-1 \
--env THING_PORT=6000 \
--env THING_LOCATION=room-1 \
--env KAFKA_HOST_1="$KAFKA_HOST_1"\
--env KAFKA_PORT_1="$KAFKA_PORT_1" \
--env KAFKA_HOST_2="$KAFKA_HOST_2" \
--env KAFKA_PORT_2="$KAFKA_PORT_2" \
--env MEDIA_SERVER_HOST="$MEDIA_SERVER_HOST" \
--env MEDIA_SERVER_RTSP_PORT="$MEDIA_SERVER_RTSP_PORT" \
-p 6000:6000 \
letsdothisshared/revue-thing
exit 0
;;
--k8s)
./gradlew generate-k8s-specifications
if [[ "$2" == --driver=* ]]; then
driver="${2#*=}"
shift
fi

if [ -z "$2" ]; then
if check_minikube; then
echo "Minikube is already running."
else
echo "Starting Minikube..."
start_minikube "$driver"
fi
helm repo add traefik https://traefik.github.io/charts
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
helm install traefik traefik/traefik --values gateway/traefik-values.yml
helm install prometheus prometheus-community/prometheus -f prometheus/prometheus-values.yml
helm install grafana grafana/grafana -f prometheus/grafana-values.yml

kubectl apply -f build/k8s
sudo minikube tunnel
exit 0
else
usage
fi
./kubernetes/deploy.sh
exit 0
;;
*)
usage
Expand Down
2 changes: 1 addition & 1 deletion device/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# syntax = docker/dockerfile:1.9
# syntax = docker/dockerfile:1.10

FROM gradle AS build
LABEL maintainer="[email protected], [email protected]"
Expand Down
8 changes: 4 additions & 4 deletions docs/website/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@docusaurus/module-type-aliases": "3.5.2",
"@docusaurus/tsconfig": "3.5.2",
"@docusaurus/types": "3.5.2",
"typescript": "~5.5.0"
"typescript": "~5.6.0"
},
"browserslist": {
"production": [
Expand Down
Loading

0 comments on commit b5459a6

Please sign in to comment.