Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add local postgresql dev database (#190)

Leendert de Borst4fb5087c82e2
diff --git a/.gitignore b/.gitignore
index 994133dab..46bbb308d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -414,3 +414,4 @@ docs/.bundle
# Database files
database/postgres
+database/postgres-dev
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index e2dfc848b..dc96c710c 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -26,16 +26,16 @@ cp .github/hooks/commit-msg .git/hooks/commit-msg
chmod +x .git/hooks/commit-msg
```
-### 3. Install the latest version of .NET SDK 8
+### 3. Install the latest version of .NET SDK 9
```bash
-# Install .NET SDK 8
+# Install .NET SDK 9
# On MacOS via brew:
brew install --cask dotnet-sdk
# On Windows via winget
-winget install Microsoft.DotNet.SDK.8
+winget install Microsoft.DotNet.SDK.9
```
### 4. Install dotnet CLI EF Tools
@@ -51,13 +51,26 @@ export PATH="$PATH:$HOME/.dotnet/tools"
dotnet ef
```
-### 5. Run Tailwind CSS compiler while changing HTML files to update compiled CSS
+### 5. Install dev database
+AliasVault uses PostgreSQL as its database. In order to run the project locally from Visual Studio / Rider you will need to install the dev database. You can do this
+by running the following command. This will start a separate PostgreSQL instance on port 5433 accessible via the `localhost:5433` address.
```bash
-npm run build:css
+./install.sh configure-dev-db
```
-### 6. Install Playwright in order to locally run NUnit E2E (end-to-end) tests
+This will start the dev database and create a new database for the project.
+
+### 6. Run Tailwind CSS compiler when changing HTML files to update compiled CSS
+
+```bash
+# For Admin project (in the admin project directory)
+npm run build:admin-css
+# For Client project (in the client project directory)
+npm run build:client-css
+```
+
+### 7. Install Playwright in order to locally run NUnit E2E (end-to-end) tests
```bash
# First install PowerShell for Mac (if you don't have it already)
@@ -66,10 +79,10 @@ brew install powershell/tap/powershell
dotnet tool install --global Microsoft.Playwright.CLI
# Run Playwright install script to download local browsers
# Note: make sure the E2E test project has been built at least once so the bin dir exists.
-pwsh src/Tests/AliasVault.E2ETests/bin/Debug/net8.0/playwright.ps1 install
+pwsh src/Tests/AliasVault.E2ETests/bin/Debug/net9.0/playwright.ps1 install
```
-### 7. Create AliasVault.Client appsettings.Development.json
+### 8. Create AliasVault.Client appsettings.Development.json
The WASM client app supports a development specific appsettings.json file. This appsettings file is optional but can override various options to make debugging easier.
diff --git a/docker-compose.build.yml b/docker-compose.build.yml
index 6478998c3..cd1382bf4 100644
--- a/docker-compose.build.yml
+++ b/docker-compose.build.yml
@@ -40,5 +40,3 @@ services:
build:
context: .
dockerfile: Dockerfile.postgres
- ports:
- - "5432:5432"
diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml
new file mode 100644
index 000000000..29dc75868
--- /dev/null
+++ b/docker-compose.dev.yml
@@ -0,0 +1,20 @@
+services:
+ postgres-dev:
+ image: postgres:16-alpine
+ ports:
+ - "5433:5432"
+ volumes:
+ - ./database/postgres-dev:/var/lib/postgresql/data:rw
+ - ./postgresql.conf:/etc/postgresql/postgresql.conf
+ environment:
+ - POSTGRES_DB=aliasvault
+ - POSTGRES_USER=aliasvault
+ - POSTGRES_PASSWORD=password
+ restart: "no"
+ healthcheck:
+ test: ["CMD-SHELL", "pg_isready -U aliasvault"]
+ interval: 5s
+ timeout: 5s
+ retries: 5
+ start_period: 10s
+ command: ["postgres", "-c", "config_file=/etc/postgresql/postgresql.conf"]
\ No newline at end of file
diff --git a/docs/misc/dev/contributing.md b/docs/misc/dev/contributing.md
new file mode 100644
index 000000000..19a841571
--- /dev/null
+++ b/docs/misc/dev/contributing.md
@@ -0,0 +1,114 @@
+---
+layout: default
+title: Contributing
+parent: Development
+grand_parent: Miscellaneous
+nav_order: 1
+---
+
+# Contributing
+This document is a work-in-progress and will be expanded as time goes on. If you have any questions feel free to open a issue on GitHub.
+
+Note: all instructions below are based on MacOS. If you are using a different operating system, you may need to adjust the commands accordingly.
+
+## Getting Started
+In order to contribute to this project follow these instructions to setup your local environment:
+
+### 1. Clone the repository
+```bash
+git clone https://github.com/lanedirt/AliasVault.git
+cd AliasVault
+```
+
+### 2. Copy pre-commit hook script to .git/hooks directory
+{: .note }
+All commits in this repo are required to contain a reference to a GitHub issue in the format of "your commit message (#123)" where "123" references the GitHub issue number.
+
+The pre-commit hook script below will check the commit message before allowing the commit to proceed. If the commit message is invalid, the commit will be aborted.
+
+```bash
+# Copy the commit-msg hook script to the .git/hooks directory
+cp .github/hooks/commit-msg .git/hooks/commit-msg
+
+# Make the script executable
+chmod +x .git/hooks/commit-msg
+```
+
+### 3. Install the latest version of .NET SDK 9
+```bash
+# Install .NET SDK 9
+
+# On MacOS via brew:
+brew install --cask dotnet-sdk
+
+# On Windows via winget
+winget install Microsoft.DotNet.SDK.9
+```
+
+### 4. Install dotnet CLI EF Tools
+```bash
+# Install dotnet EF tools globally
+dotnet tool install --global dotnet-ef
+# Include dotnet tools in your PATH
+nano ~/.zshrc
+# Add the following line to your .zshrc file
+export PATH="$PATH:$HOME/.dotnet/tools"
+# Start a new terminal and test that this command works:
+dotnet ef
+```
+
+### 5. Install dev database
+AliasVault uses PostgreSQL as its database. In order to run the project locally from Visual Studio / Rider you will need to install the dev database. You can do this by running the following command. This will start a separate PostgreSQL instance on port 5433 accessible via the `localhost:5433` address.
+
+```bash
+./install.sh configure-dev-db
+```
+
+After the database is running you can start the project from Visual Studio / Rider in run or debug mode and it should be able to connect to the dev database.
+
+### 6. Run Tailwind CSS compiler when changing HTML files to update compiled CSS
+```bash
+# For Admin project (in the admin project directory)
+npm run build:admin-css
+# For Client project (in the client project directory)
+npm run build:client-css
+```
+
+### 7. Install Playwright in order to locally run NUnit E2E (end-to-end) tests
+```bash
+# First install PowerShell for Mac (if you don't have it already)
+brew install powershell/tap/powershell
+# Install Playwright
+dotnet tool install --global Microsoft.Playwright.CLI
+# Run Playwright install script to download local browsers
+# Note: make sure the E2E test project has been built at least once so the bin dir exists.
+pwsh src/Tests/AliasVault.E2ETests/bin/Debug/net9.0/playwright.ps1 install
+```
+
+### 8. Create AliasVault.Client appsettings.Development.json
+The WASM client app supports a development specific appsettings.json file. This appsettings file is optional but can override various options to make debugging easier.
+
+1. Copy `wwwroot/appsettings.json` to `wwwroot/appsettings.Development.json`
+
+Here is an example file with the various options explained:
+
+```json
+{
+ "ApiUrl": "http://localhost:5092",
+ "PrivateEmailDomains": ["example.tld"],
+ "SupportEmail": "[email protected]",
+ "UseDebugEncryptionKey": "true",
+ "CryptographyOverrideType" : "Argon2Id",
+ "CryptographyOverrideSettings" : "{\"DegreeOfParallelism\":1,\"MemorySize\":1024,\"Iterations\":1}"
+}
+```
+
+- **UseDebugEncryptionKey**
+ - This setting will use a static encryption key so that if you login as a user you can refresh the page without needing to unlock the database again. This speeds up development when changing things in the WebApp WASM project. Note: the project needs to be run in "Development" mode for this setting to be used.
+
+- **CryptographyOverrideType**
+ - This setting allows overriding the default encryption type (Argon2id) with a different encryption type. This is useful for testing different encryption types without having to change code.
+
+- **CryptographyOverrideSettings**
+ - This setting allows overriding the default encryption settings (Argon2id) with different settings. This is useful for testing different encryption settings without having to change code. The default Argon2id settings are defined in the project as `Utilities/Cryptography/Cryptography.Client/Defaults.cs`. These default settings are focused on security but NOT performance. Normally for key derivation purposes the slower/heavier the algorithm the better protection against attackers. For production builds this is what we want, however in case of automated testing or debugging extra performance can be gained by tweaking (lowering) these settings.
+```
\ No newline at end of file
diff --git a/docs/misc/dev/enable-webauthn-pfr-chrome.md b/docs/misc/dev/enable-webauthn-pfr-chrome.md
index 0be778f84..a25d86938 100644
--- a/docs/misc/dev/enable-webauthn-pfr-chrome.md
+++ b/docs/misc/dev/enable-webauthn-pfr-chrome.md
@@ -3,7 +3,7 @@ layout: default
title: Enable WebAuthn
parent: Development
grand_parent: Miscellaneous
-nav_order: 1
+nav_order: 9
---
# WebAuthn
diff --git a/docs/misc/dev/postgresql-commands.md b/docs/misc/dev/postgresql-commands.md
index 375948f83..3796a2717 100644
--- a/docs/misc/dev/postgresql-commands.md
+++ b/docs/misc/dev/postgresql-commands.md
@@ -3,7 +3,7 @@ layout: default
title: PostgreSQL Commands
parent: Development
grand_parent: Miscellaneous
-nav_order: 1
+nav_order: 2
---
# PostgreSQL Commands
diff --git a/docs/misc/dev/run-github-actions-locally.md b/docs/misc/dev/run-github-actions-locally.md
index 3994192a5..c519486bb 100644
--- a/docs/misc/dev/run-github-actions-locally.md
+++ b/docs/misc/dev/run-github-actions-locally.md
@@ -3,7 +3,7 @@ layout: default
title: 1. Run GitHub Actions Locally
parent: Development
grand_parent: Miscellaneous
-nav_order: 1
+nav_order: 9
---
# Run GitHub Actions Locally
diff --git a/install.sh b/install.sh
index 8614a1bdd..d2cfe0951 100755
--- a/install.sh
+++ b/install.sh
@@ -50,6 +50,7 @@ show_usage() {
printf " restart Restart AliasVault containers\n"
printf " reset-password Reset admin password\n"
printf " build Build AliasVault from source (takes longer and requires sufficient specs)\n"
+ printf " configure-dev-db Configure development database (for local development only)\n"
printf "\n"
printf "Options:\n"
@@ -126,6 +127,10 @@ parse_args() {
COMMAND="update-installer"
shift
;;
+ configure-dev-db|dev-db)
+ COMMAND="configure-dev-db"
+ shift
+ ;;
--help)
show_usage
exit 0
@@ -210,6 +215,9 @@ main() {
check_install_script_update
exit $?
;;
+ "configure-dev-db")
+ configure_dev_database
+ ;;
esac
}
@@ -1438,4 +1446,95 @@ handle_install_version() {
print_success_message
}
+# Function to handle development database configuration
+configure_dev_database() {
+ printf "${YELLOW}+++ Development Database Configuration +++${NC}\n"
+ printf "\n"
+
+ if [ ! -f "docker-compose.dev.yml" ]; then
+ printf "${CYAN}> Downloading docker-compose.dev.yml...${NC}\n"
+ curl -sSf "${GITHUB_RAW_URL_REPO_BRANCH}/docker-compose.dev.yml" -o "docker-compose.dev.yml"
+ fi
+
+ # Check current status
+ if docker compose -f docker-compose.dev.yml -p aliasvault-dev ps --status running 2>/dev/null | grep -q postgres-dev; then
+ DEV_DB_STATUS="running"
+ else
+ DEV_DB_STATUS="stopped"
+ fi
+
+ printf "${CYAN}About Development Database:${NC}\n"
+ printf "A separate PostgreSQL instance for development purposes that:\n"
+ printf " - Runs on port 5433 (to avoid conflicts)\n"
+ printf " - Uses simple credentials (password: 'password')\n"
+ printf " - Stores data separately from production\n"
+ printf "\n"
+ printf "${CYAN}Current Status:${NC}\n"
+ if [ "$DEV_DB_STATUS" = "running" ]; then
+ printf "Development Database: ${GREEN}Running${NC}\n"
+ else
+ printf "Development Database: ${YELLOW}Stopped${NC}\n"
+ fi
+ printf "\n"
+ printf "Options:\n"
+ printf "1) Start development database\n"
+ printf "2) Stop development database\n"
+ printf "3) View connection details\n"
+ printf "4) Cancel\n"
+ printf "\n"
+
+ read -p "Select an option [1-4]: " dev_db_option
+
+ case $dev_db_option in
+ 1)
+ if [ "$DEV_DB_STATUS" = "running" ]; then
+ printf "${YELLOW}> Development database is already running.${NC}\n"
+ else
+ printf "${CYAN}> Starting development database...${NC}\n"
+ docker compose -p aliasvault-dev -f docker-compose.dev.yml up -d
+ printf "${GREEN}> Development database started successfully.${NC}\n"
+ fi
+ print_dev_db_details
+ ;;
+ 2)
+ if [ "$DEV_DB_STATUS" = "stopped" ]; then
+ printf "${YELLOW}> Development database is already stopped.${NC}\n"
+ else
+ printf "${CYAN}> Stopping development database...${NC}\n"
+ docker compose -p aliasvault-dev -f docker-compose.dev.yml down
+ printf "${GREEN}> Development database stopped successfully.${NC}\n"
+ fi
+ ;;
+ 3)
+ print_dev_db_details
+ ;;
+ 4)
+ printf "${YELLOW}Configuration cancelled.${NC}\n"
+ exit 0
+ ;;
+ *)
+ printf "${RED}Invalid option selected.${NC}\n"
+ exit 1
+ ;;
+ esac
+}
+
+# Function to print development database connection details
+print_dev_db_details() {
+ printf "\n"
+ printf "${MAGENTA}=========================================================${NC}\n"
+ printf "\n"
+ printf "${CYAN}Development Database Connection Details:${NC}\n"
+ printf "Host: localhost\n"
+ printf "Port: 5433\n"
+ printf "Database: aliasvault\n"
+ printf "Username: aliasvault\n"
+ printf "Password: password\n"
+ printf "\n"
+ printf "Connection string:\n"
+ printf "Host=localhost;Port=5433;Database=aliasvault;Username=aliasvault;Password=password\n"
+ printf "\n"
+ printf "${MAGENTA}=========================================================${NC}\n"
+}
+
main "$@"
diff --git a/src/AliasVault.Admin/appsettings.json b/src/AliasVault.Admin/appsettings.json
index 189a56ce1..e91f3221a 100644
--- a/src/AliasVault.Admin/appsettings.json
+++ b/src/AliasVault.Admin/appsettings.json
@@ -1,7 +1,7 @@
{
"DatabaseProvider": "postgresql",
"ConnectionStrings": {
- "AliasServerDbContext": "Host=localhost;Port=5432;Database=aliasvault;Username=aliasvault;Password=password"
+ "AliasServerDbContext": "Host=localhost;Port=5433;Database=aliasvault;Username=aliasvault;Password=password"
},
"Logging": {
"LogLevel": {
diff --git a/src/AliasVault.Api/appsettings.json b/src/AliasVault.Api/appsettings.json
index 0a484e5fb..0b0e6bf1e 100644
--- a/src/AliasVault.Api/appsettings.json
+++ b/src/AliasVault.Api/appsettings.json
@@ -13,7 +13,7 @@
},
"DatabaseProvider": "postgresql",
"ConnectionStrings": {
- "AliasServerDbContext": "Host=localhost;Port=5432;Database=aliasvault;Username=aliasvault;Password=password"
+ "AliasServerDbContext": "Host=localhost;Port=5433;Database=aliasvault;Username=aliasvault;Password=password"
},
"AllowedHosts": "*"
}
diff --git a/src/Services/AliasVault.SmtpService/appsettings.json b/src/Services/AliasVault.SmtpService/appsettings.json
index e8623fc1c..7feaf2020 100644
--- a/src/Services/AliasVault.SmtpService/appsettings.json
+++ b/src/Services/AliasVault.SmtpService/appsettings.json
@@ -8,6 +8,6 @@
},
"DatabaseProvider": "postgresql",
"ConnectionStrings": {
- "AliasServerDbContext": "Host=localhost;Port=5432;Database=aliasvault;Username=aliasvault;Password=password"
+ "AliasServerDbContext": "Host=localhost;Port=5433;Database=aliasvault;Username=aliasvault;Password=password"
}
}
diff --git a/src/Services/AliasVault.TaskRunner/appsettings.json b/src/Services/AliasVault.TaskRunner/appsettings.json
index e8623fc1c..7feaf2020 100644
--- a/src/Services/AliasVault.TaskRunner/appsettings.json
+++ b/src/Services/AliasVault.TaskRunner/appsettings.json
@@ -8,6 +8,6 @@
},
"DatabaseProvider": "postgresql",
"ConnectionStrings": {
- "AliasServerDbContext": "Host=localhost;Port=5432;Database=aliasvault;Username=aliasvault;Password=password"
+ "AliasServerDbContext": "Host=localhost;Port=5433;Database=aliasvault;Username=aliasvault;Password=password"
}
}
diff --git a/src/Tests/AliasVault.E2ETests/Infrastructure/WebApplicationAdminFactoryFixture.cs b/src/Tests/AliasVault.E2ETests/Infrastructure/WebApplicationAdminFactoryFixture.cs
index 3ea30a8a8..370ecb258 100644
--- a/src/Tests/AliasVault.E2ETests/Infrastructure/WebApplicationAdminFactoryFixture.cs
+++ b/src/Tests/AliasVault.E2ETests/Infrastructure/WebApplicationAdminFactoryFixture.cs
@@ -73,7 +73,7 @@ public class WebApplicationAdminFactoryFixture<TEntryPoint> : WebApplicationFact
if (!string.IsNullOrEmpty(_tempDbName))
{
// Create a connection to 'postgres' database to drop the test database
- using var conn = new NpgsqlConnection("Host=localhost;Port=5432;Database=postgres;Username=aliasvault;Password=password");
+ using var conn = new NpgsqlConnection("Host=localhost;Port=5433;Database=postgres;Username=aliasvault;Password=password");
await conn.OpenAsync();
// First terminate existing connections
diff --git a/src/Tests/AliasVault.E2ETests/Infrastructure/WebApplicationApiFactoryFixture.cs b/src/Tests/AliasVault.E2ETests/Infrastructure/WebApplicationApiFactoryFixture.cs
index c39fc87cd..b48a66975 100644
--- a/src/Tests/AliasVault.E2ETests/Infrastructure/WebApplicationApiFactoryFixture.cs
+++ b/src/Tests/AliasVault.E2ETests/Infrastructure/WebApplicationApiFactoryFixture.cs
@@ -78,7 +78,7 @@ public class WebApplicationApiFactoryFixture<TEntryPoint> : WebApplicationFactor
if (!string.IsNullOrEmpty(_tempDbName))
{
// Create a connection to 'postgres' database to drop the test database
- using var conn = new NpgsqlConnection("Host=localhost;Port=5432;Database=postgres;Username=aliasvault;Password=password");
+ using var conn = new NpgsqlConnection("Host=localhost;Port=5433;Database=postgres;Username=aliasvault;Password=password");
await conn.OpenAsync();
// First terminate existing connections
diff --git a/src/Tests/AliasVault.IntegrationTests/SmtpServer/TestHostBuilder.cs b/src/Tests/AliasVault.IntegrationTests/SmtpServer/TestHostBuilder.cs
index 0525c0f5d..1a282f58b 100644
--- a/src/Tests/AliasVault.IntegrationTests/SmtpServer/TestHostBuilder.cs
+++ b/src/Tests/AliasVault.IntegrationTests/SmtpServer/TestHostBuilder.cs
@@ -65,7 +65,7 @@ public class TestHostBuilder : IAsyncDisposable
_tempDbName = $"aliasdb_test_{Guid.NewGuid()}";
// Create a connection to 'postgres' database to ensure the test database exists
- using (var conn = new NpgsqlConnection("Host=localhost;Port=5432;Database=postgres;Username=aliasvault;Password=password"))
+ using (var conn = new NpgsqlConnection("Host=localhost;Port=5433;Database=postgres;Username=aliasvault;Password=password"))
{
conn.Open();
using (var cmd = conn.CreateCommand())
@@ -78,7 +78,7 @@ public class TestHostBuilder : IAsyncDisposable
}
// Create a connection to the new test database
- var dbConnection = new NpgsqlConnection($"Host=localhost;Port=5432;Database={_tempDbName};Username=aliasvault;Password=password");
+ var dbConnection = new NpgsqlConnection($"Host=localhost;Port=5433;Database={_tempDbName};Username=aliasvault;Password=password");
return Build(dbConnection);
}
@@ -162,7 +162,7 @@ public class TestHostBuilder : IAsyncDisposable
if (!string.IsNullOrEmpty(_tempDbName))
{
// Create a connection to 'postgres' database to drop the test database
- using var conn = new NpgsqlConnection("Host=localhost;Port=5432;Database=postgres;Username=aliasvault;Password=password");
+ using var conn = new NpgsqlConnection("Host=localhost;Port=5433;Database=postgres;Username=aliasvault;Password=password");
await conn.OpenAsync();
// First terminate existing connections
diff --git a/src/Tests/AliasVault.IntegrationTests/TaskRunner/TestHostBuilder.cs b/src/Tests/AliasVault.IntegrationTests/TaskRunner/TestHostBuilder.cs
index 835c48d75..a54325b6a 100644
--- a/src/Tests/AliasVault.IntegrationTests/TaskRunner/TestHostBuilder.cs
+++ b/src/Tests/AliasVault.IntegrationTests/TaskRunner/TestHostBuilder.cs
@@ -57,7 +57,7 @@ public class TestHostBuilder : IAsyncDisposable
_tempDbName = $"aliasdb_test_{Guid.NewGuid()}";
// Create a connection to 'postgres' database to create the test database
- using (var conn = new NpgsqlConnection("Host=localhost;Port=5432;Database=postgres;Username=aliasvault;Password=password"))
+ using (var conn = new NpgsqlConnection("Host=localhost;Port=5433;Database=postgres;Username=aliasvault;Password=password"))
{
conn.Open();
using (var cmd = conn.CreateCommand())
@@ -70,7 +70,7 @@ public class TestHostBuilder : IAsyncDisposable
}
// Create the connection to the new test database
- var dbConnection = new NpgsqlConnection($"Host=localhost;Port=5432;Database={_tempDbName};Username=aliasvault;Password=password");
+ var dbConnection = new NpgsqlConnection($"Host=localhost;Port=5433;Database={_tempDbName};Username=aliasvault;Password=password");
var builder = Host.CreateDefaultBuilder()
.ConfigureServices((context, services) =>
{
@@ -126,7 +126,7 @@ public class TestHostBuilder : IAsyncDisposable
if (!string.IsNullOrEmpty(_tempDbName))
{
// Create a connection to 'postgres' database to drop the test database
- using var conn = new NpgsqlConnection("Host=localhost;Port=5432;Database=postgres;Username=aliasvault;Password=password");
+ using var conn = new NpgsqlConnection("Host=localhost;Port=5433;Database=postgres;Username=aliasvault;Password=password");
await conn.OpenAsync();
// First terminate existing connections