mirror of
https://github.com/sysadminsmedia/homebox.git
synced 2025-12-21 21:33:02 +01:00
Update to add new blob storage options
This commit is contained in:
@@ -128,12 +128,60 @@ const config = reactive({
|
|||||||
allowRegistration: true,
|
allowRegistration: true,
|
||||||
autoIncrementAssetId: true,
|
autoIncrementAssetId: true,
|
||||||
checkGithubRelease: true,
|
checkGithubRelease: true,
|
||||||
|
|
||||||
|
// Storage Configuration
|
||||||
|
storageType: "local", // local, s3, gcs, azure
|
||||||
storageConfig: {
|
storageConfig: {
|
||||||
homeboxStorage: {
|
// Local storage settings
|
||||||
|
local: {
|
||||||
type: "volume", // "volume" or "directory"
|
type: "volume", // "volume" or "directory"
|
||||||
directory: "./homebox-data",
|
directory: "./homebox-data",
|
||||||
volumeName: "homebox-data",
|
volumeName: "homebox-data",
|
||||||
|
path: "/data", // Custom path for local storage
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// S3 storage settings
|
||||||
|
s3: {
|
||||||
|
bucket: "",
|
||||||
|
region: "",
|
||||||
|
endpoint: "", // For S3-compatible storage
|
||||||
|
awsAccessKeyId: "",
|
||||||
|
awsSecretAccessKey: "",
|
||||||
|
awsSessionToken: "", // Optional for temporary credentials
|
||||||
|
prefixPath: "", // Storage prefix path
|
||||||
|
awsSdk: "v2", // AWS SDK version
|
||||||
|
disableSSL: false,
|
||||||
|
s3ForcePathStyle: false,
|
||||||
|
sseType: "", // Server-side encryption type
|
||||||
|
kmsKeyId: "", // KMS key ID for encryption
|
||||||
|
fips: false,
|
||||||
|
dualstack: false,
|
||||||
|
accelerate: false,
|
||||||
|
isCompatible: false, // Whether using S3-compatible storage
|
||||||
|
compatibleService: "", // minio, cloudflare-r2, backblaze-b2, custom
|
||||||
|
},
|
||||||
|
|
||||||
|
// Google Cloud Storage settings
|
||||||
|
gcs: {
|
||||||
|
bucket: "",
|
||||||
|
projectId: "",
|
||||||
|
credentialsPath: "/app/gcs-credentials.json", // Path to service account key
|
||||||
|
prefixPath: "", // Storage prefix path
|
||||||
|
},
|
||||||
|
|
||||||
|
// Azure Blob Storage settings
|
||||||
|
azure: {
|
||||||
|
container: "",
|
||||||
|
storageAccount: "",
|
||||||
|
storageKey: "",
|
||||||
|
sasToken: "", // Optional SAS token
|
||||||
|
useEmulator: false,
|
||||||
|
emulatorEndpoint: "localhost:10001", // For local emulator
|
||||||
|
prefixPath: "", // Storage prefix path
|
||||||
|
},
|
||||||
|
|
||||||
|
// Container storage volumes (for non-local storage types)
|
||||||
|
containerStorage: {
|
||||||
postgresStorage: {
|
postgresStorage: {
|
||||||
type: "volume",
|
type: "volume",
|
||||||
directory: "./postgres-data",
|
directory: "./postgres-data",
|
||||||
@@ -160,6 +208,7 @@ const config = reactive({
|
|||||||
volumeName: "cloudflared-data",
|
volumeName: "cloudflared-data",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
function regeneratePassword() {
|
function regeneratePassword() {
|
||||||
|
|||||||
@@ -1,76 +1,552 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="tab-content">
|
<div class="storage-config">
|
||||||
<div class="card">
|
<h3>Storage Configuration</h3>
|
||||||
<div class="card-header">
|
|
||||||
<h2 class="card-title">Storage Configuration</h2>
|
<!-- Storage Type Selector -->
|
||||||
<p class="card-description">Configure storage options for your Homebox instance and related services.</p>
|
<div class="form-group">
|
||||||
|
<label for="storageType">Storage Type</label>
|
||||||
|
<select id="storageType" v-model="config.storageType" class="form-input">
|
||||||
|
<option value="local">Local Storage</option>
|
||||||
|
<option value="s3">Amazon S3 / S3-Compatible</option>
|
||||||
|
<option value="gcs">Google Cloud Storage</option>
|
||||||
|
<option value="azure">Azure Blob Storage</option>
|
||||||
|
</select>
|
||||||
|
<p class="form-help">Choose where Homebox will store your data</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-content">
|
|
||||||
<!-- Homebox Storage -->
|
|
||||||
<StorageTypeSelector
|
|
||||||
storage-key="homeboxStorage"
|
|
||||||
label="Homebox Data Storage"
|
|
||||||
description="Store Homebox data in a Docker volume or host directory"
|
|
||||||
:config="config"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<!-- PostgreSQL Storage -->
|
<!-- Local Storage Configuration -->
|
||||||
<StorageTypeSelector
|
<div v-if="config.storageType === 'local'" class="storage-section">
|
||||||
v-if="config.databaseType === 'postgres'"
|
<h4>Local Storage Settings</h4>
|
||||||
storage-key="postgresStorage"
|
|
||||||
label="PostgreSQL Data Storage"
|
|
||||||
description="Store PostgreSQL data in a Docker volume or host directory"
|
|
||||||
:config="config"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<!-- HTTPS Service Storage -->
|
<div class="form-group">
|
||||||
<StorageTypeSelector
|
<label for="localType">Storage Type</label>
|
||||||
v-if="config.httpsOption === 'traefik'"
|
<select id="localType" v-model="config.storageConfig.local.type" class="form-input">
|
||||||
storage-key="traefikStorage"
|
<option value="volume">Docker Volume</option>
|
||||||
label="Traefik Data Storage"
|
<option value="directory">Host Directory</option>
|
||||||
description="Store Traefik certificates in a Docker volume or host directory"
|
</select>
|
||||||
:config="config"
|
</div>
|
||||||
/>
|
|
||||||
|
|
||||||
<StorageTypeSelector
|
<div v-if="config.storageConfig.local.type === 'directory'" class="form-group">
|
||||||
v-if="config.httpsOption === 'nginx'"
|
<label for="localDirectory">Host Directory Path</label>
|
||||||
storage-key="nginxStorage"
|
<input
|
||||||
label="Nginx Data Storage"
|
id="localDirectory"
|
||||||
description="Store Nginx configuration and certificates in a Docker volume or host directory"
|
v-model="config.storageConfig.local.directory"
|
||||||
:config="config"
|
type="text"
|
||||||
|
class="form-input"
|
||||||
|
placeholder="./homebox-data"
|
||||||
/>
|
/>
|
||||||
|
<p class="form-help">Path on the host system where data will be stored</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<StorageTypeSelector
|
<div v-if="config.storageConfig.local.type === 'volume'" class="form-group">
|
||||||
v-if="config.httpsOption === 'caddy'"
|
<label for="localVolume">Volume Name</label>
|
||||||
storage-key="caddyStorage"
|
<input
|
||||||
label="Caddy Data Storage"
|
id="localVolume"
|
||||||
description="Store Caddy configuration and certificates in a Docker volume or host directory"
|
v-model="config.storageConfig.local.volumeName"
|
||||||
:config="config"
|
type="text"
|
||||||
|
class="form-input"
|
||||||
|
placeholder="homebox-data"
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<StorageTypeSelector
|
<div class="form-group">
|
||||||
v-if="config.httpsOption === 'cloudflared'"
|
<label for="localPath">Custom Storage Path (Optional)</label>
|
||||||
storage-key="cloudflaredStorage"
|
<input
|
||||||
label="Cloudflared Data Storage"
|
id="localPath"
|
||||||
description="Store Cloudflared configuration in a Docker volume or host directory"
|
v-model="config.storageConfig.local.path"
|
||||||
:config="config"
|
type="text"
|
||||||
|
class="form-input"
|
||||||
|
placeholder="/data"
|
||||||
/>
|
/>
|
||||||
|
<p class="form-help">Custom path inside the container. Leave as /data for default.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- S3 Storage Configuration -->
|
||||||
|
<div v-if="config.storageType === 's3'" class="storage-section">
|
||||||
|
<h4>S3 Storage Settings</h4>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
v-model="config.storageConfig.s3.isCompatible"
|
||||||
|
class="form-checkbox"
|
||||||
|
/>
|
||||||
|
Use S3-Compatible Storage (MinIO, Cloudflare R2, Backblaze B2, etc.)
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="config.storageConfig.s3.isCompatible" class="form-group">
|
||||||
|
<label for="s3Service">S3-Compatible Service</label>
|
||||||
|
<select id="s3Service" v-model="config.storageConfig.s3.compatibleService" class="form-input">
|
||||||
|
<option value="">Custom/Other</option>
|
||||||
|
<option value="minio">MinIO</option>
|
||||||
|
<option value="cloudflare-r2">Cloudflare R2</option>
|
||||||
|
<option value="backblaze-b2">Backblaze B2</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="s3Bucket">Bucket Name</label>
|
||||||
|
<input
|
||||||
|
id="s3Bucket"
|
||||||
|
v-model="config.storageConfig.s3.bucket"
|
||||||
|
type="text"
|
||||||
|
class="form-input"
|
||||||
|
placeholder="my-homebox-bucket"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="!config.storageConfig.s3.isCompatible" class="form-group">
|
||||||
|
<label for="s3Region">AWS Region</label>
|
||||||
|
<input
|
||||||
|
id="s3Region"
|
||||||
|
v-model="config.storageConfig.s3.region"
|
||||||
|
type="text"
|
||||||
|
class="form-input"
|
||||||
|
placeholder="us-east-1"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="config.storageConfig.s3.isCompatible" class="form-group">
|
||||||
|
<label for="s3Endpoint">Endpoint URL</label>
|
||||||
|
<input
|
||||||
|
id="s3Endpoint"
|
||||||
|
v-model="config.storageConfig.s3.endpoint"
|
||||||
|
type="text"
|
||||||
|
class="form-input"
|
||||||
|
:placeholder="getS3EndpointPlaceholder()"
|
||||||
|
/>
|
||||||
|
<p class="form-help">The endpoint URL for your S3-compatible service</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="s3AccessKey">AWS Access Key ID</label>
|
||||||
|
<input
|
||||||
|
id="s3AccessKey"
|
||||||
|
v-model="config.storageConfig.s3.awsAccessKeyId"
|
||||||
|
type="text"
|
||||||
|
class="form-input"
|
||||||
|
placeholder="AKIAIOSFODNN7EXAMPLE"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="s3SecretKey">AWS Secret Access Key</label>
|
||||||
|
<input
|
||||||
|
id="s3SecretKey"
|
||||||
|
v-model="config.storageConfig.s3.awsSecretAccessKey"
|
||||||
|
type="password"
|
||||||
|
class="form-input"
|
||||||
|
placeholder="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="s3SessionToken">AWS Session Token (Optional)</label>
|
||||||
|
<input
|
||||||
|
id="s3SessionToken"
|
||||||
|
v-model="config.storageConfig.s3.awsSessionToken"
|
||||||
|
type="password"
|
||||||
|
class="form-input"
|
||||||
|
placeholder="For temporary credentials"
|
||||||
|
/>
|
||||||
|
<p class="form-help">Only needed for temporary AWS credentials</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="s3PrefixPath">Storage Prefix Path (Optional)</label>
|
||||||
|
<input
|
||||||
|
id="s3PrefixPath"
|
||||||
|
v-model="config.storageConfig.s3.prefixPath"
|
||||||
|
type="text"
|
||||||
|
class="form-input"
|
||||||
|
placeholder="homebox/"
|
||||||
|
/>
|
||||||
|
<p class="form-help">Prefix for all stored objects in the bucket</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Advanced S3 Settings -->
|
||||||
|
<details class="advanced-settings">
|
||||||
|
<summary>Advanced S3 Settings</summary>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="s3AwsSdk">AWS SDK Version</label>
|
||||||
|
<select id="s3AwsSdk" v-model="config.storageConfig.s3.awsSdk" class="form-input">
|
||||||
|
<option value="v2">v2 (Recommended)</option>
|
||||||
|
<option value="v1">v1</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
v-model="config.storageConfig.s3.disableSSL"
|
||||||
|
class="form-checkbox"
|
||||||
|
/>
|
||||||
|
Disable SSL
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
v-model="config.storageConfig.s3.s3ForcePathStyle"
|
||||||
|
class="form-checkbox"
|
||||||
|
/>
|
||||||
|
Force Path Style Access
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="s3SseType">Server-Side Encryption</label>
|
||||||
|
<select id="s3SseType" v-model="config.storageConfig.s3.sseType" class="form-input">
|
||||||
|
<option value="">None</option>
|
||||||
|
<option value="AES256">AES256</option>
|
||||||
|
<option value="aws:kms">AWS KMS</option>
|
||||||
|
<option value="aws:kms:dsse">AWS KMS DSSE</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="config.storageConfig.s3.sseType.includes('kms')" class="form-group">
|
||||||
|
<label for="s3KmsKey">KMS Key ID</label>
|
||||||
|
<input
|
||||||
|
id="s3KmsKey"
|
||||||
|
v-model="config.storageConfig.s3.kmsKeyId"
|
||||||
|
type="text"
|
||||||
|
class="form-input"
|
||||||
|
placeholder="arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
v-model="config.storageConfig.s3.fips"
|
||||||
|
class="form-checkbox"
|
||||||
|
/>
|
||||||
|
Use FIPS Endpoints
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
v-model="config.storageConfig.s3.dualstack"
|
||||||
|
class="form-checkbox"
|
||||||
|
/>
|
||||||
|
Use Dual-Stack Endpoints
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
v-model="config.storageConfig.s3.accelerate"
|
||||||
|
class="form-checkbox"
|
||||||
|
/>
|
||||||
|
Use S3 Transfer Acceleration
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Google Cloud Storage Configuration -->
|
||||||
|
<div v-if="config.storageType === 'gcs'" class="storage-section">
|
||||||
|
<h4>Google Cloud Storage Settings</h4>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="gcsBucket">Bucket Name</label>
|
||||||
|
<input
|
||||||
|
id="gcsBucket"
|
||||||
|
v-model="config.storageConfig.gcs.bucket"
|
||||||
|
type="text"
|
||||||
|
class="form-input"
|
||||||
|
placeholder="my-homebox-bucket"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="gcsProject">Project ID</label>
|
||||||
|
<input
|
||||||
|
id="gcsProject"
|
||||||
|
v-model="config.storageConfig.gcs.projectId"
|
||||||
|
type="text"
|
||||||
|
class="form-input"
|
||||||
|
placeholder="my-gcp-project"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="gcsCredentialsPath">Service Account Key Path</label>
|
||||||
|
<input
|
||||||
|
id="gcsCredentialsPath"
|
||||||
|
v-model="config.storageConfig.gcs.credentialsPath"
|
||||||
|
type="text"
|
||||||
|
class="form-input"
|
||||||
|
placeholder="/app/gcs-credentials.json"
|
||||||
|
/>
|
||||||
|
<p class="form-help">Path to the service account JSON key file inside the container</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="gcsPrefixPath">Storage Prefix Path (Optional)</label>
|
||||||
|
<input
|
||||||
|
id="gcsPrefixPath"
|
||||||
|
v-model="config.storageConfig.gcs.prefixPath"
|
||||||
|
type="text"
|
||||||
|
class="form-input"
|
||||||
|
placeholder="homebox/"
|
||||||
|
/>
|
||||||
|
<p class="form-help">Prefix for all stored objects in the bucket</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="info-box">
|
||||||
|
<h5>📋 Setup Instructions:</h5>
|
||||||
|
<ol>
|
||||||
|
<li>Create a service account in your GCP project</li>
|
||||||
|
<li>Grant Storage Admin permissions to the service account</li>
|
||||||
|
<li>Download the JSON key file</li>
|
||||||
|
<li>Mount the key file as a read-only volume in your container</li>
|
||||||
|
<li>Set GOOGLE_APPLICATION_CREDENTIALS environment variable</li>
|
||||||
|
</ol>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Azure Blob Storage Configuration -->
|
||||||
|
<div v-if="config.storageType === 'azure'" class="storage-section">
|
||||||
|
<h4>Azure Blob Storage Settings</h4>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
v-model="config.storageConfig.azure.useEmulator"
|
||||||
|
class="form-checkbox"
|
||||||
|
/>
|
||||||
|
Use Azure Storage Emulator (for development)
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="azureContainer">Container Name</label>
|
||||||
|
<input
|
||||||
|
id="azureContainer"
|
||||||
|
v-model="config.storageConfig.azure.container"
|
||||||
|
type="text"
|
||||||
|
class="form-input"
|
||||||
|
placeholder="homebox-container"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="!config.storageConfig.azure.useEmulator" class="form-group">
|
||||||
|
<label for="azureAccount">Storage Account Name</label>
|
||||||
|
<input
|
||||||
|
id="azureAccount"
|
||||||
|
v-model="config.storageConfig.azure.storageAccount"
|
||||||
|
type="text"
|
||||||
|
class="form-input"
|
||||||
|
placeholder="mystorageaccount"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="!config.storageConfig.azure.useEmulator" class="form-group">
|
||||||
|
<label for="azureKey">Storage Account Key</label>
|
||||||
|
<input
|
||||||
|
id="azureKey"
|
||||||
|
v-model="config.storageConfig.azure.storageKey"
|
||||||
|
type="password"
|
||||||
|
class="form-input"
|
||||||
|
placeholder="Your Azure storage account key"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="!config.storageConfig.azure.useEmulator" class="form-group">
|
||||||
|
<label for="azureSas">SAS Token (Optional)</label>
|
||||||
|
<input
|
||||||
|
id="azureSas"
|
||||||
|
v-model="config.storageConfig.azure.sasToken"
|
||||||
|
type="password"
|
||||||
|
class="form-input"
|
||||||
|
placeholder="?sv=2021-06-08&ss=b&srt=sco&sp=rwdlacupx&se=..."
|
||||||
|
/>
|
||||||
|
<p class="form-help">Use SAS token instead of storage account key</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="config.storageConfig.azure.useEmulator" class="form-group">
|
||||||
|
<label for="azureEmulatorEndpoint">Emulator Endpoint</label>
|
||||||
|
<input
|
||||||
|
id="azureEmulatorEndpoint"
|
||||||
|
v-model="config.storageConfig.azure.emulatorEndpoint"
|
||||||
|
type="text"
|
||||||
|
class="form-input"
|
||||||
|
placeholder="localhost:10001"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="azurePrefixPath">Storage Prefix Path (Optional)</label>
|
||||||
|
<input
|
||||||
|
id="azurePrefixPath"
|
||||||
|
v-model="config.storageConfig.azure.prefixPath"
|
||||||
|
type="text"
|
||||||
|
class="form-input"
|
||||||
|
placeholder="homebox/"
|
||||||
|
/>
|
||||||
|
<p class="form-help">Prefix for all stored objects in the container</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import StorageTypeSelector from './StorageTypeSelector.vue'
|
import { defineProps } from 'vue'
|
||||||
|
|
||||||
defineProps({
|
const props = defineProps({
|
||||||
config: {
|
config: {
|
||||||
type: Object,
|
type: Object,
|
||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function getS3EndpointPlaceholder() {
|
||||||
|
const service = props.config.storageConfig.s3.compatibleService
|
||||||
|
switch (service) {
|
||||||
|
case 'minio':
|
||||||
|
return 'http://minio:9000'
|
||||||
|
case 'cloudflare-r2':
|
||||||
|
return 'https://<account-id>.r2.cloudflarestorage.com'
|
||||||
|
case 'backblaze-b2':
|
||||||
|
return 'https://s3.us-west-004.backblazeb2.com'
|
||||||
|
default:
|
||||||
|
return 'https://your-s3-compatible-endpoint.com'
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@import './common.css';
|
.storage-config {
|
||||||
|
padding: 1.5rem;
|
||||||
|
background-color: var(--vp-c-bg-soft);
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.storage-section {
|
||||||
|
margin-top: 1.5rem;
|
||||||
|
padding: 1rem;
|
||||||
|
background-color: var(--vp-c-bg);
|
||||||
|
border-radius: 6px;
|
||||||
|
border: 1px solid var(--vp-c-divider);
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group {
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 0.25rem;
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--vp-c-text-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-input {
|
||||||
|
width: 100%;
|
||||||
|
padding: 0.5rem;
|
||||||
|
border: 1px solid var(--vp-c-divider);
|
||||||
|
border-radius: 4px;
|
||||||
|
background-color: var(--vp-c-bg);
|
||||||
|
color: var(--vp-c-text-1);
|
||||||
|
font-size: 0.875rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-input:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: var(--vp-c-brand);
|
||||||
|
box-shadow: 0 0 0 2px var(--vp-c-brand-light);
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-checkbox {
|
||||||
|
width: auto;
|
||||||
|
margin-right: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-help {
|
||||||
|
margin-top: 0.25rem;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
color: var(--vp-c-text-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.advanced-settings {
|
||||||
|
margin-top: 1rem;
|
||||||
|
border: 1px solid var(--vp-c-divider);
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.advanced-settings summary {
|
||||||
|
padding: 0.75rem;
|
||||||
|
background-color: var(--vp-c-bg-mute);
|
||||||
|
cursor: pointer;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.advanced-settings[open] summary {
|
||||||
|
border-bottom: 1px solid var(--vp-c-divider);
|
||||||
|
}
|
||||||
|
|
||||||
|
.advanced-settings .form-group {
|
||||||
|
margin: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-box {
|
||||||
|
margin-top: 1rem;
|
||||||
|
padding: 1rem;
|
||||||
|
background-color: var(--vp-c-bg-alt);
|
||||||
|
border-left: 4px solid var(--vp-c-brand);
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-box h5 {
|
||||||
|
margin: 0 0 0.5rem 0;
|
||||||
|
color: var(--vp-c-text-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-box ol {
|
||||||
|
margin: 0;
|
||||||
|
padding-left: 1.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-box li {
|
||||||
|
margin-bottom: 0.25rem;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
color: var(--vp-c-text-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
margin: 0 0 1.5rem 0;
|
||||||
|
color: var(--vp-c-text-1);
|
||||||
|
font-size: 1.25rem;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
h4 {
|
||||||
|
margin: 0 0 1rem 0;
|
||||||
|
color: var(--vp-c-text-1);
|
||||||
|
font-size: 1.1rem;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -1,369 +1,440 @@
|
|||||||
import type { AppConfig, DockerServices } from "./types" // Assuming types are in a separate file
|
export function generateDockerCompose(config: any): string {
|
||||||
|
const services: any = {}
|
||||||
export function generateDockerCompose(config: AppConfig): string {
|
const volumes: any = {}
|
||||||
const services: DockerServices = {
|
const networks: any = {
|
||||||
homebox: {
|
homebox: {
|
||||||
image: config.rootless
|
driver: 'bridge'
|
||||||
? "ghcr.io/sysadminsmedia/homebox:latest-rootless"
|
}
|
||||||
: "ghcr.io/sysadminsmedia/homebox:latest",
|
}
|
||||||
container_name: "homebox",
|
|
||||||
restart: "always",
|
// Generate Homebox service
|
||||||
environment: [
|
services.homebox = generateHomeboxService(config)
|
||||||
|
|
||||||
|
// Add database service if PostgreSQL is selected
|
||||||
|
if (config.databaseType === 'postgres') {
|
||||||
|
services.postgres = generatePostgresService(config)
|
||||||
|
if (config.storageConfig.containerStorage.postgresStorage.type === 'volume') {
|
||||||
|
volumes[config.storageConfig.containerStorage.postgresStorage.volumeName] = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure homebox-data volume exists if SQLite is selected
|
||||||
|
if (config.databaseType === 'sqlite') {
|
||||||
|
volumes['homebox-data'] = null
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add reverse proxy services based on HTTPS option
|
||||||
|
switch (config.httpsOption) {
|
||||||
|
case 'traefik':
|
||||||
|
services.traefik = generateTraefikService(config)
|
||||||
|
if (config.storageConfig.containerStorage.traefikStorage.type === 'volume') {
|
||||||
|
volumes[config.storageConfig.containerStorage.traefikStorage.volumeName] = null
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 'nginx':
|
||||||
|
services.nginx = generateNginxService(config)
|
||||||
|
if (config.storageConfig.containerStorage.nginxStorage.type === 'volume') {
|
||||||
|
volumes[config.storageConfig.containerStorage.nginxStorage.volumeName] = null
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 'caddy':
|
||||||
|
services.caddy = generateCaddyService(config)
|
||||||
|
if (config.storageConfig.containerStorage.caddyStorage.type === 'volume') {
|
||||||
|
volumes[config.storageConfig.containerStorage.caddyStorage.volumeName] = null
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 'cloudflared':
|
||||||
|
services.cloudflared = generateCloudflaredService(config)
|
||||||
|
if (config.storageConfig.containerStorage.cloudflaredStorage.type === 'volume') {
|
||||||
|
volumes[config.storageConfig.containerStorage.cloudflaredStorage.volumeName] = null
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add Homebox storage volume only for local storage
|
||||||
|
if (config.storageType === 'local' && config.storageConfig.local.type === 'volume') {
|
||||||
|
volumes[config.storageConfig.local.volumeName] = null
|
||||||
|
}
|
||||||
|
|
||||||
|
const compose = {
|
||||||
|
version: '3.8',
|
||||||
|
services,
|
||||||
|
...(Object.keys(volumes).length > 0 && {volumes}),
|
||||||
|
networks
|
||||||
|
}
|
||||||
|
|
||||||
|
return `# Generated Homebox Docker Compose Config Generator 1.0 Beta
|
||||||
|
# Storage Type: ${config.storageType.toUpperCase()}
|
||||||
|
# Generated on: ${new Date().toISOString()}
|
||||||
|
${yaml.stringify(compose)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateHomeboxService(config: any): any {
|
||||||
|
const service: any = {
|
||||||
|
image: config.rootless ? config.image.replace(':latest', ':latest-rootless') : config.image,
|
||||||
|
container_name: 'homebox',
|
||||||
|
restart: 'unless-stopped',
|
||||||
|
environment: generateEnvironmentVariables(config),
|
||||||
|
networks: ['homebox']
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add ports for direct access (when no reverse proxy is used)
|
||||||
|
if (config.httpsOption === 'none') {
|
||||||
|
service.ports = [`${config.port}:7745`]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configure storage based on storage type
|
||||||
|
if (config.storageType === 'local') {
|
||||||
|
service.volumes = generateLocalStorageVolumes(config)
|
||||||
|
} else {
|
||||||
|
// For cloud storage, we might still need some local volumes for certain files
|
||||||
|
service.volumes = generateCloudStorageVolumes(config)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Always mount homebox-data at /data if SQLite is used
|
||||||
|
if (config.databaseType === 'sqlite') {
|
||||||
|
if (!service.volumes) service.volumes = []
|
||||||
|
// Only add if not already present
|
||||||
|
if (!service.volumes.some(v => v.startsWith('homebox-data:'))) {
|
||||||
|
service.volumes.push('homebox-data:/data')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return service
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateEnvironmentVariables(config: any): string[] {
|
||||||
|
const env: string[] = [
|
||||||
`HBOX_LOG_LEVEL=${config.logLevel}`,
|
`HBOX_LOG_LEVEL=${config.logLevel}`,
|
||||||
`HBOX_LOG_FORMAT=${config.logFormat}`,
|
`HBOX_LOG_FORMAT=${config.logFormat}`,
|
||||||
`HBOX_WEB_MAX_FILE_UPLOAD=${config.maxFileUpload}`,
|
`HBOX_MAX_UPLOAD_SIZE=${config.maxFileUpload}`,
|
||||||
`HBOX_OPTIONS_ALLOW_ANALYTICS=${config.allowAnalytics}`,
|
`HBOX_AUTO_INCREMENT_ASSET_ID=${config.autoIncrementAssetId}`,
|
||||||
`HBOX_OPTIONS_ALLOW_REGISTRATION=${config.allowRegistration}`,
|
`HBOX_WEB_PORT=7745`
|
||||||
`HBOX_OPTIONS_AUTO_INCREMENT_ASSET_ID=${config.autoIncrementAssetId}`,
|
]
|
||||||
`HBOX_OPTIONS_CHECK_GITHUB_RELEASE=${config.checkGithubRelease}`,
|
|
||||||
],
|
|
||||||
volumes: [],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure homebox volumes based on storage type
|
// Database configuration
|
||||||
if (config.storageConfig.homeboxStorage.type === "volume") {
|
if (config.databaseType === 'postgres') {
|
||||||
services.homebox.volumes.push(
|
env.push(
|
||||||
`${config.storageConfig.homeboxStorage.volumeName}:/data/`,
|
`HBOX_DATABASE_DRIVER=postgres`,
|
||||||
)
|
|
||||||
} else {
|
|
||||||
services.homebox.volumes.push(
|
|
||||||
`${config.storageConfig.homeboxStorage.directory}:/data/`,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure ports based on HTTPS option
|
|
||||||
if (config.httpsOption === "none") {
|
|
||||||
services.homebox.ports = [`${config.port}:7745`]
|
|
||||||
} else {
|
|
||||||
// For HTTPS options, the proxy will handle the ports
|
|
||||||
services.homebox.expose = ["7745"]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add database configuration if PostgreSQL is selected
|
|
||||||
if (config.databaseType === "postgres") {
|
|
||||||
// Ensure environment array exists before pushing
|
|
||||||
if (!services.homebox.environment) {
|
|
||||||
services.homebox.environment = []
|
|
||||||
}
|
|
||||||
services.homebox.environment.push(
|
|
||||||
"HBOX_DATABASE_DRIVER=postgres",
|
|
||||||
`HBOX_DATABASE_HOST=${config.postgresConfig.host}`,
|
`HBOX_DATABASE_HOST=${config.postgresConfig.host}`,
|
||||||
`HBOX_DATABASE_PORT=${config.postgresConfig.port}`,
|
`HBOX_DATABASE_PORT=${config.postgresConfig.port}`,
|
||||||
`HBOX_DATABASE_USERNAME=${config.postgresConfig.username}`,
|
`HBOX_DATABASE_NAME=${config.postgresConfig.database}`,
|
||||||
`HBOX_DATABASE_PASSWORD=${config.postgresConfig.password}`,
|
`HBOX_DATABASE_USER=${config.postgresConfig.username}`,
|
||||||
`HBOX_DATABASE_DATABASE=${config.postgresConfig.database}`,
|
`HBOX_DATABASE_PASS=${config.postgresConfig.password}`
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// Add PostgreSQL service
|
// Registration settings
|
||||||
services["postgres"] = {
|
if (!config.allowRegistration) {
|
||||||
image: "postgres:14",
|
env.push('HBOX_OPTIONS_ALLOW_REGISTRATION=false')
|
||||||
container_name: "homebox-postgres",
|
}
|
||||||
restart: "always",
|
|
||||||
|
// Analytics settings
|
||||||
|
if (!config.allowAnalytics) {
|
||||||
|
env.push('HBOX_OPTIONS_ALLOW_ANALYTICS=false')
|
||||||
|
}
|
||||||
|
|
||||||
|
// GitHub release check
|
||||||
|
if (!config.checkGithubRelease) {
|
||||||
|
env.push('HBOX_OPTIONS_CHECK_GITHUB_RELEASE=false')
|
||||||
|
}
|
||||||
|
|
||||||
|
// Storage configuration
|
||||||
|
env.push(...generateStorageEnvironmentVariables(config))
|
||||||
|
|
||||||
|
return env
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateStorageEnvironmentVariables(config: any): string[] {
|
||||||
|
const env: string[] = []
|
||||||
|
|
||||||
|
switch (config.storageType) {
|
||||||
|
case 'local':
|
||||||
|
const storagePath = config.storageConfig.local.path || '/data'
|
||||||
|
env.push(`HBOX_STORAGE_CONN_STRING=file://${storagePath}`)
|
||||||
|
if (config.storageConfig.local.prefixPath) {
|
||||||
|
env.push(`HBOX_STORAGE_PREFIX_PATH=${config.storageConfig.local.prefixPath}`)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
|
||||||
|
case 's3':
|
||||||
|
const s3Config = config.storageConfig.s3
|
||||||
|
let connectionString = `s3://${s3Config.bucket}?awssdk=${s3Config.awsSdk}`
|
||||||
|
|
||||||
|
if (s3Config.region && !s3Config.isCompatible) {
|
||||||
|
connectionString += `®ion=${s3Config.region}`
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s3Config.endpoint) {
|
||||||
|
connectionString += `&endpoint=${s3Config.endpoint}`
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s3Config.disableSSL) {
|
||||||
|
connectionString += '&disableSSL=true'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s3Config.s3ForcePathStyle) {
|
||||||
|
connectionString += '&s3ForcePathStyle=true'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s3Config.sseType) {
|
||||||
|
connectionString += `&sseType=${s3Config.sseType}`
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s3Config.kmsKeyId) {
|
||||||
|
connectionString += `&kmskeyid=${s3Config.kmsKeyId}`
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s3Config.fips) {
|
||||||
|
connectionString += '&fips=true'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s3Config.dualstack) {
|
||||||
|
connectionString += '&dualstack=true'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s3Config.accelerate) {
|
||||||
|
connectionString += '&accelerate=true'
|
||||||
|
}
|
||||||
|
|
||||||
|
env.push(`HBOX_STORAGE_CONN_STRING=${connectionString}`)
|
||||||
|
|
||||||
|
if (s3Config.prefixPath) {
|
||||||
|
env.push(`HBOX_STORAGE_PREFIX_PATH=${s3Config.prefixPath}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AWS credentials
|
||||||
|
env.push(`AWS_ACCESS_KEY_ID=${s3Config.awsAccessKeyId}`)
|
||||||
|
env.push(`AWS_SECRET_ACCESS_KEY=${s3Config.awsSecretAccessKey}`)
|
||||||
|
|
||||||
|
if (s3Config.awsSessionToken) {
|
||||||
|
env.push(`AWS_SESSION_TOKEN=${s3Config.awsSessionToken}`)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
|
||||||
|
case 'gcs':
|
||||||
|
const gcsConfig = config.storageConfig.gcs
|
||||||
|
env.push(`HBOX_STORAGE_CONN_STRING=gcs://${gcsConfig.bucket}`)
|
||||||
|
|
||||||
|
if (gcsConfig.prefixPath) {
|
||||||
|
env.push(`HBOX_STORAGE_PREFIX_PATH=${gcsConfig.prefixPath}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
env.push(`GOOGLE_APPLICATION_CREDENTIALS=${gcsConfig.credentialsPath}`)
|
||||||
|
break
|
||||||
|
|
||||||
|
case 'azure':
|
||||||
|
const azureConfig = config.storageConfig.azure
|
||||||
|
let azureConnectionString = `azblob://${azureConfig.container}`
|
||||||
|
|
||||||
|
if (azureConfig.useEmulator) {
|
||||||
|
azureConnectionString += `?protocol=http&domain=${azureConfig.emulatorEndpoint}`
|
||||||
|
}
|
||||||
|
|
||||||
|
env.push(`HBOX_STORAGE_CONN_STRING=${azureConnectionString}`)
|
||||||
|
|
||||||
|
if (azureConfig.prefixPath) {
|
||||||
|
env.push(`HBOX_STORAGE_PREFIX_PATH=${azureConfig.prefixPath}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!azureConfig.useEmulator) {
|
||||||
|
env.push(`AZURE_STORAGE_ACCOUNT=${azureConfig.storageAccount}`)
|
||||||
|
|
||||||
|
if (azureConfig.sasToken) {
|
||||||
|
env.push(`AZURE_STORAGE_SAS_TOKEN=${azureConfig.sasToken}`)
|
||||||
|
} else {
|
||||||
|
env.push(`AZURE_STORAGE_KEY=${azureConfig.storageKey}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
return env
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateLocalStorageVolumes(config: any): string[] {
|
||||||
|
const volumes: string[] = []
|
||||||
|
|
||||||
|
if (config.storageConfig.local.type === 'volume') {
|
||||||
|
const mountPath = config.storageConfig.local.path || '/data'
|
||||||
|
volumes.push(`${config.storageConfig.local.volumeName}:${mountPath}`)
|
||||||
|
} else {
|
||||||
|
const mountPath = config.storageConfig.local.path || '/data'
|
||||||
|
volumes.push(`${config.storageConfig.local.directory}:${mountPath}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return volumes
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateCloudStorageVolumes(config: any): string[] {
|
||||||
|
const volumes: string[] = []
|
||||||
|
|
||||||
|
// For cloud storage, we might still need local volumes for certain files like GCS credentials
|
||||||
|
if (config.storageType === 'gcs') {
|
||||||
|
volumes.push('/path/to/gcs-credentials.json:/app/gcs-credentials.json:ro')
|
||||||
|
}
|
||||||
|
|
||||||
|
return volumes
|
||||||
|
}
|
||||||
|
|
||||||
|
function generatePostgresService(config: any): any {
|
||||||
|
const service: any = {
|
||||||
|
image: 'postgres:17-alpine',
|
||||||
|
container_name: 'homebox_postgres',
|
||||||
|
restart: 'unless-stopped',
|
||||||
environment: [
|
environment: [
|
||||||
`POSTGRES_USER=${config.postgresConfig.username}`,
|
`POSTGRES_USER=${config.postgresConfig.username}`,
|
||||||
`POSTGRES_PASSWORD=${config.postgresConfig.password}`,
|
`POSTGRES_PASSWORD=${config.postgresConfig.password}`,
|
||||||
`POSTGRES_DB=${config.postgresConfig.database}`,
|
`POSTGRES_DB=${config.postgresConfig.database}`
|
||||||
],
|
],
|
||||||
volumes: [],
|
networks: ['homebox']
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure postgres volumes based on storage type
|
if (config.storageConfig.containerStorage.postgresStorage.type === 'volume') {
|
||||||
if (config.storageConfig.postgresStorage.type === "volume") {
|
service.volumes = [`${config.storageConfig.containerStorage.postgresStorage.volumeName}:/var/lib/postgresql/data`]
|
||||||
services.postgres.volumes.push(
|
|
||||||
`${config.storageConfig.postgresStorage.volumeName}:/var/lib/postgresql/data`,
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
services.postgres.volumes.push(
|
service.volumes = [`${config.storageConfig.containerStorage.postgresStorage.directory}:/var/lib/postgresql/data`]
|
||||||
`${config.storageConfig.postgresStorage.directory}:/var/lib/postgresql/data`,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add HTTPS configuration based on selected option
|
return service
|
||||||
switch (config.httpsOption) {
|
|
||||||
case "traefik":
|
|
||||||
addTraefikConfig(services, config)
|
|
||||||
break
|
|
||||||
case "nginx":
|
|
||||||
addNginxConfig(services, config)
|
|
||||||
break
|
|
||||||
case "caddy":
|
|
||||||
addCaddyConfig(services, config)
|
|
||||||
break
|
|
||||||
case "cloudflared":
|
|
||||||
addCloudflaredConfig(services, config)
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format the Docker Compose YAML
|
function generateTraefikService(config: any): any {
|
||||||
let dockerCompose = "# generated by homebox config generator v0.0.1\n\nservices:\n"
|
const service: any = {
|
||||||
|
image: 'traefik:v3.0',
|
||||||
// Add services
|
container_name: 'traefik',
|
||||||
Object.entries(services).forEach(([serviceName, serviceConfig]) => {
|
restart: 'unless-stopped',
|
||||||
dockerCompose += ` ${serviceName}:\n`
|
|
||||||
Object.entries(serviceConfig).forEach(([key, value]) => {
|
|
||||||
if (Array.isArray(value)) {
|
|
||||||
dockerCompose += ` ${key}:\n`
|
|
||||||
value.forEach((item: string) => {
|
|
||||||
// Added type assertion for item
|
|
||||||
dockerCompose += ` - ${item}\n`
|
|
||||||
})
|
|
||||||
} else if (value !== undefined) {
|
|
||||||
// Check for undefined before adding
|
|
||||||
dockerCompose += ` ${key}: ${value}\n`
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
// Add volumes section if needed
|
|
||||||
const volumeNames: string[] = []
|
|
||||||
|
|
||||||
// Only add volumes that are configured as Docker volumes, not directories
|
|
||||||
if (config.storageConfig.homeboxStorage.type === "volume") {
|
|
||||||
volumeNames.push(config.storageConfig.homeboxStorage.volumeName)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
config.databaseType === "postgres" &&
|
|
||||||
config.storageConfig.postgresStorage.type === "volume"
|
|
||||||
) {
|
|
||||||
volumeNames.push(config.storageConfig.postgresStorage.volumeName)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add HTTPS-related volumes
|
|
||||||
if (
|
|
||||||
config.httpsOption === "traefik" &&
|
|
||||||
config.storageConfig.traefikStorage.type === "volume"
|
|
||||||
) {
|
|
||||||
volumeNames.push(config.storageConfig.traefikStorage.volumeName)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
config.httpsOption === "nginx" &&
|
|
||||||
config.storageConfig.nginxStorage.type === "volume"
|
|
||||||
) {
|
|
||||||
volumeNames.push(config.storageConfig.nginxStorage.volumeName)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
config.httpsOption === "caddy" &&
|
|
||||||
config.storageConfig.caddyStorage.type === "volume"
|
|
||||||
) {
|
|
||||||
volumeNames.push(config.storageConfig.caddyStorage.volumeName)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
config.httpsOption === "cloudflared" &&
|
|
||||||
config.storageConfig.cloudflaredStorage.type === "volume"
|
|
||||||
) {
|
|
||||||
volumeNames.push(config.storageConfig.cloudflaredStorage.volumeName)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (volumeNames.length > 0) {
|
|
||||||
dockerCompose += "\nvolumes:\n"
|
|
||||||
volumeNames.forEach((volumeName: string) => {
|
|
||||||
dockerCompose += ` ${volumeName}:\n driver: local\n`
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return dockerCompose
|
|
||||||
}
|
|
||||||
|
|
||||||
function addTraefikConfig(services: DockerServices, config: AppConfig): void {
|
|
||||||
// Add Traefik labels to Homebox
|
|
||||||
services.homebox.labels = [
|
|
||||||
"traefik.enable=true",
|
|
||||||
`traefik.http.routers.homebox.rule=Host(\`${config.traefikConfig.domain}\`)`,
|
|
||||||
"traefik.http.routers.homebox.entrypoints=websecure",
|
|
||||||
"traefik.http.routers.homebox.tls.certresolver=letsencrypt",
|
|
||||||
"traefik.http.services.homebox.loadbalancer.server.port=7745",
|
|
||||||
]
|
|
||||||
|
|
||||||
// Add Traefik service
|
|
||||||
services["traefik"] = {
|
|
||||||
image: "traefik:v2.10",
|
|
||||||
container_name: "homebox-traefik",
|
|
||||||
restart: "always",
|
|
||||||
ports: ["80:80", "443:443"],
|
|
||||||
command: [
|
command: [
|
||||||
"--api.insecure=false",
|
'--api.dashboard=true',
|
||||||
"--providers.docker=true",
|
'--providers.docker=true',
|
||||||
"--providers.docker.exposedbydefault=false",
|
'--providers.docker.exposedbydefault=false',
|
||||||
"--entrypoints.web.address=:80",
|
'--entrypoints.web.address=:80',
|
||||||
"--entrypoints.web.http.redirections.entrypoint.to=websecure",
|
'--entrypoints.websecure.address=:443',
|
||||||
"--entrypoints.web.http.redirections.entrypoint.scheme=https",
|
'--certificatesresolvers.letsencrypt.acme.tlschallenge=true',
|
||||||
"--entrypoints.websecure.address=:443",
|
|
||||||
"--certificatesresolvers.letsencrypt.acme.tlschallenge=true",
|
|
||||||
`--certificatesresolvers.letsencrypt.acme.email=${config.traefikConfig.email}`,
|
`--certificatesresolvers.letsencrypt.acme.email=${config.traefikConfig.email}`,
|
||||||
"--certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json",
|
'--certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json'
|
||||||
],
|
],
|
||||||
volumes: ["/var/run/docker.sock:/var/run/docker.sock:ro"],
|
ports: ['80:80', '443:443'],
|
||||||
}
|
networks: ['homebox'],
|
||||||
|
labels: [
|
||||||
// Configure traefik volumes based on storage type
|
'traefik.enable=true',
|
||||||
if (config.storageConfig.traefikStorage.type === "volume") {
|
'traefik.http.routers.traefik.rule=Host(`traefik.${config.traefikConfig.domain}`)',
|
||||||
services.traefik.volumes.push(
|
'traefik.http.routers.traefik.entrypoints=websecure',
|
||||||
`${config.storageConfig.traefikStorage.volumeName}:/letsencrypt`,
|
'traefik.http.routers.traefik.tls.certresolver=letsencrypt',
|
||||||
)
|
'traefik.http.routers.traefik.service=api@internal'
|
||||||
} else {
|
|
||||||
services.traefik.volumes.push(
|
|
||||||
`${config.storageConfig.traefikStorage.directory}:/letsencrypt`,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function addNginxConfig(services: DockerServices, config: AppConfig): void {
|
|
||||||
// Add Nginx service
|
|
||||||
services["nginx"] = {
|
|
||||||
image: "nginx:latest",
|
|
||||||
container_name: "homebox-nginx",
|
|
||||||
restart: "always",
|
|
||||||
ports: [`${config.nginxConfig.port}:443`, "80:80"],
|
|
||||||
volumes: [],
|
|
||||||
depends_on: ["homebox"],
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure nginx volumes based on storage type
|
|
||||||
if (config.storageConfig.nginxStorage.type === "volume") {
|
|
||||||
services.nginx.volumes.push(
|
|
||||||
`${config.storageConfig.nginxStorage.volumeName}/conf.d:/etc/nginx/conf.d`,
|
|
||||||
)
|
|
||||||
services.nginx.volumes.push(
|
|
||||||
`${config.storageConfig.nginxStorage.volumeName}/ssl:/etc/nginx/ssl`,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
services.nginx.volumes.push(
|
|
||||||
`${config.storageConfig.nginxStorage.directory}/conf.d:/etc/nginx/conf.d`,
|
|
||||||
)
|
|
||||||
services.nginx.volumes.push(
|
|
||||||
`${config.storageConfig.nginxStorage.directory}/ssl:/etc/nginx/ssl`,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add default Nginx configuration path (assuming the file exists)
|
|
||||||
const nginxConfVolume =
|
|
||||||
config.storageConfig.nginxStorage.type === "volume"
|
|
||||||
? `${config.storageConfig.nginxStorage.volumeName}/conf.d/default.conf:/etc/nginx/conf.d/default.conf`
|
|
||||||
: `${config.storageConfig.nginxStorage.directory}/conf.d/default.conf:/etc/nginx/conf.d/default.conf`
|
|
||||||
|
|
||||||
services.nginx.volumes.push(nginxConfVolume)
|
|
||||||
|
|
||||||
// Add comments via environment variables (Docker Compose doesn't support comments directly in YAML this way)
|
|
||||||
services.nginx.environment = [
|
|
||||||
"# You need to create SSL certificates and place them in the SSL directory",
|
|
||||||
`# Certificate path: ${config.nginxConfig.sslCertPath}`,
|
|
||||||
`# Key path: ${config.nginxConfig.sslKeyPath}`,
|
|
||||||
"# Then create a default.conf file in the conf.d directory with the following content:",
|
|
||||||
"# server {",
|
|
||||||
"# listen 80;",
|
|
||||||
`# server_name ${config.nginxConfig.domain};`,
|
|
||||||
"# return 301 https://$host$request_uri;",
|
|
||||||
"# }",
|
|
||||||
"# server {",
|
|
||||||
"# listen 443 ssl;",
|
|
||||||
`# server_name ${config.nginxConfig.domain};`,
|
|
||||||
`# ssl_certificate ${config.nginxConfig.sslCertPath};`,
|
|
||||||
`# ssl_certificate_key ${config.nginxConfig.sslKeyPath};`,
|
|
||||||
"# location / {",
|
|
||||||
"# proxy_pass http://homebox:7745;",
|
|
||||||
"# proxy_set_header Host $host;",
|
|
||||||
"# proxy_set_header X-Real-IP $remote_addr;",
|
|
||||||
"# }",
|
|
||||||
"# }",
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
function addCaddyConfig(services: DockerServices, config: AppConfig): void {
|
if (config.storageConfig.containerStorage.traefikStorage.type === 'volume') {
|
||||||
// Add Caddy service
|
service.volumes = [
|
||||||
services["caddy"] = {
|
'/var/run/docker.sock:/var/run/docker.sock:ro',
|
||||||
image: "caddy:latest",
|
`${config.storageConfig.containerStorage.traefikStorage.volumeName}:/letsencrypt`
|
||||||
container_name: "homebox-caddy",
|
|
||||||
restart: "always",
|
|
||||||
ports: ["80:80", "443:443"],
|
|
||||||
volumes: [],
|
|
||||||
depends_on: ["homebox"],
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure caddy volumes based on storage type
|
|
||||||
if (config.storageConfig.caddyStorage.type === "volume") {
|
|
||||||
services.caddy.volumes.push(
|
|
||||||
`${config.storageConfig.caddyStorage.volumeName}/data:/data`,
|
|
||||||
)
|
|
||||||
services.caddy.volumes.push(
|
|
||||||
`${config.storageConfig.caddyStorage.volumeName}/config:/config`,
|
|
||||||
)
|
|
||||||
services.caddy.volumes.push(
|
|
||||||
`${config.storageConfig.caddyStorage.volumeName}/Caddyfile:/etc/caddy/Caddyfile`,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
services.caddy.volumes.push(
|
|
||||||
`${config.storageConfig.caddyStorage.directory}/data:/data`,
|
|
||||||
)
|
|
||||||
services.caddy.volumes.push(
|
|
||||||
`${config.storageConfig.caddyStorage.directory}/config:/config`,
|
|
||||||
)
|
|
||||||
services.caddy.volumes.push(
|
|
||||||
`${config.storageConfig.caddyStorage.directory}/Caddyfile:/etc/caddy/Caddyfile`,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add environment variables for Caddy comments and potential ACME config
|
|
||||||
services.caddy.environment = [
|
|
||||||
`# Create a Caddyfile in ${config.storageConfig.caddyStorage.type === "volume" ? config.storageConfig.caddyStorage.volumeName : config.storageConfig.caddyStorage.directory} with the following content:`,
|
|
||||||
`# ${config.caddyConfig.domain} {`,
|
|
||||||
"# reverse_proxy homebox:7745",
|
|
||||||
"# }",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
// Add email if provided for ACME
|
|
||||||
if (config.caddyConfig.email) {
|
|
||||||
// Ensure environment array exists
|
|
||||||
if (!services.caddy.environment) {
|
|
||||||
services.caddy.environment = []
|
|
||||||
}
|
|
||||||
services.caddy.environment.push(`ACME_AGREE=true`) // Note: Caddy v2 doesn't use ACME_AGREE env var, email is set in Caddyfile
|
|
||||||
services.caddy.environment.push(`EMAIL=${config.caddyConfig.email}`) // This might be useful for scripting but Caddy reads email from Caddyfile
|
|
||||||
services.caddy.environment.push(
|
|
||||||
`# Add 'email ${config.caddyConfig.email}' to your Caddyfile for automatic HTTPS`,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function addCloudflaredConfig(
|
|
||||||
services: DockerServices,
|
|
||||||
config: AppConfig,
|
|
||||||
): void {
|
|
||||||
// Add Cloudflared service
|
|
||||||
services["cloudflared"] = {
|
|
||||||
image: "cloudflare/cloudflared:latest",
|
|
||||||
container_name: "homebox-cloudflared",
|
|
||||||
restart: "always",
|
|
||||||
command: ["tunnel", "--no-autoupdate", "run"],
|
|
||||||
volumes: [],
|
|
||||||
environment: [`TUNNEL_TOKEN=${config.cloudflaredConfig.token}`],
|
|
||||||
depends_on: ["homebox"],
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure cloudflared volumes based on storage type
|
|
||||||
if (config.storageConfig.cloudflaredStorage.type === "volume") {
|
|
||||||
services.cloudflared.volumes.push(
|
|
||||||
`${config.storageConfig.cloudflaredStorage.volumeName}:/etc/cloudflared`,
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
services.cloudflared.volumes.push(
|
service.volumes = [
|
||||||
`${config.storageConfig.cloudflaredStorage.directory}:/etc/cloudflared`,
|
'/var/run/docker.sock:/var/run/docker.sock:ro',
|
||||||
)
|
`${config.storageConfig.containerStorage.traefikStorage.directory}:/letsencrypt`
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add comments via environment variables
|
return service
|
||||||
// Ensure environment array exists
|
}
|
||||||
if (!services.cloudflared.environment) {
|
|
||||||
services.cloudflared.environment = []
|
function generateNginxService(config: any): any {
|
||||||
|
// This would generate an Nginx service with SSL configuration
|
||||||
|
// Implementation would depend on specific Nginx configuration needs
|
||||||
|
return {
|
||||||
|
image: 'nginx:alpine',
|
||||||
|
container_name: 'nginx',
|
||||||
|
restart: 'unless-stopped',
|
||||||
|
ports: [`${config.nginxConfig.port}:443`, '80:80'],
|
||||||
|
networks: ['homebox']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateCaddyService(config: any): any {
|
||||||
|
return {
|
||||||
|
image: 'caddy:alpine',
|
||||||
|
container_name: 'caddy',
|
||||||
|
restart: 'unless-stopped',
|
||||||
|
ports: ['80:80', '443:443'],
|
||||||
|
networks: ['homebox']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateCloudflaredService(config: any): any {
|
||||||
|
return {
|
||||||
|
image: 'cloudflare/cloudflared:latest',
|
||||||
|
container_name: 'cloudflared',
|
||||||
|
restart: 'unless-stopped',
|
||||||
|
command: `tunnel --no-autoupdate run --token ${config.cloudflaredConfig.token}`,
|
||||||
|
networks: ['homebox']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simple YAML stringifier (basic implementation
|
||||||
|
|
||||||
|
const yaml = {
|
||||||
|
stringify(obj: any, indent = 0, parentKey = "", isTopLevel = true): string {
|
||||||
|
const spaces = ' '.repeat(indent)
|
||||||
|
const nextSpaces = ' '.repeat(indent + 1)
|
||||||
|
if (obj === null || obj === undefined) {
|
||||||
|
return 'null'
|
||||||
|
}
|
||||||
|
if (typeof obj === 'string') {
|
||||||
|
if (parentKey === 'environment') {
|
||||||
|
// Should not be used, handled by stringifyEnv
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
if (obj.includes(':') || obj.includes('#') || obj.includes('\n') || /^[0-9]/.test(obj) || obj.includes('${')) {
|
||||||
|
return `"${obj.replace(/"/g, '\\"')}"`
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
if (typeof obj === 'number' || typeof obj === 'boolean') {
|
||||||
|
return String(obj)
|
||||||
|
}
|
||||||
|
if (Array.isArray(obj)) {
|
||||||
|
if (obj.length === 0) return '[]'
|
||||||
|
if (parentKey === 'environment') {
|
||||||
|
return yaml.stringifyEnv(obj, indent)
|
||||||
|
}
|
||||||
|
// For arrays under object keys, indent dashes at the same level as the parent key's value (spaces)
|
||||||
|
return '\n' + obj.map(item => `${spaces}- ${this.stringify(item, indent + 1, '', false).replace(/^\s+/, '')}`).join('\n')
|
||||||
|
}
|
||||||
|
if (typeof obj === 'object') {
|
||||||
|
const keys = Object.keys(obj)
|
||||||
|
if (keys.length === 0) return '{}'
|
||||||
|
return (isTopLevel ? '' : '\n') + keys.map(key => {
|
||||||
|
const value = this.stringify(obj[key], indent + 1, key, false)
|
||||||
|
// If value is an array, ensure correct indentation
|
||||||
|
if (Array.isArray(obj[key])) {
|
||||||
|
// Place key at current indent, then array items at next indent
|
||||||
|
return `${isTopLevel ? '' : spaces}${key}:${value}`
|
||||||
|
}
|
||||||
|
if (value.startsWith('\n')) {
|
||||||
|
return `${isTopLevel ? '' : spaces}${key}:${value}`
|
||||||
|
}
|
||||||
|
return `${isTopLevel ? '' : spaces}${key}: ${value}`
|
||||||
|
}).join('\n')
|
||||||
|
}
|
||||||
|
return String(obj)
|
||||||
|
},
|
||||||
|
|
||||||
|
stringifyEnv(envArr: string[], indent = 0): string {
|
||||||
|
const spaces = ' '.repeat(indent)
|
||||||
|
return '\n' + envArr.map(env => {
|
||||||
|
const eqIdx = env.indexOf('=')
|
||||||
|
if (eqIdx !== -1) {
|
||||||
|
const key = env.slice(0, eqIdx + 1)
|
||||||
|
let value = env.slice(eqIdx + 1)
|
||||||
|
// Only quote the value if it contains special YAML characters
|
||||||
|
if (value.match(/[:#\n]|^\d|\${/)) {
|
||||||
|
value = `"${value.replace(/"/g, '\\"')}"`
|
||||||
|
}
|
||||||
|
return `${spaces}- ${key}${value}`
|
||||||
|
}
|
||||||
|
return `${spaces}- ${env}`
|
||||||
|
}).join('\n')
|
||||||
}
|
}
|
||||||
services.cloudflared.environment.push(
|
|
||||||
"# Create a tunnel in the Cloudflare Zero Trust dashboard",
|
|
||||||
`# Configure DNS for ${config.cloudflaredConfig.domain} to point to your tunnel`,
|
|
||||||
"# Add a public hostname in the tunnel configuration pointing to http://homebox:7745",
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
715
pnpm-lock.yaml
generated
715
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user