mirror of
https://github.com/bitwarden/server.git
synced 2024-11-21 12:05:42 +01:00
Simplify development environment setup (#1588)
This commit is contained in:
parent
7802c2b969
commit
964e262d44
251
SETUP.md
251
SETUP.md
@ -19,188 +19,120 @@ By default some of the services depends on the Bitwarden licensed `CommCore`, ho
|
||||
|
||||
This guide will show you how to set up the Api, Identity and SQL projects for development. These are the minimum projects for any development work. You may need to set up additional projects depending on the changes you want to make.
|
||||
|
||||
We recommend using [Visual Studio](https://visualstudio.microsoft.com/vs/).
|
||||
We recommend using [Visual Studio](https://visualstudio.microsoft.com/vs/), and [PowerShell](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell?view=powershell-7.1) which is used for the helper scripts.
|
||||
|
||||
## Database setup
|
||||
## Docker containers
|
||||
|
||||
### Docker setup
|
||||
To simplify the setup process we provide a [Docker Compose](https://docs.docker.com/compose/) application model. This is split up into multiple service profiles to facilitate easily customization.
|
||||
|
||||
We use SQL Server Developer Edition as a Docker Container to run the local development database. More information about the container image is available [on its Docker Hub page](https://hub.docker.com/_/microsoft-mssql-server) (this is especially useful if you're having issues).
|
||||
Some settings can be customized by modifying the `dev/.env` file, such as the `MSSQL_PASSWORD` which should be modified before starting the project.
|
||||
|
||||
Steps:
|
||||
```bash
|
||||
# Copy the example environment file
|
||||
cp ./.env.example ./.env
|
||||
|
||||
1. Make sure you have already run `git clone` for the server repo, so that you have the migrator scripts required
|
||||
2. Install the [Docker desktop runtime](https://hub.docker.com/editions/community/docker-ce-desktop-mac)
|
||||
3. Create a Docker account if prompted (optional)
|
||||
4. Organize your folders (important for the below scripts to work properly):
|
||||
* Create a folder to house Docker information (e.g. `docker`) - this should be in the same folder as your cloned repositories (e.g. `server`, `web`, `browser` etc)
|
||||
* Create sub-folder to house this specific container (ex: `docker/SQLServer`)
|
||||
5. Create `docker-compose.yml` file in `docker/SQLServer` with the following contents:
|
||||
# We recommend running the following command when developing for self-hosted
|
||||
docker compose --profile mssql --profile mail up
|
||||
|
||||
```Dockerfile
|
||||
version: '3.1'
|
||||
# We also provide a storage profile which uses Azurite to emulate some services used by the cloud instance
|
||||
# Usually only needed by internal Bitwarden developers
|
||||
docker compose --profile cloud --profile mail up
|
||||
```
|
||||
|
||||
services:
|
||||
### SQL Server
|
||||
|
||||
db:
|
||||
image: mcr.microsoft.com/mssql/server:2017-CU14-ubuntu
|
||||
container_name: mssql-dev
|
||||
restart: always
|
||||
environment:
|
||||
ACCEPT_EULA: Y
|
||||
SA_PASSWORD: SET_A_PASSWORD_HERE
|
||||
MSSQL_PID: Developer
|
||||
volumes:
|
||||
- mssql_dev_data:/var/opt/mssql/data
|
||||
- ../../server/util/Migrator:/mnt/migrator/
|
||||
ports:
|
||||
- '1433:1433'
|
||||
We recommend changing the `MSSQL_PASSWORD` variable in `dev/.env` to avoid exposing the sqlserver with a default password. Note: changing this after first running docker compose may require a re-creation of the storage volume. To do this, stop the running containers and run `docker volume rm bitwardenserver_mssql_dev_data`. (**Warning:** this will delete your development database.)
|
||||
|
||||
volumes:
|
||||
mssql_dev_data:
|
||||
```
|
||||
6. Update the SA_PASSWORD field with a password you want to use. It must include at least 8 characters of at least three of these four categories: uppercase letters, lowercase letters, numbers and non-alphanumeric symbols.
|
||||
7. Open up a terminal window and cd into your folder with the .yml file and execute the following command
|
||||
* `docker-compose up -d` (omit the `-d` switch if you want to see the output for debugging)
|
||||
* You should now have a container up and running the SQL Server
|
||||
We provide a helper script which will create the development database `vault_dev` and also run all migrations. This commad should be run after starting docker the first time, as well as after syncing against upstream and after creating a new migration.
|
||||
|
||||
<img width="194" alt="salserver" src="https://user-images.githubusercontent.com/3904944/78942922-b344e880-7a88-11ea-8c1e-ba12ab3446bb.png">
|
||||
```powershell
|
||||
.\dev\migrate.ps1
|
||||
|
||||
### Running Migrator scripts
|
||||
# You can also re-run the last migration using
|
||||
.\dev\migrate.ps1 -r
|
||||
```
|
||||
|
||||
You now have an empty SQL server instance. The instructions below will automatically create your `vault_dev` database and run the migration scripts located in `server/util/Migrator/DbScripts` to populate it.
|
||||
### Azurite
|
||||
|
||||
Note: you must have followed the steps above to set up your folder structures and the `docker-compose` file for this to work.
|
||||
[Azurite](https://github.com/Azure/Azurite) is a emulator for Azure Storage API and supports Blob, Queues and Table storage. We use it to avoid a hard dependency on online services for cloud development.
|
||||
|
||||
1. Open the Docker Desktop GUI
|
||||
2. Click the CLI button to open a new terminal in your mssql-dev service
|
||||
![Screen Shot 2021-03-18 at 11 12 30 am](https://user-images.githubusercontent.com/31796059/111558643-e59faf80-87da-11eb-96d7-c26875ce322c.png)
|
||||
3. Run `sh /mnt/migrator/createVaultDev.sh 'SA_PASSWORD'`. Replace `SA_PASSWORD` with the password you set in your `docker-compose.yml` file. You should put your `SA_PASSWORD` in single quotes to avoid special bash characters being caught by the shell.
|
||||
To bootstrap the local Azurite instance please run the following command:
|
||||
```powershell
|
||||
# This script requires the Az module, which can be installed using
|
||||
Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force
|
||||
|
||||
4. (Optional) To confirm this worked correctly, you can connect to the SQL database with an SQL client (such as [Azure Data Studio](https://docs.microsoft.com/en-us/sql/azure-data-studio/download-azure-data-studio?view=sql-server-ver15)). You should see that the `vault_dev` database has been created and has been populated with tables.
|
||||
.\dev\setup_azurite.ps1
|
||||
```
|
||||
|
||||
5. **Troubleshooting:** if your login details for `sa` are being rejected:
|
||||
* Make sure your SA_PASSWORD is meeting the complexity requirements above. If these requirements are not met, the password may not be set properly (without any warning) and your login attempts will be rejected for having an incorrect password. If this is happening and you're sure you're using the right password, try increasing the complexity of SA_PASSWORD.
|
||||
* If you change SA_PASSWORD in `docker-compose.yml`, you may need to delete the Docker container *and volume* for it to take effect. (This will obviously delete all of your container files/setup.) Stop and delete the running container, then delete the volume with `docker volume ls` and `docker volume rm <volume name>`. Then update `docker-compose.yml` and run `docker compose up -d` again.
|
||||
* Make sure you are wrapping your SA_PASSWORD in single quotes when executing the `createVaultDev.sh` script.
|
||||
### Mailcatcher
|
||||
|
||||
Your database is now ready to go!
|
||||
Since the server uses emails for many user interactions a working SMTP server is a requirement, we provide a pre-setup instance of [MailCatcher](https://mailcatcher.me/) which exposes a web interface at http://localhost:1080.
|
||||
|
||||
## Setting up User Secrets
|
||||
## Certificates
|
||||
In order to run Bitwarden, we require two certificats which for local development can be resolved by using self signed certificates.
|
||||
|
||||
### Windows
|
||||
|
||||
We provide a helper script which will generate and add the certificates to the users Certificate Store. After running the script it will output the thumbrints needed for the next step. The certificates can later be acccessed using `certml.msc` under `Personal/Certificates`.
|
||||
|
||||
```powershell
|
||||
.\create_certificates_windows.ps1
|
||||
|
||||
PSParentPath: Microsoft.PowerShell.Security\Certificate::CurrentUser\My
|
||||
Thumbprint Subject
|
||||
---------- -------
|
||||
0BE8A0072214AB37C6928968752F698EEC3A68B5 CN=Bitwarden Identity Server Dev
|
||||
C3A6CECAD3DB580F91A52FC9C767FE780300D8AB CN=Bitwarden Data Protection Dev
|
||||
```
|
||||
|
||||
### MacOS
|
||||
|
||||
We provide a helper script which will generate the certificates and add them to the keychain.
|
||||
|
||||
**Note:** You should update the Trust options for each certificate to `always trust` using *Keychain Access*.
|
||||
|
||||
```bash
|
||||
./create_certificates_mac.sh
|
||||
|
||||
Certificate fingerprints:
|
||||
Identity Server Dev: 0BE8A0072214AB37C6928968752F698EEC3A68B5
|
||||
Data Protection Dev: C3A6CECAD3DB580F91A52FC9C767FE780300D8AB
|
||||
```
|
||||
|
||||
## User Secrets
|
||||
User secrets are a method for managing application settings on a per-developer basis. They are stored outside of the local git repository so that they are not pushed to remote.
|
||||
|
||||
User secrets override the settings in `appsettings.json` of each project. Your user secrets file should match the structure of the `appsettings.json` file for the settings you intend to override.
|
||||
|
||||
For more information, see: [Safe storage of app secrets in development in ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-5.0).
|
||||
|
||||
Open the server solution file (`bitwarden-server.sln`) in Visual Studio before proceeding.
|
||||
### Automated Helper script
|
||||
|
||||
### Editing user secrets - Visual Studio on Windows
|
||||
Right-click on the project in the Solution Explorer and click **Manage User Secrets**.
|
||||
We provide a helper scripts which simplifies setting user secrets for all projects in the repository.
|
||||
|
||||
### Editing user secrets - Visual Studio on macOS
|
||||
Open a terminal and navigate to the project directory. Once there, initiate and create the blank user secrets file by running:
|
||||
Start by copying the `secret.json.example` file to `secret.json` and modify the existing settings and add any other required setting. Afterwards run the following command which will add the settings to each each project in the bitwarden repository.
|
||||
|
||||
```bash
|
||||
dotnet user-secrets init
|
||||
```powershell
|
||||
.\setup_secrets.ps1
|
||||
|
||||
# The script also supports an optional flag which removes all existing settings before re-applying them
|
||||
.\setup_secrets.ps1 -clear 1
|
||||
```
|
||||
|
||||
Add a user secret by running:
|
||||
### Manually creating and modifying
|
||||
|
||||
```bash
|
||||
dotnet user-secrets set "<key>" "<value>"
|
||||
```
|
||||
It is also possible to manually creata and modify the user secrets using either the `dotnet` CLI or `Visual Studio` on Windows. For more details see [Appendix A](#user-secrets).
|
||||
|
||||
View currently set secrets by running:
|
||||
|
||||
```bash
|
||||
dotnet user-secrets list
|
||||
```
|
||||
|
||||
By default, user secret files are located in `~/.microsoft/usersecrets/<project name>/secrets.json`. After the file has been created, you can edit this directly with VSCode, which is much easier than using the command line tool.
|
||||
|
||||
### Editing user secrets - Rider
|
||||
* Navigate to **Preferences -> Plugins** and Install .NET Core User Secrets
|
||||
* Right click on the a project and click **Tools** > **Open project user secrets**
|
||||
|
||||
## User Secrets - Certificates
|
||||
Once you have your user secrets files set up, you'll need to generate 3 of your own certificates for use in local development.
|
||||
|
||||
This guide uses OpenSSL to generate the certificates. If you are using Windows, pre-compiled OpenSSL binaries are available via [Cygwin](https://www.cygwin.com/).
|
||||
|
||||
1. Open a terminal.
|
||||
2. Create an Identity Server (Dev) certificate file (.crt) and key file (.key):
|
||||
```bash
|
||||
openssl req -x509 -newkey rsa:4096 -sha256 -nodes -keyout identity_server_dev.key -out identity_server_dev.crt -subj "/CN=Bitwarden Identity Server Dev" -days 3650
|
||||
```
|
||||
3. Create an Identity Server (Dev) .pfx file based on the certificate and key you just created. You will be prompted to enter a password - remember this because you’ll need it later:
|
||||
```bash
|
||||
openssl pkcs12 -export -out identity_server_dev.pfx -inkey identity_server_dev.key -in identity_server_dev.crt -certfile identity_server_dev.crt
|
||||
```
|
||||
5. Create a Data Protection (Dev) certificate file (.crt) and key file (.key):
|
||||
```bash
|
||||
openssl req -x509 -newkey rsa:4096 -sha256 -nodes -keyout data_protection_dev.key -out data_protection_dev.crt -subj "/CN=Bitwarden Data Protection Dev" -days 3650
|
||||
```
|
||||
6. Create a Data Protection (Dev) .pfx file based on the certificate and key you just created. You will be prompted to enter a password - remember this because you’ll need it later:
|
||||
```bash
|
||||
openssl pkcs12 -export -out data_protection_dev.pfx -inkey data_protection_dev.key -in data_protection_dev.crt -certfile data_protection_dev.crt
|
||||
```
|
||||
8. Install the .pfx files by double-clicking on them and entering the password when prompted.
|
||||
* On Windows, this will add them to your certificate stores. You should add them to the "Trusted Root Certificate Authorities" store.
|
||||
* On MacOS, this will add them to your keychain. You should update the Trust options for each certificate to `always trust`.
|
||||
9. Get the SHA1 thumbprint for the Identity and Data Protection certificates
|
||||
* On Windows
|
||||
* press Windows key + R to open the Run prompt
|
||||
* type "certmgr.msc" and press enter. This will open the system tool used to manage user certificates
|
||||
* find the "Bitwarden Data Protection Dev" and "Bitwarden Identity Server Dev" certificates in the Trusted Root Certificate Authorities > Certificates folder
|
||||
* double click on the certificate
|
||||
* click the "Details" tab and find the "Thumbprint" field in the list of properties.
|
||||
* On MacOS
|
||||
* press Command + Spacebar to open the Spotlight search
|
||||
* type "keychain access" and press enter
|
||||
* find the "Bitwarden Data Protection Dev" and "Bitwarden Identity Server Dev" certificates
|
||||
* select each certificate and click the "i" (information) button
|
||||
* find the SHA-1 fingerprint in the list of properties
|
||||
10. Add the SHA1 thumbprints of both certificates to your user secrets for the Api and Identity projects. (See the example user secrets file below.)
|
||||
|
||||
## User Secrets - Other
|
||||
### Required User Secrets
|
||||
|
||||
**selfhosted**: It is highly recommended that you use the `selfHosted: true` setting when running a local development environment. This tells the system not to use cloud services, assuming that you are running your own local SQL instance.
|
||||
|
||||
Alternatively, there are emulators that allow you to run local dev instances of various Azure and/or AWS services (e.g. local-stack), or you can use your own Azure accounts for provisioning the necessary services and set the connection strings accordingly. These are outside the scope of this guide.
|
||||
**sqlServer__connectionString**: this provides the information required for the Server to connect to the SQL instance. See the example connection string in `secrets.json.example`. You may need to change the default password in the connection string.
|
||||
|
||||
**sqlServer__connectionString**: this provides the information required for the Server to connect to the SQL instance. See the example connection string below.
|
||||
|
||||
**licenseDirectory**: this must be set to avoid errors, but it can be set to an aribtrary empty folder.
|
||||
**licenseDirectory**: this must be set to avoid errors, but it can be set to an arbitrary empty folder.
|
||||
|
||||
**installation__key** and **installation__id**: request your own private Installation Id and Installation Key for self-hosting: https://bitwarden.com/host/.
|
||||
|
||||
## Example User Secrets file
|
||||
|
||||
This is an example user secrets file for both the Api and Identity projects.
|
||||
|
||||
```json
|
||||
{
|
||||
"globalSettings": {
|
||||
"selfHosted": true,
|
||||
"identityServer": {
|
||||
"certificateThumbprint": "<your Identity certificate thumbprint with no spaces>"
|
||||
},
|
||||
"dataProtection": {
|
||||
"certificateThumbprint": "<your Data Protection certificate thumbprint with no spaces>"
|
||||
},
|
||||
"installation": {
|
||||
"id": "<your Installation Id>",
|
||||
"key": "<your Installation Key>"
|
||||
},
|
||||
"licenseDirectory": "<full path to licence directory>",
|
||||
"sqlServer": {
|
||||
"connectionString": "Server=localhost;Database=vault_dev;User Id=sa;Password=<your SA_PASSWORD>"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Running and Debugging
|
||||
After you have completed the above steps, you should be ready to launch your development environment for the Api and Identity projects.
|
||||
|
||||
@ -230,3 +162,34 @@ From within Rider, launch both the Api project and the Identity project by click
|
||||
|
||||
### Troubleshooting
|
||||
* If you get a 404 error, the projects may be listening on a non-default port. Check the output of your running projects to check the port they are listening on.
|
||||
|
||||
|
||||
# <a name="user-secrets"></a>Appendix A (User Secrets)
|
||||
|
||||
### Editing user secrets - Visual Studio on Windows
|
||||
Right-click on the project in the Solution Explorer and click **Manage User Secrets**.
|
||||
|
||||
### Editing user secrets - Visual Studio on macOS
|
||||
Open a terminal and navigate to the project directory. Once there, initiate and create the blank user secrets file by running:
|
||||
|
||||
```bash
|
||||
dotnet user-secrets init
|
||||
```
|
||||
|
||||
Add a user secret by running:
|
||||
|
||||
```bash
|
||||
dotnet user-secrets set "<key>" "<value>"
|
||||
```
|
||||
|
||||
View currently set secrets by running:
|
||||
|
||||
```bash
|
||||
dotnet user-secrets list
|
||||
```
|
||||
|
||||
By default, user secret files are located in `~/.microsoft/usersecrets/<project name>/secrets.json`. After the file has been created, you can edit this directly with VSCode, which is much easier than using the command line tool.
|
||||
|
||||
### Editing user secrets - Rider
|
||||
* Navigate to **Preferences -> Plugins** and Install .NET Core User Secrets
|
||||
* Right click on the a project and click **Tools** > **Open project user secrets**
|
||||
|
3
dev/.env.example
Normal file
3
dev/.env.example
Normal file
@ -0,0 +1,3 @@
|
||||
COMPOSE_PROJECT_NAME=BitwardenServer
|
||||
MSSQL_PASSWORD=SET_A_PASSWORD_HERE_123
|
||||
MAILCATCHER_PORT=1080
|
10
dev/.gitignore
vendored
Normal file
10
dev/.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
.data
|
||||
secrets.json
|
||||
.env
|
||||
|
||||
identity_server_dev.crt
|
||||
identity_server_dev.key
|
||||
identity_server_dev.pfx
|
||||
data_protection_dev.crt
|
||||
data_protection_dev.key
|
||||
data_protection_dev.pfx
|
23
dev/create_certificates_mac.sh
Executable file
23
dev/create_certificates_mac.sh
Executable file
@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
openssl req -x509 -newkey rsa:4096 -sha256 -nodes -keyout identity_server_dev.key -out identity_server_dev.crt \
|
||||
-subj "/CN=Bitwarden Identity Server Dev" -days 3650
|
||||
openssl pkcs12 -export -out identity_server_dev.pfx -inkey identity_server_dev.key -in identity_server_dev.crt \
|
||||
-certfile identity_server_dev.crt
|
||||
|
||||
security import ./identity_server_dev.pfx -k ~/Library/Keychains/Login.keychain
|
||||
|
||||
openssl req -x509 -newkey rsa:4096 -sha256 -nodes -keyout data_protection_dev.key -out data_protection_dev.crt \
|
||||
-subj "/CN=Bitwarden Data Protection Dev" -days 3650
|
||||
openssl pkcs12 -export -out data_protection_dev.pfx -inkey data_protection_dev.key -in data_protection_dev.crt \
|
||||
-certfile data_protection_dev.crt
|
||||
|
||||
security import ./data_protection_dev.pfx -k ~/Library/Keychains/Login.keychain
|
||||
|
||||
identity=($(openssl x509 -in identity_server_dev.crt -outform der | shasum -a 1 | tr a-z A-Z));
|
||||
data=($(openssl x509 -in data_protection_dev.crt -outform der | shasum -a 1 | tr a-z A-Z));
|
||||
|
||||
echo "Certificate fingerprints:"
|
||||
|
||||
echo "Identity Server Dev: ${identity}"
|
||||
echo "Data Protection Dev: ${data}"
|
14
dev/create_certificates_windows.ps1
Normal file
14
dev/create_certificates_windows.ps1
Normal file
@ -0,0 +1,14 @@
|
||||
# Script for generating and installing the Bitwarden development certificates on Windows.
|
||||
|
||||
$params = @{
|
||||
'KeyAlgorithm' = 'RSA';
|
||||
'KeyLength' = 4096;
|
||||
'NotAfter' = (Get-Date).AddDays(3650);
|
||||
'CertStoreLocation' = 'Cert:\CurrentUser\My';
|
||||
};
|
||||
|
||||
$params['Subject'] = 'CN=Bitwarden Identity Server Dev';
|
||||
New-SelfSignedCertificate @params;
|
||||
|
||||
$params['Subject'] = 'CN=Bitwarden Data Protection Dev';
|
||||
New-SelfSignedCertificate @params;
|
43
dev/docker-compose.yml
Normal file
43
dev/docker-compose.yml
Normal file
@ -0,0 +1,43 @@
|
||||
version: "3.9"
|
||||
|
||||
services:
|
||||
mssql:
|
||||
image: mcr.microsoft.com/mssql/server:2017-latest
|
||||
restart: always
|
||||
environment:
|
||||
ACCEPT_EULA: Y
|
||||
SA_PASSWORD: ${MSSQL_PASSWORD}
|
||||
MSSQL_PID: Developer
|
||||
volumes:
|
||||
- mssql_dev_data:/var/opt/mssql/data
|
||||
- ../util/Migrator:/mnt/migrator/
|
||||
- ./helpers/mssql:/mnt/helpers
|
||||
- ./.data/mssql:/mnt/data
|
||||
ports:
|
||||
- '1433:1433'
|
||||
profiles:
|
||||
- cloud
|
||||
- mssql
|
||||
|
||||
storage:
|
||||
image: mcr.microsoft.com/azure-storage/azurite:latest
|
||||
ports:
|
||||
- "10000:10000"
|
||||
- "10001:10001"
|
||||
- "10002:10002"
|
||||
volumes:
|
||||
- ./.data/azurite:/data
|
||||
profiles:
|
||||
- storage
|
||||
- cloud
|
||||
|
||||
mail:
|
||||
image: sj26/mailcatcher:latest
|
||||
ports:
|
||||
- "${MAILCATCHER_PORT}:1080"
|
||||
- "10250:1025"
|
||||
profiles:
|
||||
- mail
|
||||
|
||||
volumes:
|
||||
mssql_dev_data:
|
70
dev/helpers/mssql/run_migrations.sh
Normal file
70
dev/helpers/mssql/run_migrations.sh
Normal file
@ -0,0 +1,70 @@
|
||||
#!/bin/bash
|
||||
|
||||
MIGRATE_DIRECTORY="/mnt/migrator/DbScripts"
|
||||
LAST_MIGRATION_FILE="/mnt/data/last_migration"
|
||||
SERVER='localhost'
|
||||
DATABASE="vault_dev"
|
||||
USER="SA"
|
||||
PASSWD=$SA_PASSWORD
|
||||
|
||||
if [ ! -f "$LAST_MIGRATION_FILE" ]; then
|
||||
echo "$LAST_MIGRATION_FILE not found!"
|
||||
echo "This will run all migrations which might cause unexpected behaviour if the database is not empty."
|
||||
echo
|
||||
read -p "Run all Migrations? (y/N) " -n 1 -r
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]
|
||||
then
|
||||
exit 1
|
||||
fi
|
||||
LAST_MIGRATION=""
|
||||
else
|
||||
LAST_MIGRATION=$(cat $LAST_MIGRATION_FILE)
|
||||
fi
|
||||
|
||||
[ -z "$LAST_MIGRATION" ]
|
||||
PERFORM_MIGRATION=$?
|
||||
|
||||
while getopts "r" arg; do
|
||||
case $arg in
|
||||
r)
|
||||
RERUN=1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -n "$RERUN" ]; then
|
||||
echo "Rerunning the last migration"
|
||||
fi
|
||||
|
||||
# Create database if it does not already exist
|
||||
QUERY="IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = 'vault_dev')
|
||||
BEGIN
|
||||
CREATE DATABASE vault_dev;
|
||||
END;"
|
||||
|
||||
/opt/mssql-tools/bin/sqlcmd -S $SERVER -d master -U $USER -P $PASSWD -I -Q "$QUERY"
|
||||
|
||||
migrate () {
|
||||
local file=$1
|
||||
echo "Performing $file"
|
||||
/opt/mssql-tools/bin/sqlcmd -S $SERVER -d $DATABASE -U $USER -P $PASSWD -I -i $file
|
||||
echo $file > $LAST_MIGRATION_FILE
|
||||
}
|
||||
|
||||
for f in `ls -v $MIGRATE_DIRECTORY/*.sql`; do
|
||||
if (( PERFORM_MIGRATION == 0 )); then
|
||||
migrate $f
|
||||
else
|
||||
echo "Skipping $f"
|
||||
if [ "$LAST_MIGRATION" == "$f" ]; then
|
||||
PERFORM_MIGRATION=0
|
||||
|
||||
# Rerun last migration
|
||||
if [ -n "$RERUN" ]; then
|
||||
migrate $f
|
||||
unset RERUN
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done;
|
4
dev/migrate.ps1
Normal file
4
dev/migrate.ps1
Normal file
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env pwsh
|
||||
# Creates the vault_dev database, and runs all the migrations.
|
||||
|
||||
docker-compose --profile mssql exec mssql bash /mnt/helpers/run_migrations.sh @args
|
22
dev/secrets.json.example
Normal file
22
dev/secrets.json.example
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"adminSettings": {
|
||||
"admins": "admin@localhost"
|
||||
},
|
||||
"globalSettings": {
|
||||
"selfHosted": true,
|
||||
"sqlServer": {
|
||||
"connectionString": "Server=localhost;Database=vault_dev;User Id=SA;Password=SET_A_PASSWORD_HERE_123;"
|
||||
},
|
||||
"identityServer": {
|
||||
"certificateThumbprint": "<your Identity certificate thumbprint with no spaces>"
|
||||
},
|
||||
"dataProtection": {
|
||||
"certificateThumbprint": "<your Data Protection certificate thumbprint with no spaces>"
|
||||
},
|
||||
"installation": {
|
||||
"id": "<your Installation Id>",
|
||||
"key": "<your Installation Key>"
|
||||
},
|
||||
"licenseDirectory": "<full path to licence directory>"
|
||||
}
|
||||
}
|
47
dev/setup_azurite.ps1
Executable file
47
dev/setup_azurite.ps1
Executable file
@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env pwsh
|
||||
# Script for configuring the initial state of Azurite Storage account
|
||||
# Can be run multiple times without negative impact
|
||||
|
||||
# Start configuration
|
||||
$corsRules = (@{
|
||||
AllowedHeaders = @("*");
|
||||
ExposedHeaders = @("*");
|
||||
AllowedOrigins = @("*");
|
||||
MaxAgeInSeconds = 30;
|
||||
AllowedMethods = @("Get", "PUT");
|
||||
});
|
||||
$containers = "attachments", "sendfiles", "misc";
|
||||
$queues = "event", "notifications", "reference-events", "mail";
|
||||
$tables = "event", "metadata", "installationdevice";
|
||||
# End configuration
|
||||
|
||||
$context = New-AzStorageContext -Local
|
||||
|
||||
foreach ($container in $containers) {
|
||||
if (Get-AzStorageContainer -Name $container -Context $context -ErrorAction SilentlyContinue) {
|
||||
Write-Host -ForegroundColor Magenta "Container already exists:" $container
|
||||
}
|
||||
else {
|
||||
New-AzStorageContainer -Name $container -Context $context
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($queue in $queues) {
|
||||
if (Get-AzStorageQueue -Name $queue -Context $context -ErrorAction SilentlyContinue) {
|
||||
Write-Host -ForegroundColor Magenta "Queue already exists:" $queue
|
||||
}
|
||||
else {
|
||||
New-AzStorageQueue -Name $queue -Context $context
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($table in $tables) {
|
||||
if (Get-AzStorageTable -Name $table -Context $context -ErrorAction SilentlyContinue) {
|
||||
Write-Host -ForegroundColor Magenta "Table already exists:" $table
|
||||
}
|
||||
else {
|
||||
New-AzStorageTable -Name $table -Context $context
|
||||
}
|
||||
}
|
||||
|
||||
Set-AzStorageCORSRule -ServiceType Blob -CorsRules $corsRules -Context $context
|
21
dev/setup_secrets.ps1
Normal file
21
dev/setup_secrets.ps1
Normal file
@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env pwsh
|
||||
# Helper script for applying the same user secrets to each project
|
||||
param (
|
||||
[bool]$clear,
|
||||
[Parameter(ValueFromRemainingArguments = $true, Position=1)]
|
||||
$cmdArgs
|
||||
)
|
||||
|
||||
if (!(Test-Path "secrets.json")) {
|
||||
Write-Warning "No secrets.json file found, please copy and modify the provided example";
|
||||
exit;
|
||||
}
|
||||
|
||||
$projects = "Admin", "Api", "Billing", "Events", "EventsProcessor", "Icons", "Identity", "Notifications";
|
||||
|
||||
foreach ($projects in $projects) {
|
||||
if ($clear -eq $true) {
|
||||
dotnet user-secrets clear -p "../src/$projects"
|
||||
}
|
||||
Get-Content secrets.json | & dotnet user-secrets set -p "../src/$projects"
|
||||
}
|
@ -14,9 +14,17 @@
|
||||
"internalVault": "http://localhost:4001",
|
||||
"internalSso": "http://localhost:51822"
|
||||
},
|
||||
"send": {
|
||||
"connectionString": "SECRET",
|
||||
"baseUrl": "http://localhost:4000/sendfiles/"
|
||||
"mail": {
|
||||
"smtp": {
|
||||
"host": "localhost",
|
||||
"port": 10250
|
||||
}
|
||||
},
|
||||
"events": {
|
||||
"connectionString": "UseDevelopmentStorage=true"
|
||||
},
|
||||
"storage": {
|
||||
"connectionString": "UseDevelopmentStorage=true"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,13 +14,28 @@
|
||||
"internalVault": "http://localhost:4001",
|
||||
"internalSso": "http://localhost:51822"
|
||||
},
|
||||
"mail": {
|
||||
"smtp": {
|
||||
"host": "localhost",
|
||||
"port": 10250
|
||||
}
|
||||
},
|
||||
"attachment": {
|
||||
"connectionString": "SECRET",
|
||||
"connectionString": "UseDevelopmentStorage=true",
|
||||
"baseUrl": "http://localhost:4000/attachments/"
|
||||
},
|
||||
"events": {
|
||||
"connectionString": "UseDevelopmentStorage=true"
|
||||
},
|
||||
"send": {
|
||||
"connectionString": "SECRET",
|
||||
"connectionString": "UseDevelopmentStorage=true",
|
||||
"baseUrl": "http://localhost:4000/sendfiles/"
|
||||
},
|
||||
"notifications": {
|
||||
"connectionString": "UseDevelopmentStorage=true"
|
||||
},
|
||||
"storage": {
|
||||
"connectionString": "UseDevelopmentStorage=true"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,22 @@
|
||||
"internalApi": "http://localhost:4000",
|
||||
"internalVault": "http://localhost:4001",
|
||||
"internalSso": "http://localhost:51822"
|
||||
},
|
||||
"mail": {
|
||||
"smtp": {
|
||||
"host": "localhost",
|
||||
"port": 10250
|
||||
}
|
||||
},
|
||||
"attachment": {
|
||||
"connectionString": "UseDevelopmentStorage=true",
|
||||
"baseUrl": "http://localhost:4000/attachments/"
|
||||
},
|
||||
"events": {
|
||||
"connectionString": "UseDevelopmentStorage=true"
|
||||
},
|
||||
"storage": {
|
||||
"connectionString": "UseDevelopmentStorage=true"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,12 @@
|
||||
"internalApi": "http://localhost:4000",
|
||||
"internalVault": "http://localhost:4001",
|
||||
"internalSso": "http://localhost:51822"
|
||||
},
|
||||
"events": {
|
||||
"connectionString": "UseDevelopmentStorage=true"
|
||||
},
|
||||
"storage": {
|
||||
"connectionString": "UseDevelopmentStorage=true"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,18 @@
|
||||
"internalApi": "http://localhost:4000",
|
||||
"internalVault": "http://localhost:4001",
|
||||
"internalSso": "http://localhost:51822"
|
||||
},
|
||||
"attachment": {
|
||||
"connectionString": "UseDevelopmentStorage=true"
|
||||
},
|
||||
"events": {
|
||||
"connectionString": "UseDevelopmentStorage=true"
|
||||
},
|
||||
"notifications": {
|
||||
"connectionString": "UseDevelopmentStorage=true"
|
||||
},
|
||||
"storage": {
|
||||
"connectionString": "UseDevelopmentStorage=true"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,9 @@
|
||||
"internalApi": "http://localhost:4000",
|
||||
"internalVault": "http://localhost:4001",
|
||||
"internalSso": "http://localhost:51822"
|
||||
},
|
||||
"notifications": {
|
||||
"connectionString": "UseDevelopmentStorage=true"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user