Skip to content

Commit

Permalink
Merge branch 'release/v0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Onyxmoon committed Jan 17, 2024
2 parents 21ea61c + 0694cb4 commit d6414c9
Show file tree
Hide file tree
Showing 72 changed files with 2,116 additions and 4,060 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.sh text eol=lf
2 changes: 1 addition & 1 deletion .github/workflows/create coverage badge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Run Test
run: |
go test -v hsfl.de/group6/hsfl-master-ai-cloud-engineering/... -covermode=count -coverprofile=coverage.out
go test -v hsfl.de/group6/hsfl-master-ai-cloud-engineering/... -covermode=count -coverprofile=coverage.out --tags=integration
go tool cover -func=coverage.out -o=coverage.out
- name: Go Coverage Badge # Pass the `coverage.out` output to this action
Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/run-tests-http-proxy-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ jobs:
with:
go-version: 1.21

- name: Install dependencies
working-directory: ./src/http-proxy-service
run: go mod tidy

- name: Build
working-directory: ./src/http-proxy-service
run: go build -v ./...

- name: Test Go Module
run: |
cd src/http-proxy-service
Expand Down
24 changes: 0 additions & 24 deletions .github/workflows/run-tests-lib-folder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,6 @@ jobs:
with:
go-version: 1.21

- name: Install dependencies for config
working-directory: ./lib/config
run: go mod tidy

- name: Install dependencies for router
working-directory: ./lib/router
run: go mod tidy

- name: Install dependencies for rpc
working-directory: ./lib/rpc
run: go mod tidy

- name: Build config library
working-directory: ./lib/config
run: go build -v ./...

- name: Build router library
working-directory: ./lib/router
run: go build -v ./...

- name: Build rpc library
working-directory: ./lib/rpc
run: go build -v ./...

- name: Test Go config Module
run: |
cd lib/config
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/run-tests-load-balancer-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Run tests (load balancer service)

on:
push:
paths:
- 'src/load-balancer-service/**'
workflow_dispatch:

jobs:
test:
name: Test web-service
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.21

- name: Test Go Module
run: |
cd src/load-balancer-service
go test ./...
test_exit_code=$? # Capture the exit code of the go test command
if [ $test_exit_code -eq 0 ]; then
echo "Tests passed successfully."
else
echo "Tests failed with exit code $test_exit_code."
exit 1 # Fail the GitHub Actions workflow
fi
10 changes: 1 addition & 9 deletions .github/workflows/run-tests-product-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,10 @@ jobs:
with:
go-version: 1.21

- name: Install dependencies
working-directory: ./src/product-service
run: go mod tidy

- name: Build
working-directory: ./src/product-service
run: go build -v ./...

- name: Test Go Module
run: |
cd src/product-service
go test ./...
go test ./... --tags=integration
test_exit_code=$? # Capture the exit code of the go test command
if [ $test_exit_code -eq 0 ]; then
echo "Tests passed successfully."
Expand Down
10 changes: 1 addition & 9 deletions .github/workflows/run-tests-shoppinglist-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,10 @@ jobs:
with:
go-version: 1.21

- name: Install dependencies
working-directory: ./src/shoppinglist-service
run: go mod tidy

- name: Build
working-directory: ./src/shoppinglist-service
run: go build -v ./...

- name: Test Go Module
run: |
cd src/shoppinglist-service
go test ./...
go test ./... --tags=integration
test_exit_code=$? # Capture the exit code of the go test command
if [ $test_exit_code -eq 0 ]; then
echo "Tests passed successfully."
Expand Down
10 changes: 1 addition & 9 deletions .github/workflows/run-tests-user-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,10 @@ jobs:
with:
go-version: 1.21

- name: Install dependencies
working-directory: ./src/user-service
run: go mod tidy

- name: Build
working-directory: ./src/user-service
run: go build -v ./...

- name: Test Go Module
run: |
cd src/user-service
go test ./...
go test ./... --tags=integration
test_exit_code=$? # Capture the exit code of the go test command
if [ $test_exit_code -eq 0 ]; then
echo "Tests passed successfully."
Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/run-tests-web-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ jobs:
with:
go-version: 1.21

- name: Install dependencies
working-directory: ./src/web-service
run: go mod tidy

- name: Build
working-directory: ./src/web-service
run: go build -v ./...

- name: Test Go Module
run: |
cd src/web-service
Expand Down
10 changes: 10 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,13 @@ packages:
interfaces:
Controller:
Repository:
hsfl.de/group6/hsfl-master-ai-cloud-engineering/user-service/auth:
config:
dir: "./src/user-service/auth/_mock"
interfaces:
TokenGenerator:
hsfl.de/group6/hsfl-master-ai-cloud-engineering/user-service/crypto:
config:
dir: "./src/user-service/crypto/_mock"
interfaces:
Hasher:
2 changes: 1 addition & 1 deletion README.assets/CE_Architecture_Prototype.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 40 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Price Whisper
![Coverage](https://img.shields.io/badge/Coverage-75.1%25-brightgreen)
![Coverage](https://img.shields.io/badge/Coverage-83.3%25-brightgreen)
![GitHub release (by tag)](https://img.shields.io/github/v/tag/onyxmoon/hsfl-master-ai-cloud-engineering.svg?sort=semver&label=Version&color=4ccc93d)
[![Run tests (lib folder)](https://github.com/Onyxmoon/hsfl-master-ai-cloud-engineering/actions/workflows/run-tests-lib-folder.yml/badge.svg)](https://github.com/Onyxmoon/hsfl-master-ai-cloud-engineering/actions/workflows/run-tests-lib-folder.yml)
[![Run tests (http proxy service)](https://github.com/Onyxmoon/hsfl-master-ai-cloud-engineering/actions/workflows/run-tests-http-proxy-service.yml/badge.svg)](https://github.com/Onyxmoon/hsfl-master-ai-cloud-engineering/actions/workflows/run-tests-http-proxy-service.yml)
Expand All @@ -25,13 +25,31 @@ Key features:

![Architecture](README.assets/CE_Architecture_Prototype.svg)

## Requirements
### Development
## Setup project in Kubernetes
The complete application can be deployed within a kubernetes cluster.
1. Manifest files for deployment (including monitoring) are located at [`kubernetes/manifests`](kubernetes/manifests)
2. It is optional but highly recommended to set your own username and password for the database access in manifest files (replace `db-username` and `db-pw-changeMe!` in each service manifest).
> Some special characters are not possible because RQLite uses basic auth. Please use url-safe characters like Alphanumeric [0-9a-zA-Z], special characters $-_.+!*'(),.
3. The user service ([`price-whisper/user.yaml`](kubernetes/manifests/price-whisper/users.yaml)) uses JWT tokens for authentication while logged-in. A custom ECDSA private key can be specified as path or inline in environment variable `JWT_PRIVATE_KEY`.

Generate a key with the following command:
```shell
ssh-keygen -t ecdsa -f ./src/user-service/privateKey.pem -m pem
```
> When step is missing, container will use a random but secure generated key on each start, but users will be logged-out at restarts.
4. Apply the manifests in `kubernetes/manifests` to your kubernetes control plane.
```shell
kubectl apply -R -f ./kubernetes/manifests
```
5. The main page can be accessed via the public port of the `HTTP Proxy Service` container.
Monitoring can be accessed via the Grafana public port. There is an example dashboard configuration file at [kubernetes/grafana](kubernetes/grafana/dashboard-config.json).
## Setup project in Docker
### Requirements
- Docker Compose version v2.23.3
- a compatible container daemon

## Setup the project
### Development setup via docker-compose
> The development setup exposes all ports to the host machine, so you can access each service individually. Docker will build local and database is not persistent in this setup.
> The development setup exposes all ports to the host machine, so you can access each service individually. Docker will build locally and the database is not persistent in this setup.
1. Clone repository from Github `git clone https://github.com/Onyxmoon/hsfl-master-ai-cloud-engineering.git`
2. Set your own username and password for the database access in compose file (replace `db-username` and `db-pw-changeMe!`).
> Some special characters are not possible because RQLite uses basic auth. Please use url-safe characters like Alphanumeric [0-9a-zA-Z], special characters $-_.+!*'(),.
Expand Down Expand Up @@ -65,14 +83,23 @@ Key features:
```
> When step is missing, container will use a random but secure generated key on each start.
4. Run `docker compose -f docker-compose.yml up -d` to start the containers defined in the Compose file
5. Run `docker compopse down` to stop container, networks, volumes, and images created by up.

### Setup with kubernetes
1. SECRETS
1. Apply the manifests in `kubernetes/manifests`
```shell
kubectl apply -R -f ./kubernetes/manifests
```
5. Run `docker compose down` to stop container, networks, volumes, and images created by up.

## Testing
To run all tests, you can use the following command in the root directory:
```shell
go test -v hsfl.de/group6/hsfl-master-ai-cloud-engineering/...
```

### Integration tests
If you want to include integrations tests in your test flow use the following command:
```shell
go test -v hsfl.de/group6/hsfl-master-ai-cloud-engineering/... --tags=integration
```
> Please note, that a with [Testcontainers](https://testcontainers.com/) compatible container daemon is needed.
> - Docker Desktop
> - Docker Engine on Linux
> - Testcontainers Cloud
## Authors

Expand Down
24 changes: 24 additions & 0 deletions kubernetes/kubernetes-cluster/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Kubernetes Cluster Setup

This README guides you through the process of setting up a Kubernetes cluster with vms using Vagrant and Ansible. Ensure that you have all necessary dependencies installed, including Ansible, Vagrant, and any SSH tools needed.

## Steps to Follow

1. First, change to the `kubernetes-cluster` directory
2. Move your ssh public key into `kubernetes-cluster/ubuntu/vagrant/id_rsa.pub`
3. Start the vm deployment with `vagrant up`
4. Change, to the `ansible_playbooks` folder
5. Optional: Sometimes you have to specify the ansible config
```shell
export ANSIBLE_CONFIG=./ansible.cfg
```
6. Run `ansible-playbook setup.yaml` to setup cluster

> The first time the manifests are automatically deployed after commissioning, the distribution of the pods may not be uniform.

## Additional Notes
Ensure that Ansible is properly installed and configured on your system.
Verify that the SSH key has the correct permissions and is recognized by your system.
If you encounter any issues, consult the official Kubernetes and Ansible documentation for troubleshooting steps.
Conclusion
Following these steps should successfully set up a Kubernetes cluster using Ansible. For more detailed instructions or advanced configurations, refer to the Kubernetes and Ansible official documentation.
21 changes: 19 additions & 2 deletions kubernetes/manifests/price-whisper/database.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ stringData:
config.json: |
[
{
"username": "username",
"password": "changeMe!",
"username": "db-username",
"password": "db-pw-changeMe!",
"perms": [ "all" ]
},
{
Expand All @@ -20,13 +20,30 @@ stringData:
]
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: database-data
annotations:
author: Gruppe 6 <philipp.borucki@stud.hs-flensburg.de | dorien.groenwald@stud.hs-flensburg.de | jannick.lindner@stud.hs-flensburg.de>
spec:
capacity:
storage: 1Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
hostPath:
path: /var/price-whisper/database-data/
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: database-data
namespace: price-whisper
annotations:
author: Gruppe 6 <philipp.borucki@stud.hs-flensburg.de | dorien.groenwald@stud.hs-flensburg.de | jannick.lindner@stud.hs-flensburg.de>
spec:
volumeName: database-data
accessModes:
- ReadWriteOnce
resources:
Expand Down
4 changes: 2 additions & 2 deletions kubernetes/manifests/price-whisper/products.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ metadata:
annotations:
author: Gruppe 6 <philipp.borucki@stud.hs-flensburg.de | dorien.groenwald@stud.hs-flensburg.de | jannick.lindner@stud.hs-flensburg.de>
stringData:
RQLITE_USER: "username"
RQLITE_PASSWORD: "changeMe!"
RQLITE_USER: "db-username"
RQLITE_PASSWORD: "db-pw-changeMe!"
---
apiVersion: v1
kind: ConfigMap
Expand Down
4 changes: 2 additions & 2 deletions kubernetes/manifests/price-whisper/shoppinglists.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ metadata:
annotations:
author: Gruppe 6 <philipp.borucki@stud.hs-flensburg.de | dorien.groenwald@stud.hs-flensburg.de | jannick.lindner@stud.hs-flensburg.de>
stringData:
RQLITE_USER: "username"
RQLITE_PASSWORD: "changeMe!"
RQLITE_USER: "db-username"
RQLITE_PASSWORD: "db-pw-changeMe!"
---
apiVersion: v1
kind: ConfigMap
Expand Down
46 changes: 46 additions & 0 deletions kubernetes/manifests/price-whisper/test-data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
apiVersion: v1
kind: Secret
metadata:
name: test-data-secrets
namespace: price-whisper
annotations:
author: Gruppe 6 <philipp.borucki@stud.hs-flensburg.de | dorien.groenwald@stud.hs-flensburg.de | jannick.lindner@stud.hs-flensburg.de>
stringData:
RQLITE_USER: "db-username"
RQLITE_PASSWORD: "db-pw-changeMe!"
---
apiVersion: v1
kind: ConfigMap
metadata:
name: test-data-config
namespace: price-whisper
annotations:
author: Gruppe 6 <philipp.borucki@stud.hs-flensburg.de | dorien.groenwald@stud.hs-flensburg.de | jannick.lindner@stud.hs-flensburg.de>
data:
RQLITE_HOST: "database"
RQLITE_PORT: "4001"
---
apiVersion: v1
kind: Pod
metadata:
name: test-data-pod
namespace: price-whisper
annotations:
author: Gruppe 6 <philipp.borucki@stud.hs-flensburg.de | dorien.groenwald@stud.hs-flensburg.de | jannick.lindner@stud.hs-flensburg.de>
spec:
restartPolicy: OnFailure
initContainers:
- name: wait-for-database
image: busybox
command: [ "/bin/sh", "-c" ]
args: [ "until wget --spider -S http://database:4001/readyz 2>&1 | grep 'HTTP/1.1 200 OK'; do echo 'Waiting for RQLite...'; sleep 2; done;" ]
containers:
- name: test-data-container
image: onyxmoon/pw-database-rqlite-test-data-init:latest
envFrom:
- secretRef:
name: test-data-secrets
- configMapRef:
name: test-data-config

---
Loading

0 comments on commit d6414c9

Please sign in to comment.