Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fritzthecat9/dockerblazorwasmtest
Deploy C# web API backend, Blazor WASM frontend, and Postgres database to Raspberry Pi with Docker
https://github.com/fritzthecat9/dockerblazorwasmtest
api blazor blazor-client blazor-webassembly c-sharp csharp docker docker-compose http https minimal-api nginx postgresql postgresql-database raspberry-pi raspberry-pi-4 raspberry-pi4 wasm
Last synced: about 1 month ago
JSON representation
Deploy C# web API backend, Blazor WASM frontend, and Postgres database to Raspberry Pi with Docker
- Host: GitHub
- URL: https://github.com/fritzthecat9/dockerblazorwasmtest
- Owner: FritzTheCat9
- Created: 2024-04-26T14:58:31.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2024-04-27T15:49:27.000Z (9 months ago)
- Last Synced: 2024-11-07T19:51:55.399Z (3 months ago)
- Topics: api, blazor, blazor-client, blazor-webassembly, c-sharp, csharp, docker, docker-compose, http, https, minimal-api, nginx, postgresql, postgresql-database, raspberry-pi, raspberry-pi-4, raspberry-pi4, wasm
- Language: C#
- Homepage:
- Size: 123 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# DockerBlazorWASMTest
This repository contains C# web API backend with database and Blazor WASM frontend served in docker-compose file.### Generate https certificate for Api:
```
cd %USERPROFILE%
dotnet dev-certs https --clean
dotnet dev-certs https -ep .aspnet\https\aspnetapp.pfx -p password
dotnet dev-certs https --trust
-ep - path to existing certificate file (.pfx) that you want to use for HTTPS development (existing PFX file)
```
### Generate https certificate for Blazor WASM (when generating certificate press ENTER):
```
cd %USERPROFILE%\.aspnet\https
Press ENTER on any prompts after this command:
openssl req -newkey rsa:2048 -nodes -keyout private.key -out certificate.csr
openssl x509 -req -days 365 -in certificate.csr -signkey private.key -out certificate.crt
```
### Run application with one command (setup all docker containers with database, change environment variables depending on system You want to use):
```
cd C:\Users\bartl\source\repos\DockerBlazorWASMTest
docker-compose --env-file linux.env up -d --build
docker-compose --env-file windows.env up -d --build
--env-file - environment variables (other for different configuration / system)
-d - detached mode (services in the background, without blocking the command prompt)
--build - rebuild the docker images
```
### Created containers:
- C# Web API http/https (swagger):
```
http://localhost:5000 (redirect to https 5001)
https://localhost:5001
```
- Blazor WASM frontend http/https:
```
http://localhost:7000 (redirect to https 7001)
https://localhost:7001
```
### Open the Blazor WASM frontend on https://localhost:7001, trust the website.
### Docker compose push (push all containers to docker hub)
```
docker-compose --env-file linux.env push
docker-compose --env-file windows.env push
```
### Copy files to Raspberry Pi (change to correct Raspberry Pi ip)
- Copy "docker-compose.yml" file to Raspberry Pi (using scp)
- Copy "linux.env" file to Raspberry Pi (using scp)
```
scp C:\Users\bartl\source\repos\DockerBlazorWASMTest\docker-compose.yml malinka@:/home/malinka/Desktop/
scp C:\Users\bartl\source\repos\DockerBlazorWASMTest\linux.env malinka@:/home/malinka/Desktop/
```
##### IMPORTANT - COPY CERTIFICATE TO RASPBERRY PI!!! (use scp) -> to: $HOME/.aspnet/https (change to correct Raspberry Pi ip)
```
scp C:\Users\bartl\.aspnet\https\aspnetapp.pfx malinka@:/home/malinka/Desktop
scp C:\Users\bartl\.aspnet\https\private.key malinka@:/home/malinka/Desktop
scp C:\Users\bartl\.aspnet\https\certificate.crt malinka@:/home/malinka/Desktop
ssh malinka@
sudo mv /home/malinka/Desktop/aspnetapp.pfx /home/malinka/.aspnet/https
sudo mv /home/malinka/Desktop/private.key /home/malinka/.aspnet/https
sudo mv /home/malinka/Desktop/certificate.crt /home/malinka/.aspnet/https
ls -la /home/malinka/.aspnet/https
```
### Pull and run Docker Compose on Rapberry Pi / Windows:
```
docker-compose --env-file linux.env pull
docker-compose --env-file linux.env up -d
docker-compose --env-file windows.env pull
docker-compose --env-file windows.env up -d
```
### Check docker images and containers:
```
docker images
docker ps -a
```
### Test Apis:
```
curl http://localhost:5000/api
curl -k https://localhost:5001/api
curl http://localhost:7000/api
curl -k https://localhost:7001/api
-k - ignore certificate check
```
### Helpers:
Update ef core tools:
```
dotnet tool update --global dotnet-ef
```
Remember to change ***MIGRATION_NAME***
```
cd C:\Users\bartl\source\repos\DockerBlazorWASMTest\DockerBlazorWASMTest.Api
dotnet ef migrations add MIGRATION_NAME -o ./Migrations --startup-project ../DockerBlazorWASMTest.Api
dotnet ef migrations add Init -o ./Migrations --startup-project ../DockerBlazorWASMTest.Api
dotnet ef database update
```