mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-05 18:48:41 +00:00
refactor: simplify configuration to a single env file
This commit is contained in:
+3
-1
@@ -1,6 +1,8 @@
|
|||||||
**/.classpath
|
**/.classpath
|
||||||
**/.dockerignore
|
**/.dockerignore
|
||||||
**/.env
|
**/.env
|
||||||
|
**/backend.env
|
||||||
|
**/frontend.env
|
||||||
**/.git
|
**/.git
|
||||||
**/.gitignore
|
**/.gitignore
|
||||||
**/.project
|
**/.project
|
||||||
@@ -27,4 +29,4 @@ README.md
|
|||||||
!.git/HEAD
|
!.git/HEAD
|
||||||
!.git/config
|
!.git/config
|
||||||
!.git/packed-refs
|
!.git/packed-refs
|
||||||
!.git/refs/heads/**
|
!.git/refs/heads/**
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
# Replace every replace_with_ value before running. See README.md for secret generation.
|
# Copy to .env in the repository root. Replace every replace_with_ value before running.
|
||||||
# Use a different random secret for each setting, except the shared frontend/backend key.
|
# Generate a different random value for each secret. See README.md for instructions.
|
||||||
# Required Misc. Variables
|
|
||||||
|
# Site
|
||||||
Domain=example.com
|
Domain=example.com
|
||||||
Https=true
|
Https=true
|
||||||
AllowedCorsOrigins__0=https://example.com
|
AllowedCorsOrigins__0=https://example.com
|
||||||
JwtSettings__Secret=replace_with_a_unique_random_jwt_secret_before_running
|
ORIGIN=https://example.com
|
||||||
ConnectionStrings__DefaultConnection=Data Source=/app/data/sharpbin.db
|
|
||||||
|
|
||||||
# Auth Settings
|
# Authentication
|
||||||
|
JwtSettings__Secret=replace_with_a_unique_random_jwt_secret_before_running
|
||||||
# These Turnstile keys are for testing. Use your own site and secret keys in production.
|
# These Turnstile keys are for testing. Use your own site and secret keys in production.
|
||||||
AuthSettings__CF_Turnstile_SecretKey=1x0000000000000000000000000000000AA
|
AuthSettings__CF_Turnstile_SecretKey=1x0000000000000000000000000000000AA
|
||||||
AuthSettings__CF_Turnstile_SiteKey=3x00000000000000000000FF
|
AuthSettings__CF_Turnstile_SiteKey=3x00000000000000000000FF
|
||||||
@@ -15,12 +16,11 @@ AuthSettings__Registration_Enabled=true
|
|||||||
AuthSettings__Admins_Require_2FA=true
|
AuthSettings__Admins_Require_2FA=true
|
||||||
AuthSettings__API_Key_HMAC_Secret=replace_with_a_unique_random_api_key_hmac_secret_before_running
|
AuthSettings__API_Key_HMAC_Secret=replace_with_a_unique_random_api_key_hmac_secret_before_running
|
||||||
|
|
||||||
# Paste Settings
|
# Pastes
|
||||||
PasteSettings__MaxTitleLength=500
|
PasteSettings__MaxTitleLength=500
|
||||||
PasteSettings__MaxPasteSizeInBytes=1048576
|
PasteSettings__MaxPasteSizeInBytes=1048576
|
||||||
PasteSettings__EnablePasteCompression=true
|
PasteSettings__EnablePasteCompression=true
|
||||||
PasteSettings__RequiresVerification=true
|
PasteSettings__RequiresVerification=true
|
||||||
PasteSettings__View_HMAC_Secret=replace_with_a_unique_random_view_hmac_secret_before_running
|
PasteSettings__View_HMAC_Secret=replace_with_a_unique_random_view_hmac_secret_before_running
|
||||||
# Used so that views are only counted from the frontend
|
# Compose passes this value to both services. No separate frontend key is needed.
|
||||||
# Must be the same on both the frontend and backend environment
|
PasteSettings__View_Internal_API_Key=replace_with_a_unique_random_internal_api_key_before_running
|
||||||
PasteSettings__View_Internal_API_Key=replace_with_the_same_random_internal_api_key_in_both_files
|
|
||||||
+3
-1
@@ -325,4 +325,6 @@ Data
|
|||||||
!SharpbinV3.Server/Data
|
!SharpbinV3.Server/Data
|
||||||
.idea
|
.idea
|
||||||
|
|
||||||
**/.env
|
**/.env
|
||||||
|
backend.env
|
||||||
|
frontend.env
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ The easiest way to run SharpbinV3 is using Docker Compose.
|
|||||||
git clone https://github.com/whoswhip/Sharpbin.git
|
git clone https://github.com/whoswhip/Sharpbin.git
|
||||||
```
|
```
|
||||||
|
|
||||||
3. In the repository root, copy `backend.env.example` to `backend.env` and `frontend.env.example` to `frontend.env`.
|
3. In the repository root, copy `.env.example` to `.env`.
|
||||||
4. Replace the secret placeholders and configure your domain and Turnstile keys. Set `ORIGIN` to the public frontend URL, including the scheme. For local Docker testing, use `ORIGIN=http://localhost:5173`, `Domain=localhost:5173`, `Https=false`, and `AllowedCorsOrigins__0=http://localhost:5173`.
|
4. Replace the secret placeholders and configure your domain and Turnstile keys. Set `ORIGIN` to the public frontend URL, including the scheme. For local Docker testing, use `ORIGIN=http://localhost:5173`, `Domain=localhost:5173`, `Https=false`, and `AllowedCorsOrigins__0=http://localhost:5173`.
|
||||||
5. Run the following command in the root directory:
|
5. Run the following command in the root directory:
|
||||||
|
|
||||||
@@ -36,9 +36,11 @@ docker compose up -d --build
|
|||||||
|
|
||||||
### Configuration
|
### Configuration
|
||||||
|
|
||||||
Configure the backend in `backend.env` and the frontend in `frontend.env` when using Docker Compose. The backend also loads `appsettings.json`, with environment variables taking precedence.
|
Configure Sharpbin in the root `.env` file when using Docker Compose. The backend loads this file as environment variables. Compose passes only the backend URL, public origin, and shared view-recording key to the frontend.
|
||||||
|
|
||||||
Compose explicitly sets `ConnectionStrings__DefaultConnection`, `DATA_PROTECTION_KEY_PATH`, and the frontend's `VITE_API_URL`. These override values from the environment files; change `docker-compose.yml` to override them.
|
The backend image includes `appsettings.json` with application defaults. Environment variables have priority, so you do not need to edit or mount that file for normal setup. Additional backend settings, including `EmailSettings__Host` and other SMTP settings, can be added to `.env` using their existing names.
|
||||||
|
|
||||||
|
Compose defaults the database to `/app/data/sharpbin.db`, Data Protection keys to `/app/data/keys`, and `VITE_API_URL` to `http://backend:8080`. To override them, add `ConnectionStrings__DefaultConnection`, `DATA_PROTECTION_KEY_PATH`, or `VITE_API_URL` to `.env`. Keep database and key paths under `/app/data` to use the existing persistent volume.
|
||||||
|
|
||||||
The example secrets are placeholders, not secure defaults. Generate a separate secret for JWT signing, API-key hashing, and view hashing, plus one shared internal API key. This command generates a 64-character random hex value; run it once for each secret:
|
The example secrets are placeholders, not secure defaults. Generate a separate secret for JWT signing, API-key hashing, and view hashing, plus one shared internal API key. This command generates a 64-character random hex value; run it once for each secret:
|
||||||
|
|
||||||
@@ -52,7 +54,17 @@ or use openSSL:
|
|||||||
openssl rand -hex 32
|
openssl rand -hex 32
|
||||||
```
|
```
|
||||||
|
|
||||||
Set the same shared value in `PasteSettings__View_Internal_API_Key` in `backend.env` and `VIEW_INTERNAL_API_KEY` in `frontend.env`. Keep generated secrets across restarts and updates. Changing the API-key HMAC secret invalidates existing API keys.
|
Set the shared key once as `PasteSettings__View_Internal_API_Key`. Compose supplies it to the frontend as `VIEW_INTERNAL_API_KEY`. Keep generated secrets across restarts and updates. Changing the API-key HMAC secret invalidates existing API keys.
|
||||||
|
|
||||||
|
#### Migrating an Existing Installation
|
||||||
|
|
||||||
|
1. Copy the values from `backend.env` into the root `.env` file. If `.env` already exists, merge the settings without replacing existing values blindly.
|
||||||
|
2. Copy `ORIGIN` from `frontend.env`. If it was unset, use your public frontend URL, including the scheme.
|
||||||
|
3. Keep `PasteSettings__View_Internal_API_Key` set to the existing shared key. The separate `VIEW_INTERNAL_API_KEY` entry is no longer needed for Compose.
|
||||||
|
4. Move any custom `appsettings.json` values into `.env` using `__` for nested settings. For array settings, use numbered entries such as `AllowedCorsOrigins__0`. If you need to retain a custom JSON file, add a read-only mount for it in `compose.override.yaml`.
|
||||||
|
5. Run `docker compose up -d --build`. The old `backend.env` and `frontend.env` files are no longer read by Compose.
|
||||||
|
|
||||||
|
Keep the existing database volume, Data Protection keys, and secret values. Do not regenerate secrets during this migration.
|
||||||
|
|
||||||
> When configuring via `appsettings.json` instead of for example `ConnectionStrings__DefaultConnection` it would be:
|
> When configuring via `appsettings.json` instead of for example `ConnectionStrings__DefaultConnection` it would be:
|
||||||
|
|
||||||
@@ -80,14 +92,14 @@ Set the same shared value in `PasteSettings__View_Internal_API_Key` in `backend.
|
|||||||
- `PasteSettings__EnablePasteCompression`:**true**: Enables/Disables server-side paste compression.
|
- `PasteSettings__EnablePasteCompression`:**true**: Enables/Disables server-side paste compression.
|
||||||
- `PasteSettings__RequiresVerification`:**true**: Enables/Disables CAPTCHA verification when creating pastes.
|
- `PasteSettings__RequiresVerification`:**true**: Enables/Disables CAPTCHA verification when creating pastes.
|
||||||
- `PasteSettings__View_HMAC_Secret`: A required random secret of 32–128 characters used to hash viewer identifiers.
|
- `PasteSettings__View_HMAC_Secret`: A required random secret of 32–128 characters used to hash viewer identifiers.
|
||||||
- `PasteSettings__View_Internal_API_Key`: A shared key of 32–128 characters used to authorize view recording. Match the frontend's `VIEW_INTERNAL_API_KEY`.
|
- `PasteSettings__View_Internal_API_Key`: A shared key of 32–128 characters used to authorize view recording. Compose passes it to both services.
|
||||||
|
|
||||||
#### Frontend (SharpbinV3.Client)
|
#### Frontend (SharpbinV3.Client)
|
||||||
|
|
||||||
- `VITE_API_URL`: The backend URL reachable from the frontend server. Defaults to `http://localhost:5050`; Compose overrides it with `http://backend:8080`. Browser requests use the frontend's `/api` proxy.
|
- `VITE_API_URL`: The backend URL reachable from the frontend server. Defaults to `http://localhost:5050` when running directly and `http://backend:8080` in Compose. Browser requests use the frontend's `/api` proxy.
|
||||||
- `ORIGIN`: The public frontend URL, including its scheme (e.g., `https://example.com`). Used by the production Node server; see [SvelteKit's Node adapter documentation](https://svelte.dev/docs/kit/adapter-node#ORIGIN-PROTOCOL_HEADER-HOST_HEADER-and-PORT_HEADER).
|
- `ORIGIN`: The public frontend URL, including its scheme (e.g., `https://example.com`). Used by the production Node server; see [SvelteKit's Node adapter documentation](https://svelte.dev/docs/kit/adapter-node#ORIGIN-PROTOCOL_HEADER-HOST_HEADER-and-PORT_HEADER).
|
||||||
- `VITE_ALLOWED_HOSTS`: A comma-separated list used only by Vite dev/preview (e.g., `localhost,sharpbin.cc`). Export it in the shell before starting Vite; the config reads `process.env` directly. It does not configure production host restrictions.
|
- `VITE_ALLOWED_HOSTS`: A comma-separated list used only by Vite dev/preview (e.g., `localhost,sharpbin.cc`). Export it in the shell before starting Vite; the config reads `process.env` directly. It does not configure production host restrictions.
|
||||||
- `VIEW_INTERNAL_API_KEY`: The production frontend's shared view-recording key. Falls back to `View_HMAC_Internal_API_Key` if unset. The frontend does not read `PasteSettings__View_Internal_API_Key`.
|
- `VIEW_INTERNAL_API_KEY`: The production frontend's shared view-recording key. Compose sets it from `PasteSettings__View_Internal_API_Key`; do not duplicate it in the root `.env`. When running the frontend directly, set it yourself or use the existing `View_HMAC_Internal_API_Key` fallback.
|
||||||
|
|
||||||
When `NODE_ENV=development`, the frontend uses a fixed development-only internal key matching the backend's checked-in development configuration and ignores both environment key names. See the [client README](SharpbinV3.Client/README.md) for development and standalone production setup.
|
When `NODE_ENV=development`, the frontend uses a fixed development-only internal key matching the backend's checked-in development configuration and ignores both environment key names. See the [client README](SharpbinV3.Client/README.md) for development and standalone production setup.
|
||||||
|
|
||||||
|
|||||||
@@ -38,13 +38,15 @@ The frontend will be available at http://localhost:5173.
|
|||||||
|
|
||||||
### Running in Production
|
### Running in Production
|
||||||
|
|
||||||
Docker Compose loads `frontend.env` and runs the built Node server on port 5173. Set these runtime variables:
|
Docker Compose reads the root `.env` file and runs the built Node server on port 5173. Configure these values there:
|
||||||
|
|
||||||
- `VITE_API_URL`: Backend URL. Compose sets `http://backend:8080` directly, overriding `frontend.env`.
|
- `VITE_API_URL`: Backend URL. Defaults to `http://backend:8080` in Compose.
|
||||||
- `ORIGIN`: Public frontend URL, such as `https://example.com` or `http://localhost:5173` for local Docker testing.
|
- `ORIGIN`: Public frontend URL, such as `https://example.com` or `http://localhost:5173` for local Docker testing.
|
||||||
- `VIEW_INTERNAL_API_KEY`: Same generated value as the backend's `PasteSettings__View_Internal_API_Key`. If unset, the frontend reads `View_HMAC_Internal_API_Key`; it does not read the backend setting name.
|
- `PasteSettings__View_Internal_API_Key`: Shared view-recording key. Compose passes it to the frontend as `VIEW_INTERNAL_API_KEY`, so you only set it once.
|
||||||
|
|
||||||
For a standalone Node deployment, `.env` is not loaded automatically. Build the frontend, then load your environment file explicitly:
|
For a standalone Node deployment, set `VITE_API_URL`, `ORIGIN`, and `VIEW_INTERNAL_API_KEY` in the client's own `.env` file. The key must match the backend's `PasteSettings__View_Internal_API_Key`. The frontend still supports `View_HMAC_Internal_API_Key` as a fallback; it does not read the backend setting name directly.
|
||||||
|
|
||||||
|
The standalone server does not load `.env` automatically. Build the frontend, then load your environment file explicitly:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm run build
|
npm run build
|
||||||
|
|||||||
@@ -13,10 +13,12 @@ This is the backend API for SharpbinV3, built with ASP.NET Core and Entity Frame
|
|||||||
|
|
||||||
The server configuration is managed in `appsettings.json`. For development, ensure you have set the following in `appsettings.Development.json` or as environment variables:
|
The server configuration is managed in `appsettings.json`. For development, ensure you have set the following in `appsettings.Development.json` or as environment variables:
|
||||||
|
|
||||||
- `ConnectionStrings__DefaultConnection`: SQLite connection string (e.g., `Data Source=sharpbin.db` locally). Compose sets `Data Source=/app/data/sharpbin.db` directly.
|
- `ConnectionStrings__DefaultConnection`: SQLite connection string (e.g., `Data Source=sharpbin.db` locally). Compose defaults to `Data Source=/app/data/sharpbin.db`.
|
||||||
- `JwtSettings__Secret`: A random secret of 32–128 characters used for signing JWT tokens.
|
- `JwtSettings__Secret`: A random secret of 32–128 characters used for signing JWT tokens.
|
||||||
- `PasteSettings__View_HMAC_Secret`: A required random secret of 32–128 characters used to hash viewer identifiers.
|
- `PasteSettings__View_HMAC_Secret`: A required random secret of 32–128 characters used to hash viewer identifiers.
|
||||||
- `PasteSettings__View_Internal_API_Key`: A shared key of 32–128 characters used to authorize view recording. Match the production frontend's `VIEW_INTERNAL_API_KEY`.
|
- `PasteSettings__View_Internal_API_Key`: A shared key of 32–128 characters used to authorize view recording. Compose passes it to both services. For standalone deployments, match the frontend's `VIEW_INTERNAL_API_KEY`.
|
||||||
|
|
||||||
|
For Docker Compose, configure the backend in the root `.env` file. The image includes `appsettings.json` defaults, and environment variables override them. No host configuration mount is required.
|
||||||
|
|
||||||
The development frontend uses a fixed internal key matching the checked-in `appsettings.Development.json`. Changing only the backend key will break development view recording. Use generated secrets for deployment; see the [root configuration guide](../README.md#configuration).
|
The development frontend uses a fixed internal key matching the checked-in `appsettings.Development.json`. Changing only the backend key will break development view recording. Use generated secrets for deployment; see the [root configuration guide](../README.md#configuration).
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Content Include="appsettings.json" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
|
||||||
<EmbeddedResource Include="EmailTemplates\*.html" />
|
<EmbeddedResource Include="EmailTemplates\*.html" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
+8
-8
@@ -6,13 +6,13 @@ services:
|
|||||||
image: sharpbin-backend
|
image: sharpbin-backend
|
||||||
container_name: sharpbin-backend
|
container_name: sharpbin-backend
|
||||||
env_file:
|
env_file:
|
||||||
- "backend.env"
|
- ".env"
|
||||||
environment:
|
environment:
|
||||||
DATA_PROTECTION_KEY_PATH: /app/data/keys
|
DATA_PROTECTION_KEY_PATH: ${DATA_PROTECTION_KEY_PATH:-/app/data/keys}
|
||||||
ConnectionStrings__DefaultConnection: "Data Source=/app/data/sharpbin.db"
|
ConnectionStrings__DefaultConnection: ${ConnectionStrings__DefaultConnection:-Data Source=/app/data/sharpbin.db}
|
||||||
|
PasteSettings__View_Internal_API_Key: ${PasteSettings__View_Internal_API_Key:?Set PasteSettings__View_Internal_API_Key in .env}
|
||||||
volumes:
|
volumes:
|
||||||
- sharpbin-data:/app/data
|
- sharpbin-data:/app/data
|
||||||
- ./SharpbinV3.Server/appsettings.json:/app/appsettings.json
|
|
||||||
networks:
|
networks:
|
||||||
- sharpbin-net
|
- sharpbin-net
|
||||||
healthcheck:
|
healthcheck:
|
||||||
@@ -28,13 +28,13 @@ services:
|
|||||||
context: ./SharpbinV3.Client
|
context: ./SharpbinV3.Client
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
args:
|
args:
|
||||||
GIT_COMMIT_HASH: ${GIT_COMMIT_HASH}
|
GIT_COMMIT_HASH: ${GIT_COMMIT_HASH:-unknown}
|
||||||
image: sharpbin-frontend
|
image: sharpbin-frontend
|
||||||
container_name: sharpbin-frontend
|
container_name: sharpbin-frontend
|
||||||
env_file:
|
|
||||||
- "frontend.env"
|
|
||||||
environment:
|
environment:
|
||||||
VITE_API_URL: http://backend:8080
|
VITE_API_URL: ${VITE_API_URL:-http://backend:8080}
|
||||||
|
ORIGIN: ${ORIGIN:?Set ORIGIN in .env}
|
||||||
|
VIEW_INTERNAL_API_KEY: ${PasteSettings__View_Internal_API_Key:?Set PasteSettings__View_Internal_API_Key in .env}
|
||||||
|
|
||||||
ports:
|
ports:
|
||||||
- "5173:5173"
|
- "5173:5173"
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
# Docker Compose sets this URL directly; change docker-compose.yml to override it.
|
|
||||||
VITE_API_URL=http://backend:8080
|
|
||||||
# Public frontend URL, including the scheme. Use http://localhost:5173 for local Docker testing.
|
|
||||||
ORIGIN=https://example.com
|
|
||||||
# VITE_ALLOWED_HOSTS only affects Vite dev/preview, not the production Node server.
|
|
||||||
# Used so that views are only counted from the frontend
|
|
||||||
# Must be the same on both the frontend and backend environment
|
|
||||||
# Production fallback: View_HMAC_Internal_API_Key (not PasteSettings__View_Internal_API_Key).
|
|
||||||
# Replace this placeholder with the same generated value as the backend setting.
|
|
||||||
VIEW_INTERNAL_API_KEY=replace_with_the_same_random_internal_api_key_in_both_files
|
|
||||||
Reference in New Issue
Block a user