mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-07-17 16:37:43 +00:00
feat: webdav sync default settings in env variables of container
In the docker setup, allow admin to provide the default values for WebDAV settings in the "Sync" section of the "Settings" page, via setting some environment variables of the docker container. This could be used for single user instances to pre-fill those settings. The available environment variables are: - WEBDAV_BASE_URL=<base-url> - WEBDAV_USERNAME=<username> - WEBDAV_SYNC_FOLDER_PATH=<sync-folder-path> - SYNC_INTERVAL=<integer-in-minutes> - IS_COMPRESSION_ENABLED=<true-or-false> - IS_ENCRYPTION_ENABLED=<true-or-false> These configurations are provided as environment variables after the build process of the app, so they have to be loaded at runtime, instead of build process. This can be achieved by the following way: 1. The environment variables are loaded into the docker container. 2. The container starts with `docker-entrypoint.sh`. 3. `docker-entrypoint.sh` converts the variables into a JSON file placed at `assets/sync-config-default-override.json`. 4. `sync-config.service.ts` fetches `assets/sync-config-default-override.json` dynamically at runtime to override the default values from `default-global-config.const.ts`.
This commit is contained in:
parent
94b77b46d8
commit
ab3d2824a5
6 changed files with 86 additions and 13 deletions
12
Dockerfile
12
Dockerfile
|
|
@ -34,14 +34,22 @@ FROM --platform=$TARGETPLATFORM nginx:1-alpine
|
|||
# environmental variables
|
||||
ENV PORT=80
|
||||
|
||||
# install dependencies
|
||||
RUN apk update \
|
||||
&& apk add --no-cache jq=1.7.1-r0
|
||||
|
||||
# copy artifact build from the 'build environment'
|
||||
COPY --from=build /app/dist/browser /usr/share/nginx/html
|
||||
|
||||
# copy nginx config
|
||||
COPY ./nginx/default.conf.template /etc/nginx/templates/default.conf.template
|
||||
|
||||
# copy entrypoint script
|
||||
COPY ./docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
|
||||
|
||||
# expose port: defaults to 80
|
||||
EXPOSE $PORT
|
||||
|
||||
# run nginx
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
# run docker-entrypoint.sh
|
||||
WORKDIR /usr/share/nginx/html
|
||||
CMD ["docker-entrypoint.sh"]
|
||||
|
|
|
|||
|
|
@ -425,6 +425,10 @@ docker compose up -d
|
|||
|
||||
Additionally to accessing the web app from your browser at `http://localhost`, you can set up WebDAV synchronization with base url `http://localhost/webdav/`.
|
||||
|
||||
### Other configuration of docker container
|
||||
|
||||
You can provide the default values for WebDAV settings in the "Sync" section of the "Settings" page, via setting some environment variables of the docker container. This could be used for single user instances. Check out `docker-compose.yaml` in this repository for available environment variables.
|
||||
|
||||
## Custom themes (desktop only)
|
||||
|
||||
In addition to color coding your projects and tags and to the dark and light theme you can also load completely custom CSS to restyle everything. To load a custom theme you simply need to put them into a new file named `styles.css` directly in the [user data folder](#user-data-folder).
|
||||
|
|
|
|||
|
|
@ -4,10 +4,21 @@ services:
|
|||
ports:
|
||||
- 80:80
|
||||
environment:
|
||||
- WEBDAV_BACKEND=http://webdav # Optional
|
||||
# WebDAV backend served at `/webdav/` subdirectory (Optional)
|
||||
# Used with "webdav" container below
|
||||
- WEBDAV_BACKEND=http://webdav
|
||||
|
||||
# Optional: WebDAV backend server
|
||||
# (used with the WEBDAV_BACKEND environment variable)
|
||||
# Default values in "Sync" section in "Settings" page (Optional)
|
||||
# Useful for single user instances
|
||||
- WEBDAV_BASE_URL=<base-url>
|
||||
- WEBDAV_USERNAME=<username>
|
||||
- WEBDAV_SYNC_FOLDER_PATH=<sync-folder-path>
|
||||
- SYNC_INTERVAL=<integer-in-minutes>
|
||||
- IS_COMPRESSION_ENABLED=<true-or-false>
|
||||
- IS_ENCRYPTION_ENABLED=<true-or-false>
|
||||
|
||||
# WebDAV backend server (Optional)
|
||||
# Used with the WEBDAV_BACKEND environment variable
|
||||
webdav:
|
||||
image: hacdias/webdav:latest
|
||||
volumes:
|
||||
|
|
|
|||
34
docker-entrypoint.sh
Executable file
34
docker-entrypoint.sh
Executable file
|
|
@ -0,0 +1,34 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Generate ./assets/sync-config-default-override.json from environment variables
|
||||
JSON="{}"
|
||||
JSON_PATH=./assets/sync-config-default-override.json
|
||||
if [ -n "${WEBDAV_BASE_URL}" ]; then
|
||||
JSON=$(echo "$JSON" | jq ".webDav.baseUrl |= \"$WEBDAV_BASE_URL\"")
|
||||
fi
|
||||
if [ -n "${WEBDAV_USERNAME}" ]; then
|
||||
JSON=$(echo "$JSON" | jq ".webDav.userName |= \"$WEBDAV_USERNAME\"")
|
||||
fi
|
||||
if [ -n "${WEBDAV_SYNC_FOLDER_PATH}" ]; then
|
||||
JSON=$(echo "$JSON" | jq ".webDav.syncFolderPath |= \"$WEBDAV_SYNC_FOLDER_PATH\"")
|
||||
fi
|
||||
if [ "$JSON" != "{}" ]; then
|
||||
# Change syncProvider if previous variables are set
|
||||
JSON=$(echo "$JSON" | jq '.syncProvider |= "WebDAV"')
|
||||
fi
|
||||
if [ -n "${SYNC_INTERVAL}" ]; then
|
||||
JSON=$(echo "$JSON" | jq ".syncInterval |= $(expr $SYNC_INTERVAL \* 60000)")
|
||||
fi
|
||||
if [ -n "${IS_COMPRESSION_ENABLED}" ]; then
|
||||
JSON=$(echo "$JSON" | jq ".isCompressionEnabled |= $IS_COMPRESSION_ENABLED")
|
||||
fi
|
||||
if [ -n "${IS_ENCRYPTION_ENABLED}" ]; then
|
||||
JSON=$(echo "$JSON" | jq ".isEncryptionEnabled |= $IS_ENCRYPTION_ENABLED")
|
||||
fi
|
||||
if [ "$JSON" != "{}" ]; then
|
||||
# Write the resultant json
|
||||
echo "$JSON" >$JSON_PATH
|
||||
fi
|
||||
|
||||
# run nginx
|
||||
nginx -g "daemon off;"
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
import { inject, Injectable } from '@angular/core';
|
||||
import { PfapiService } from '../../pfapi/pfapi.service';
|
||||
import { GlobalConfigService } from '../../features/config/global-config.service';
|
||||
import { combineLatest, Observable } from 'rxjs';
|
||||
import { combineLatest, from, of, Observable } from 'rxjs';
|
||||
import { SyncConfig } from '../../features/config/global-config.model';
|
||||
import { map, tap } from 'rxjs/operators';
|
||||
import { switchMap, tap } from 'rxjs/operators';
|
||||
import { PrivateCfgByProviderId, SyncProviderId } from '../../pfapi/api';
|
||||
import { DEFAULT_GLOBAL_CONFIG } from '../../features/config/default-global-config.const';
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ export class SyncConfigService {
|
|||
this._globalConfigService.sync$,
|
||||
this._pfapiService.currentProviderPrivateCfg$,
|
||||
]).pipe(
|
||||
map(([syncCfg, currentProviderCfg]) => {
|
||||
switchMap(([syncCfg, currentProviderCfg]) => {
|
||||
// Base config with defaults
|
||||
const baseConfig = {
|
||||
...DEFAULT_GLOBAL_CONFIG.sync,
|
||||
|
|
@ -35,10 +35,23 @@ export class SyncConfigService {
|
|||
|
||||
// If no provider is active, return base config with empty encryption key
|
||||
if (!currentProviderCfg) {
|
||||
return {
|
||||
...baseConfig,
|
||||
encryptKey: '',
|
||||
};
|
||||
return from(
|
||||
fetch('/assets/sync-config-default-override.json')
|
||||
.then((res) => res.json())
|
||||
.then((defaultOverride) => {
|
||||
return {
|
||||
...baseConfig,
|
||||
...defaultOverride,
|
||||
encryptKey: '',
|
||||
};
|
||||
})
|
||||
.catch(() => {
|
||||
return {
|
||||
...baseConfig,
|
||||
encryptKey: '',
|
||||
};
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
const prop = PROP_MAP_TO_FORM[currentProviderCfg.providerId];
|
||||
|
|
@ -57,7 +70,7 @@ export class SyncConfigService {
|
|||
result[prop] = currentProviderCfg.privateCfg;
|
||||
}
|
||||
|
||||
return result;
|
||||
return of(result);
|
||||
}),
|
||||
tap((v) => console.log('syncSettingsForm$', v)),
|
||||
);
|
||||
|
|
|
|||
3
src/assets/sync-config-default-override.json
Normal file
3
src/assets/sync-config-default-override.json
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"_comment": "This JSON file will be regenerated by docker-entrypoint.sh based on environment variables in docker environment."
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue