## pOST Social Media

### Arch Linux mit speziellem file system

Dateisystem erstellen

```
sudo mkdir -p /mnt/podman-tmp && \
sudo mount -t tmpfs -o rw,dev,exec,suid,size=10G,mode=0755 tmpfs /mnt/podman-tmp && \
sudo chown "$USER:$USER" /mnt/podman-tmp
```

für podman Dateisystem vorbereiten (?)

```
cat > ~/podman-tmp-storage.conf <<'EOF'
[storage]
driver = "overlay"
runroot = "/mnt/podman-tmp/runroot"
graphroot = "/mnt/podman-tmp/store"
EOF
```

Konfiguration für kind mit podman und Dateisystem

```
export KIND_EXPERIMENTAL_PROVIDER=podman # damit kind auf podman nicht auf docker läuft, auch in flake.nix
export CONTAINERS_STORAGE_CONF=~/podman-tmp-storage.conf
export GLIBC_TUNABLES=glibc.pthread.rseq=1 #https://forums.docker.com/t/docker-compose-mongo-exit-code-139/151353/10
GLIBC_TUNABLES=glibc.pthread.rseq=1
```

## Usage of the Makefile

To start the entire system (Cluster, Images, Manifests):

```bash
make up
```

For help:

```bash
make help
```

This will:

1. Build the Podman images for client and server.
2. Create a `kind` cluster (if not already existing) with port 3000 exposed.
3. Load the images into the cluster.
4. Apply all Kubernetes manifests.
5. Wait for the services to be ready.

To access the application after startup, run one of these in a separate terminal:

- **Local:** `make local` -> [http://localhost:3000](http://localhost:3000)
- **Public:** `make public` -> [http://localhost:8080](http://localhost:8080)

### WSL make port public to network

Remove after use, because next time the port is not available.

linux: `make public`
windows (in admin cmd) :

```PowerShell
wsl hostname -I
netsh interface portproxy add v4tov4 listenport=8080 listenaddress=0.0.0.0 connectport=8080 connectaddress=<ip address>
```

And remove:

```PowerShell
netsh interface portproxy show all
netsh interface portproxy delete v4tov4 listenport=8080 listenaddress=0.0.0.0
```

[source](https://medium.com/@aliyousefi-dev/how-to-expose-wsl2-to-your-local-network-port-proxy-static-ip-methods-f2d21621f377)

## hey - load test

Perform a load test against a JWT-protected endpoint of your system and document the results. During the presentation, show how your system behaves under load, what the bottleneck could be, and how many requests/second it can handle.

Results are saved in the folder `/hey`

```shell
TOKEN=...

make hey-public:
  hey -n 1000 -c 500 \
  -H "Authorization: Bearer $TOKEN" \
  http://localhost:8080/home > hey/hey-results-npm.txt
  cat hey/hey-results-npm.txt
```

```shell
hey -n 1000 -c 1000 \
-H "Authorization: Bearer $TOKEN" \
http://localhost:8080/home
```

load test the creation of posts, change the userId with data from local storage!

```shell
hey -n 10 -c 10 -m POST \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
  "userId": "6a042e8ea8941f321c293058",
  "description": "load test post"
}' \
http://localhost:3000/posts
```

## Dev Testing (fast setup)

Most important commands, more infos in obsidian notes.
Setup for working on the website.

Important: check if new image did include the changes! `make build-no-cache` and if needed restart the whole kind cluster (`make clean` and `make start-cluster`).

```powershell
# new
# podman pull mongo:8.2.5
podman run -d --name local-mongo -p 27017:27017 docker.io/mongo:8.2.5

# or restart
podman start local-mongo

# -----
# Overview
podman container list
podman ps

# remove image
podman image rm mongo:latest # or version tag

# check if mongodb accessible
mongosh mongodb://localhost:27017/mern-social
```

start server

```bash
wsl
cd /home/jf/wsl-code/ost_4_semester/pOST # of course this only works for my setup
nix develop

cd server
npm install
npm run dev
```

start client

```bash
nix develop
cd client
npm install
npm run start
```

The client will start on `http://localhost:3000`.

### Debug Mongodb local

```
nix-shell -p mongosh
mongosh  mongodb://localhost:27017/mern-social
```

## Set up in cluster from ost

Todo..

## Set up Kind with podman

<!-- (Podman Machine is running in Podman Desktop) -->

1. Install podman on linux `podman -v`
1. install packages, if possible: `nix develop`
1. use the `make` commands for creating or restarting cluster and setting up kind environment `make help`

#### Start kind cluster again

- Podman Desktop: Settings > Resources > start kind cluster
  View Kubernetes Clusters + Context in Settings > Kubernetes
- Podman shell: `make restart-cluster`

#### First Time Setup with Podman Desktop

1. Open **Podman Desktop**.
2. Go to **Extensions**.
3. Ensure the **Kind** extension is enabled.
4. Go to the **Kind** tab, **Settings** (gear icon) > Resources (or search for Kind in the dashboard) and click **Create Cluster**.
5. Give it a name (e.g., `mern-cluster`) and ensure it uses the Podman engine.

**Tipp** click "show logs" for example while creating a kind cluster.
