Skip to content

Commit

Permalink
working on real identity / auth (#30)
Browse files Browse the repository at this point in the history
* working on real identity / auth

* cleanup

* reorganized folders

* fix centralized packages

* fixed project reference error

* migrated all identity functionality to SQL Server

* fix issues with email sending

* finally have auth working

* defining some shared types

* added Akka.NET messages

* added some DData replication for the index

* added command and event processing for drawings

* defining entity actors and other subscription commands

* add indicies subscriptions

* added Akka.Hosting and Sharding config

* working on defining local paint actors

* added local drawing actor

* added Akka.Hosting support for local actors

* actor startup works correctly

* disable DData persistence

* added data loading to homepage

* fixed up new UI

* fixed startup crash issues

* got new paint session navigation working

* fixing issues with pruning dead sessions

* fixing some UX issues

* fixed SSR
  • Loading branch information
Aaronontheweb authored May 6, 2024
1 parent 40f9117 commit 87c8a0e
Show file tree
Hide file tree
Showing 123 changed files with 6,453 additions and 13 deletions.
15 changes: 14 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,27 @@
<!-- Akka.NET Package Versions -->
<ItemGroup>
<PackageVersion Include="Akka" Version="1.5.20" />
<PackageVersion Include="Akka.Cluster.Hosting" Version="1.5.20" />
<PackageVersion Include="Akka.Hosting" Version="1.5.20" />
<PackageVersion Include="Akka.Hosting.TestKit" Version="1.5.20" />
<PackageVersion Include="Akka.Persistence.Sql.Hosting" Version="1.5.13" />
<PackageVersion Include="Akka.Streams" Version="1.5.20" />
<PackageVersion Include="Akka.Streams.TestKit" Version="1.5.20" />
<PackageVersion Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.4" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.4" />
<PackageVersion Include="MudBlazor" Version="6.19.1" />
</ItemGroup>
<!-- ASP.NET Package Versions -->
<ItemGroup>
<PackageVersion Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.4" />
<PackageVersion Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.4" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4" />
<PackageVersion Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.4" />
<PackageVersion Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.4" />
</ItemGroup>
<!-- FluentEmail Package Versions -->
<ItemGroup>
<PackageVersion Include="FluentEmail.Mailgun" Version="3.0.2" />
<PackageVersion Include="FluentEmail.Razor" Version="3.0.2" />
</ItemGroup>
<!-- OTEL Package Versions -->
<ItemGroup>
Expand Down
68 changes: 68 additions & 0 deletions DrawTogether.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DrawTogether.UI.Server", "s
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DrawTogether.UI.Shared", "src\DrawTogether.UI\Shared\DrawTogether.UI.Shared.csproj", "{308A77AD-9D61-4D4A-B003-CF59B0BCE1A6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{8CE7AE81-DC9A-439A-87CC-7E5CB8F894B1}"
ProjectSection(SolutionItems) = preProject
Directory.Build.props = Directory.Build.props
Directory.Packages.props = Directory.Packages.props
global.json = global.json
nuget.config = nuget.config
README.md = README.md
RELEASE_NOTES.md = RELEASE_NOTES.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DrawTogether.Email", "src\DrawTogether.Email\DrawTogether.Email.csproj", "{ED49A473-3E9F-4689-8297-13C9030565CC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DrawTogether", "src\DrawTogether\DrawTogether.csproj", "{538A12B5-7CE5-4F72-931D-92F1F03495D7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "infrastructure", "infrastructure", "{DB40625F-3958-4D43-8430-C88AEC0FBB1C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DrawTogether.Entities", "src\DrawTogether.Entities\DrawTogether.Entities.csproj", "{7F01390E-AF15-442C-831C-C574D6AAFC1F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DrawTogether.Actors", "src\DrawTogether.Actors\DrawTogether.Actors.csproj", "{5863DD74-00DE-4DE9-9F0A-FCBC32195E78}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -41,6 +61,54 @@ Global
{308A77AD-9D61-4D4A-B003-CF59B0BCE1A6}.Release|x64.Build.0 = Release|Any CPU
{308A77AD-9D61-4D4A-B003-CF59B0BCE1A6}.Release|x86.ActiveCfg = Release|Any CPU
{308A77AD-9D61-4D4A-B003-CF59B0BCE1A6}.Release|x86.Build.0 = Release|Any CPU
{ED49A473-3E9F-4689-8297-13C9030565CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ED49A473-3E9F-4689-8297-13C9030565CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ED49A473-3E9F-4689-8297-13C9030565CC}.Debug|x64.ActiveCfg = Debug|Any CPU
{ED49A473-3E9F-4689-8297-13C9030565CC}.Debug|x64.Build.0 = Debug|Any CPU
{ED49A473-3E9F-4689-8297-13C9030565CC}.Debug|x86.ActiveCfg = Debug|Any CPU
{ED49A473-3E9F-4689-8297-13C9030565CC}.Debug|x86.Build.0 = Debug|Any CPU
{ED49A473-3E9F-4689-8297-13C9030565CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ED49A473-3E9F-4689-8297-13C9030565CC}.Release|Any CPU.Build.0 = Release|Any CPU
{ED49A473-3E9F-4689-8297-13C9030565CC}.Release|x64.ActiveCfg = Release|Any CPU
{ED49A473-3E9F-4689-8297-13C9030565CC}.Release|x64.Build.0 = Release|Any CPU
{ED49A473-3E9F-4689-8297-13C9030565CC}.Release|x86.ActiveCfg = Release|Any CPU
{ED49A473-3E9F-4689-8297-13C9030565CC}.Release|x86.Build.0 = Release|Any CPU
{538A12B5-7CE5-4F72-931D-92F1F03495D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{538A12B5-7CE5-4F72-931D-92F1F03495D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{538A12B5-7CE5-4F72-931D-92F1F03495D7}.Debug|x64.ActiveCfg = Debug|Any CPU
{538A12B5-7CE5-4F72-931D-92F1F03495D7}.Debug|x64.Build.0 = Debug|Any CPU
{538A12B5-7CE5-4F72-931D-92F1F03495D7}.Debug|x86.ActiveCfg = Debug|Any CPU
{538A12B5-7CE5-4F72-931D-92F1F03495D7}.Debug|x86.Build.0 = Debug|Any CPU
{538A12B5-7CE5-4F72-931D-92F1F03495D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{538A12B5-7CE5-4F72-931D-92F1F03495D7}.Release|Any CPU.Build.0 = Release|Any CPU
{538A12B5-7CE5-4F72-931D-92F1F03495D7}.Release|x64.ActiveCfg = Release|Any CPU
{538A12B5-7CE5-4F72-931D-92F1F03495D7}.Release|x64.Build.0 = Release|Any CPU
{538A12B5-7CE5-4F72-931D-92F1F03495D7}.Release|x86.ActiveCfg = Release|Any CPU
{538A12B5-7CE5-4F72-931D-92F1F03495D7}.Release|x86.Build.0 = Release|Any CPU
{7F01390E-AF15-442C-831C-C574D6AAFC1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7F01390E-AF15-442C-831C-C574D6AAFC1F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7F01390E-AF15-442C-831C-C574D6AAFC1F}.Debug|x64.ActiveCfg = Debug|Any CPU
{7F01390E-AF15-442C-831C-C574D6AAFC1F}.Debug|x64.Build.0 = Debug|Any CPU
{7F01390E-AF15-442C-831C-C574D6AAFC1F}.Debug|x86.ActiveCfg = Debug|Any CPU
{7F01390E-AF15-442C-831C-C574D6AAFC1F}.Debug|x86.Build.0 = Debug|Any CPU
{7F01390E-AF15-442C-831C-C574D6AAFC1F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7F01390E-AF15-442C-831C-C574D6AAFC1F}.Release|Any CPU.Build.0 = Release|Any CPU
{7F01390E-AF15-442C-831C-C574D6AAFC1F}.Release|x64.ActiveCfg = Release|Any CPU
{7F01390E-AF15-442C-831C-C574D6AAFC1F}.Release|x64.Build.0 = Release|Any CPU
{7F01390E-AF15-442C-831C-C574D6AAFC1F}.Release|x86.ActiveCfg = Release|Any CPU
{7F01390E-AF15-442C-831C-C574D6AAFC1F}.Release|x86.Build.0 = Release|Any CPU
{5863DD74-00DE-4DE9-9F0A-FCBC32195E78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5863DD74-00DE-4DE9-9F0A-FCBC32195E78}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5863DD74-00DE-4DE9-9F0A-FCBC32195E78}.Debug|x64.ActiveCfg = Debug|Any CPU
{5863DD74-00DE-4DE9-9F0A-FCBC32195E78}.Debug|x64.Build.0 = Debug|Any CPU
{5863DD74-00DE-4DE9-9F0A-FCBC32195E78}.Debug|x86.ActiveCfg = Debug|Any CPU
{5863DD74-00DE-4DE9-9F0A-FCBC32195E78}.Debug|x86.Build.0 = Debug|Any CPU
{5863DD74-00DE-4DE9-9F0A-FCBC32195E78}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5863DD74-00DE-4DE9-9F0A-FCBC32195E78}.Release|Any CPU.Build.0 = Release|Any CPU
{5863DD74-00DE-4DE9-9F0A-FCBC32195E78}.Release|x64.ActiveCfg = Release|Any CPU
{5863DD74-00DE-4DE9-9F0A-FCBC32195E78}.Release|x64.Build.0 = Release|Any CPU
{5863DD74-00DE-4DE9-9F0A-FCBC32195E78}.Release|x86.ActiveCfg = Release|Any CPU
{5863DD74-00DE-4DE9-9F0A-FCBC32195E78}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
51 changes: 49 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,52 @@ A collaborative browser-based drawing program written in .NET.

Please see [REQUIREMENTS](docs/requirements.md) for more information.

## UI
![DrawTogether.NET UI](/docs/images/paintarea-ui.png)
## Running Locally

First things first, you will need to launch the dependencies for DrawTogether.NET - make sure you have `docker` installed locally:

**Windows**

```shell
start-dependencies.cmd
```

**Linux**

```shell
start-dependencies.sh
```

This will launch, among other things, a prebuilt SQL Server 2022 instance that has the correct default connection string and `DrawTogether` database required by DrawTogether.NET.

### Entity Framework Core Migrations

If you need to apply a change to the database model, by default this project uses a Sqlite instance locally. To apply migrations, change your directory to the `DrawTogether` project:

```shell
cd ./src/DrawTogether/
```

And then apply the migrations:

```shell
dotnet ef database update
```

To generate a migration script that you can apply manually (later):

```shell
dotnet ef migrations script
```

## MailGun Configuration

DrawTogether.NET can use [MailGun](https://mailgun.com/) to send outbound emails (via `FluentEmail.Mailgun`) - and the following two secrets need to be configured in order for that sending to work:

```shell
cd ./src/DrawTogether/
dotnet user-secrets set "EmailSettings:MailgunDomain" "<mailgun-domain>"
dotnet user-secrets set "EmailSettings:MailgunApiKey" "<mailgun-api-key>"
```

If these settings are not provided, DrawTogether.NET will simply fall back to not having email available to support ASP.NET Core Identity.
3 changes: 3 additions & 0 deletions infrastructure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# DrawTogether.NET Infrastructure

This folder contains some "`git clone` and run" tooling for helping run all of DrawTogether.NET's infrastructure.
10 changes: 10 additions & 0 deletions infrastructure/build.all.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
REM @echo off
REM executes all `build.cmd` scripts recursively inside from this directory on down

pushd "%~dp0"
for /R %%f in ("build.cmd") do (
IF EXIST "%%f" (
call "%%f" %~1
)
)
popd
8 changes: 8 additions & 0 deletions infrastructure/build.all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
# executes all `build.sh` scripts recursively inside from this directory on down
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
cd "$parent_path"

for file in ./**/build.sh; do
./${file} $1
done
39 changes: 39 additions & 0 deletions infrastructure/mssql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# MSSQL Image

This is a prebuilt [SQL Server 2022 on Linux](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-whats-new-2019) Docker image that contains a blank `DrawTogether` database which will subsequently be used by Akka.Persistence.Sql for relevant samples.

## Build

To build this image, run the `build.sh` or `build.cmd` script found in root of this directory.

```shell
build.sh [-t {tag}]
````

```shell
build.cmd [-t {tag}]
```

This will produce an image named `drawtogether.sqlserver:{tag}`.

If you leave out the `{tag}` parameter the image name will default to `drawtogether.sqlserver:0.1.0`.

### Adding Additional Schema

If you need additional tables or any other DDLs added to this sample, modify the [`setup.sql`](setup.sql) script inside this repository. Those schema modifications will be applied when the container first starts up.

### Deployment

To run this image you will still need to provide the default environment variable arguments required by the [SQL Server 2022 public Docker image](https://hub.docker.com/_/microsoft-mssql-server):

```shell
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=yourStrong(!)Password" -p 1633:1433 -d drawtogether.sqlserver:0.1.0
```

This will produce a connection string that you can use to run Akka.Persistence (from the host machine):

```
Server=localhost; Database=DrawTogether; User Id=sa; Password=yourStrong(!)Password;
```
> **N.B.** It might take `drawtogether.sqlserver.sqlserver` up to 30 seconds to fully initialize the very first time it starts. Please be patient prior to running your sample and check the logs inside the Docker dashboard to see if the `DrawTogether` database has been created.
15 changes: 15 additions & 0 deletions infrastructure/mssql/build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@echo off
REM builds all docker images

set version="0.1.0"
set imageName="drawtogether.sqlserver"

if "%~1"=="" (
REM No version tag specified
echo No tag for [%imageName%] specified. Defaulting to [%version%]
) else (
set version="%~1"
echo Building [%imageName%] with tag [%~1]
)

docker build %~dp0/src/. -t "%imageName%:%version%"
16 changes: 16 additions & 0 deletions infrastructure/mssql/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
# Builds docker images
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
cd "$parent_path"

version="0.1.0"
imageName="drawtogether.sqlserver"

if [ -z $1 ]; then
echo "No tag for [${imageName}] specified. Defaulting to [${version}]"
else
version="$1"
echo "Building [${imageName}] with tag [${version}]"
fi

docker build ./src/. -t "${imageName}:${version}"
14 changes: 14 additions & 0 deletions infrastructure/mssql/deploy.k8s.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
echo off
REM Deploys container instance into Kubernetes namespace

set namespace="drawtogether"

if "%~1"=="" (
REM No K8S namespace specified
echo No namespace specified. Defaulting to [%namespace%]
) else (
set namespace="%~1"
echo Deploying into K8s namespace [%namespace%]
)

kubectl apply -f "%~dp0/drawtogether.sql.yaml" -n "%namespace%"
15 changes: 15 additions & 0 deletions infrastructure/mssql/deploy.k8s.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
# Deploys container instance into Kubernetes namespace
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )


namespace="drawtogether"

if [ -z $1 ]; then
echo "No namespace specified. Defaulting to [${namespace}]"
else
namespace="$1"
echo "Deploying into K8s namespace [${namespace}]"
fi

kubectl apply -f "drawtogether.sql.yaml" -n "%namespace%"
46 changes: 46 additions & 0 deletions infrastructure/mssql/drawtogether.sql.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
apiVersion: v1
kind: Service
metadata:
name: sqlserver
spec:
ports:
- name: sqlserver
port: 1644
protocol: TCP
targetPort: 1433
selector:
app: sqlserver
type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: sqlserver
labels:
app: sqlserver
spec:
replicas: 1
selector:
matchLabels:
app: sqlserver
template:
metadata:
labels:
app: sqlserver
spec:
containers:
- name: sqlserver
image: drawtogether.sqlserver:0.1.0
env:
- name: ACCEPT_EULA
value: "Y"
- name: SA_PASSWORD
value: "yourStrong(!)Password"
ports:
- containerPort: 1433
name: sqlserver
readinessProbe:
exec:
command: ["/bin/sh", "-c", "ready-check.sh"]
initialDelaySeconds: 5
periodSeconds: 5
10 changes: 10 additions & 0 deletions infrastructure/mssql/src/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM mcr.microsoft.com/mssql/server:2022-latest

COPY ./setup.sql .
COPY ./setup.sh .
COPY ./ready-check.sh .

# Grant permission on the setup script
#RUN chmod +x ./setup.sh

CMD /bin/bash -C './setup.sh';'bash'
5 changes: 5 additions & 0 deletions infrastructure/mssql/src/ready-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

echo "checking to see if [DrawTogether] database is available..."

/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P ${SA_PASSWORD} -d master -q "select [dbo].[DatabaseExists]('DrawTogether')"
13 changes: 13 additions & 0 deletions infrastructure/mssql/src/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

# start SQL Server
/opt/mssql/bin/sqlservr &

#wait for the SQL Server to come up
sleep 15s

# setup the tables
echo "Connecting to SQL and creating Akka database."
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P ${SA_PASSWORD} -d master -i setup.sql

sleep infinity
Loading

0 comments on commit 87c8a0e

Please sign in to comment.