Skip to content

Commit

Permalink
Optimize application.yml
Browse files Browse the repository at this point in the history
The background idea is to remove the amount of variables that need to be set. Many of them have sane defaults and others can be generalized when more general variables are set (e.g. FAF_DOMAIN).

Before: 3 application.ymls:
 main/default: only fixed values are set
 dev: rebinding variables with defaults mostly pointing to localhost
 prod: only rebinding variable names

 After:
 main/default: fixed values and rebinding variable names with prod defaults
 local: fixed values mostly pointing to localhost
  • Loading branch information
Brutus5000 committed Dec 16, 2021
1 parent e4aad44 commit 3f23007
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 105 deletions.
81 changes: 81 additions & 0 deletions configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
| Env variable | Default value | Optional if env is defined | Default value (local) |
| ---- | ---- | ---- | ---- |
| ACTIVATION_URL_FORMAT | `https://www.${FAF_DOMAIN}/account/activate?username=%s&token=%s` | `FAF_DOMAIN` | `http://localhost:8020/account/activate?username=%s&token=%s` |
| ANOPE_DATABASE_NAME | `faf-anope` | | |
| API_PORT | `8010` | | |
| API_PROFILE | `local` | | |
| AVATAR_ALLOWED_FILE_EXTENSIONS | `png` | | `png` |
| AVATAR_DOWNLOAD_URL_FORMAT | `https://content.${FAF_DOMAIN}/faf/avatars/%s` | `FAF_DOMAIN` | `https://content.test.faforever.com/faf/avatars/%s` |
| AVATAR_IMAGE_HEIGHT | `20` | | |
| AVATAR_IMAGE_WIDTH | `40` | | |
| AVATAR_MAX_SIZE_BYTES | `4096` | | |
| AVATAR_TARGET_DIRECTORY | `/content/avatars` | | `build/cache/avatars` |
| CHALLONGE_KEY | | | |
| CLAN_INVITE_LINK_EXPIRE_DURATION_MINUTES | `604800` | | |
| CLAN_WEBSITE_URL_FORMAT | `https://clans.${FAF_DOMAIN}/clan/%s` | `FAF_DOMAIN` | `http://clans.test.faforever.com/clan/%s` |
| CONTEXT_PATH | `/` | | |
| DATABASE_ADDRESS | | | `127.0.0.1` |
| DATABASE_NAME | | | `faf` |
| DATABASE_PASSWORD | | | `banana` |
| DATABASE_SCHEMA_VERSION | `122` | | |
| DATABASE_USERNAME | | | `faf-java-api` |
| EMAIL_FROM_ADDRESS | | | `[email protected]` |
| EMAIL_FROM_NAME | | | `FAForever` |
| EXE_UPLOAD_BETA_PATH | `/content/legacy-featured-mod-files/updates_fafbeta_files` | | `build/exe/beta` |
| EXE_UPLOAD_DEVELOP_PATH | `/content/legacy-featured-mod-files/updates_fafdevelop_files` | | `build/exe/develop` |
| FEATURED_MODS_TARGET_DIRECTORY | `/content/legacy-featured-mod-files` | | `build/cache/deployment` |
| FEATURED_MOD_URL_FORMAT | `https://content.${FAF_DOMAIN}/legacy-featured-mod-files/%s/%s` | `FAF_DOMAIN` | `https://content.test.faforever.com/faf/updaterNew/%s/%s` |
| FORGED_ALLIANCE_EXE_PATH | `/content/legacy-featured-mod-files/updates_faf_files/ForgedAlliance.exe` | | |
| GITHUB_ACCESS_TOKEN | `false` | | |
| GITHUB_DEPLOYMENT_ENVIRONMENT | `production` | | `development` |
| GITHUB_WEBHOOK_SECRET | `false` | | |
| GOG_GAMES_LIST_URL | `https://www.gog.com/u/%s/games/stats?sort=recent_playtime&order=desc&page=%d` | | |
| GOG_PROFILE_URL | `https://www.gog.com/u/%s` | | |
| GOG_TOKEN_FORMAT | `{{FAF:%s}}` | | |
| JWT_FAF_HYDRA_ISSUER | `https://hydra.${FAF_DOMAIN}/` | `FAF_DOMAIN` | `https://hydra.test.faforever.com/` |
| JWT_FAF_HYDRA_JWKS_URL | `https://hydra.${FAF_DOMAIN}/.well-known/jwks.json` | `FAF_DOMAIN` | `https://hydra.test.faforever.com/.well-known/jwks.json` |
| JWT_PRIVATE_KEY_PATH | `/pki/secret.key` | | `test-pki-private.key` |
| JWT_PUBLIC_KEY_PATH | `/pki/public.key` | | `test-pki-public.key` |
| LEAGUE_DATABASE_ADDRESS | `127.0.0.1` | | `127.0.0.1` |
| LEAGUE_DATABASE_NAME | `faf-league` | | `faf-league` |
| LEAGUE_DATABASE_PASSWORD | | | `banana` |
| LEAGUE_DATABASE_USERNAME | `faf-league-service` | | `faf-league-service` |
| LOG_FILE_DIRECTORY | | | |
| LOG_LEVEL | `info` | | |
| MAIL_HOST | `false` | | |
| MAIL_PASSWORD | `false` | | |
| MAIL_PORT | `false` | | |
| MAIL_USERNAME | `false` | | |
| MANAGEMENT_ADDRESS | | | |
| MANAGEMENT_PORT | `8011` | | |
| MAP_DOWNLOAD_URL_FORMAT | `https://content.${FAF_DOMAIN}/maps/%s` | `FAF_DOMAIN` | `https://content.test.faforever.com/maps/%s` |
| MAP_LARGE_PREVIEWS_URL_FORMAT | `https://content.${FAF_DOMAIN}/maps/previews/large/%s` | `FAF_DOMAIN` | `https://content.test.faforever.com/faf/maps/previews/large/%s` |
| MAP_PREVIEW_PATH_LARGE | `/content/maps/previews/large` | | `build/cache/map_previews/large` |
| MAP_PREVIEW_PATH_SMALL | `/content/maps/previews/small` | | `build/cache/map_previews/small` |
| MAP_SMALL_PREVIEWS_URL_FORMAT | `https://content.${FAF_DOMAIN}/maps/previews/small/%s` | `FAF_DOMAIN` | `https://content.test.faforever.com/faf/maps/previews/small/%s` |
| MAP_UPLOAD_PATH | `/content/maps` | | `build/cache/map/maps` |
| MAUTIC_ACCESS_TOKEN_URL | `false` | | |
| MAUTIC_BASE_URL | `false` | | |
| MAUTIC_CLIENT_ID | `false` | | |
| MAUTIC_CLIENT_SECRET | `false` | | |
| MOD_DOWNLOAD_URL_FORMAT | `https://content.${FAF_DOMAIN}/mods/%s` | `FAF_DOMAIN` | `https://content.test.faforever.com/faf/vault/mods/%s` |
| MOD_PREVIEW_URL_FORMAT | `https://content.${FAF_DOMAIN}/mods/%s` | `FAF_DOMAIN` | `https://content.test.faforever.com/faf/vault/mods/%s` |
| NODEBB_ADMIN_USERID | `1` | | |
| NODEBB_BASE_URL | `false` | | |
| NODEBB_MASTER_TOKEN | `false` | | |
| PASSWORD_RESET_EMAIL_BODY | `Reset email body for user {0} with reset link {1}` | | `Reset email body for user {0} with reset link {1}` |
| PASSWORD_RESET_EMAIL_SUBJECT | `FAF password reset` | | `FAF password reset` |
| PASSWORD_RESET_URL_FORMAT | `https://www.${FAF_DOMAIN}/account/password/confirmReset?username=%s&token=%s` | `FAF_DOMAIN` | `http://localhost:8020/account/password/confirmReset?username=%s&token=%s` |
| PID | `- ` | | |
| RECAPTCHA_ENABLED | `false` | | `false` |
| RECAPTCHA_SECRET | | | |
| REGISTRATION_EMAIL_BODY | `"Registration email body for user {0} with activation link {1}"` | | `"Registration email body for user {0} with activation link {1}"` |
| REGISTRATION_EMAIL_SUBJECT | `FAF user registration` | | `FAF user registration` |
| REPLAY_DOWNLOAD_URL_FORMAT | `https://replays.${FAF_DOMAIN}/%s` | `FAF_DOMAIN` | `https://content.test.faforever.com/replays/%s` |
| REPOSITORIES_DIRECTORY | `/repositories` | | `build/cache/repos` |
| STEAM_API_KEY | | | `banana` |
| STEAM_LINK_REDIRECT_URL_FORMAT | `https://api.${FAF_DOMAIN}/users/linkToSteam?token=%s` | `FAF_DOMAIN` | `http://localhost:8010/users/linkToSteam?token=%s` |
| STEAM_PASSWORD_RESET_REDIRECT_URL_FORMAT | `https://api.${FAF_DOMAIN}/users/requestPasswordResetViaSteam` | `FAF_DOMAIN` | `http://localhost:8010/users/requestPasswordResetViaSteam` |
| STEAM_REALM | `https://api.${FAF_DOMAIN}` | `FAF_DOMAIN` | `http://localhost` |
| TESTING_EXE_UPLOAD_KEY | | | `banana` |
| TUTORIAL_THUMBNAIL_URL_FORMAT | `https://content.${FAF_DOMAIN}/faf/tutorials/thumbs/%s` | `FAF_DOMAIN` | `https://content.test.faforever.com/faf/tutorials/thumbs/%s` |
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=snapshot
profile=dev
profile=local
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ public static class Avatar {
@Data
public static class FeaturedMod {
private String fileUrlFormat;
private String bireusUrlFormat;
}

@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ private short readModVersion(Path modPath) {
private void verifyVersion(int version, boolean allowOverride, String modName) {
if (!allowOverride) {
// Normally I'd create a proper query, but this is a hotfix and a protest against the DB-driven patcher
// Luckily, BiReUS is coming "soon".
OptionalInt existingVersion = featuredModService.getFiles(modName, version).stream()
.mapToInt(FeaturedModFile::getVersion)
.filter(value -> value == version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,22 @@ faf-api:
target-directory: ${MAP_UPLOAD_PATH:build/cache/map/maps}
directory-preview-path-small: ${MAP_PREVIEW_PATH_SMALL:build/cache/map_previews/small}
directory-preview-path-large: ${MAP_PREVIEW_PATH_LARGE:build/cache/map_previews/large}
small-previews-url-format: ${MAP_SMALL_PREVIEWS_URL_FORMAT:http://test.content.faforever.com/faf/vault/map_previews/small/%s}
large-previews-url-format: ${MAP_LARGE_PREVIEWS_URL_FORMAT:http://test.content.faforever.com/faf/vault/map_previews/large/%s}
download-url-format: ${MAP_DOWNLOAD_URL_FORMAT:http://test.content.faforever.com/faf/vault/maps/%s}
small-previews-url-format: ${MAP_SMALL_PREVIEWS_URL_FORMAT:https://content.test.faforever.com/faf/maps/previews/small/%s}
large-previews-url-format: ${MAP_LARGE_PREVIEWS_URL_FORMAT:https://content.test.faforever.com/faf/maps/previews/large/%s}
download-url-format: ${MAP_DOWNLOAD_URL_FORMAT:https://content.test.faforever.com/maps/%s}
mod:
download-url-format: ${MOD_DOWNLOAD_URL_FORMAT:http://test.content.faforever.com/faf/vault/mods/%s}
preview-url-format: ${MOD_PREVIEW_URL_FORMAT:http://test.content.faforever.com/faf/vault/mods/%s}
download-url-format: ${MOD_DOWNLOAD_URL_FORMAT:https://content.test.faforever.com/faf/vault/mods/%s}
preview-url-format: ${MOD_PREVIEW_URL_FORMAT:https://content.test.faforever.com/faf/vault/mods/%s}
replay:
download-url-format: ${REPLAY_DOWNLOAD_URL_FORMAT:http://content.test.faforever.com/replays/%s}
download-url-format: ${REPLAY_DOWNLOAD_URL_FORMAT:https://content.test.faforever.com/replays/%s}
tutorial:
thumbnail-url-format: ${TUTORIAL_THUMBNAIL_URL_FORMAT:http://content.test.faforever.com/faf/tutorials/thumbs/%s}
thumbnail-url-format: ${TUTORIAL_THUMBNAIL_URL_FORMAT:https://content.test.faforever.com/faf/tutorials/thumbs/%s}
avatar:
download-url-format: ${AVATAR_DOWNLOAD_URL_FORMAT:http://content.test.faforever.com/faf/avatars/%s}
download-url-format: ${AVATAR_DOWNLOAD_URL_FORMAT:https://content.test.faforever.com/faf/avatars/%s}
target-directory: ${AVATAR_TARGET_DIRECTORY:build/cache/avatars}
allowed-extensions: ${AVATAR_ALLOWED_FILE_EXTENSIONS:png}
featured-mod:
file-url-format: ${FEATURED_MOD_URL_FORMAT:http://content.test.faforever.com/faf/updaterNew/%s/%s}
bireus-url-format: ${FEATURED_MOD_BIREUS_URL_FORMAT:https://content.test.faforever.com/repositories/%s}
file-url-format: ${FEATURED_MOD_URL_FORMAT:https://content.test.faforever.com/faf/updaterNew/%s/%s}
git-hub:
deployment-environment: ${GITHUB_DEPLOYMENT_ENVIRONMENT:development}
deployment:
Expand Down
77 changes: 0 additions & 77 deletions src/main/resources/config/application-prod.yml

This file was deleted.

88 changes: 73 additions & 15 deletions src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,88 @@
faf-api:
version: #faf-api.version#
anope:
database-name: ${ANOPE_DATABASE_NAME:faf-anope}
avatar:
max-size-bytes: ${AVATAR_MAX_SIZE_BYTES:4096}
image-width: ${AVATAR_IMAGE_WIDTH:40}
image-height: ${AVATAR_IMAGE_HEIGHT:20}
clan:
invite-link-expire-duration-minutes: ${CLAN_INVITE_LINK_EXPIRE_DURATION_MINUTES:604800}
download-url-format: ${AVATAR_DOWNLOAD_URL_FORMAT:https://content.${FAF_DOMAIN}/faf/avatars/%s}
target-directory: ${AVATAR_TARGET_DIRECTORY:/content/avatars}
allowed-extensions: ${AVATAR_ALLOWED_FILE_EXTENSIONS:png}
challonge:
key: ${CHALLONGE_KEY:}
clan:
invite-link-expire-duration-minutes: ${CLAN_INVITE_LINK_EXPIRE_DURATION_MINUTES:604800}
website-url-format: ${CLAN_WEBSITE_URL_FORMAT:https://clans.${FAF_DOMAIN}/clan/%s}
database:
schema-version: ${DATABASE_SCHEMA_VERSION:122}
deployment:
forged-alliance-exe-path: ${FORGED_ALLIANCE_EXE_PATH:/content/legacy-featured-mod-files/updates_faf_files/ForgedAlliance.exe}
repositories-directory: ${REPOSITORIES_DIRECTORY:/repositories}
featured-mods-target-directory: ${FEATURED_MODS_TARGET_DIRECTORY:/content/legacy-featured-mod-files}
testing-exe-upload-key: ${TESTING_EXE_UPLOAD_KEY}
forged-alliance-beta-exe-path: ${EXE_UPLOAD_BETA_PATH:/content/legacy-featured-mod-files/updates_fafbeta_files}
forged-alliance-develop-exe-path: ${EXE_UPLOAD_DEVELOP_PATH:/content/legacy-featured-mod-files/updates_fafdevelop_files}
featured-mod:
file-url-format: ${FEATURED_MOD_URL_FORMAT:https://content.${FAF_DOMAIN}/legacy-featured-mod-files/%s/%s}
git-hub:
access-token: ${GITHUB_ACCESS_TOKEN:false}
webhook-secret: ${GITHUB_WEBHOOK_SECRET:false}
deployment-environment: ${GITHUB_DEPLOYMENT_ENVIRONMENT:production}
gog:
token-format: ${GOG_TOKEN_FORMAT:{{FAF:%s}}}
profile-page-url: ${GOG_PROFILE_URL:https://www.gog.com/u/%s}
games-list-url: ${GOG_GAMES_LIST_URL:https://www.gog.com/u/%s/games/stats?sort=recent_playtime&order=desc&page=%d}
jwt:
secretKeyPath: ${JWT_PRIVATE_KEY_PATH:/pki/secret.key}
publicKeyPath: ${JWT_PUBLIC_KEY_PATH:/pki/public.key}
fafHydraJwksUrl: ${JWT_FAF_HYDRA_JWKS_URL:https://hydra.${FAF_DOMAIN}/.well-known/jwks.json}
fafHydraIssuer: ${JWT_FAF_HYDRA_ISSUER:https://hydra.${FAF_DOMAIN}/}
mail:
from-email-name: ${EMAIL_FROM_NAME}
from-email-address: ${EMAIL_FROM_ADDRESS}
map:
target-directory: ${MAP_UPLOAD_PATH:/content/maps}
directory-preview-path-small: ${MAP_PREVIEW_PATH_SMALL:/content/maps/previews/small}
directory-preview-path-large: ${MAP_PREVIEW_PATH_LARGE:/content/maps/previews/large}
small-previews-url-format: ${MAP_SMALL_PREVIEWS_URL_FORMAT:https://content.${FAF_DOMAIN}/maps/previews/small/%s}
large-previews-url-format: ${MAP_LARGE_PREVIEWS_URL_FORMAT:https://content.${FAF_DOMAIN}/maps/previews/large/%s}
download-url-format: ${MAP_DOWNLOAD_URL_FORMAT:https://content.${FAF_DOMAIN}/maps/%s}
mautic:
base-url: ${MAUTIC_BASE_URL:false}
client-id: ${MAUTIC_CLIENT_ID:false}
client-secret: ${MAUTIC_CLIENT_SECRET:false}
access-token-url: ${MAUTIC_ACCESS_TOKEN_URL:false}
git-hub:
access-token: ${GITHUB_ACCESS_TOKEN:false}
webhook-secret: ${GITHUB_WEBHOOK_SECRET:false}
anope:
database-name: ${ANOPE_DATABASE_NAME:faf-anope}
rating:
default-mean: 1500
default-deviation: 500
mod:
download-url-format: ${MOD_DOWNLOAD_URL_FORMAT:https://content.${FAF_DOMAIN}/mods/%s}
preview-url-format: ${MOD_PREVIEW_URL_FORMAT:https://content.${FAF_DOMAIN}/mods/%s}
nodebb:
base-url: ${NODEBB_BASE_URL:false}
admin-user-id: ${NODEBB_ADMIN_USERID:1}
master-token: ${NODEBB_MASTER_TOKEN:false}
gog:
token-format: ${GOG_TOKEN_FORMAT:{{FAF:%s}}}
profile-page-url: ${GOG_PROFILE_URL:https://www.gog.com/u/%s}
games-list-url: ${GOG_GAMES_LIST_URL:https://www.gog.com/u/%s/games/stats?sort=recent_playtime&order=desc&page=%d}
password-reset:
password-reset-url-format: ${PASSWORD_RESET_URL_FORMAT:https://www.${FAF_DOMAIN}/account/password/confirmReset?username=%s&token=%s}
subject: ${PASSWORD_RESET_EMAIL_SUBJECT:FAF password reset}
html-format: ${PASSWORD_RESET_EMAIL_BODY:Reset email body for user {0} with reset link {1}}
rating:
default-mean: 1500
default-deviation: 500
recaptcha:
enabled: ${RECAPTCHA_ENABLED:false}
secret: ${RECAPTCHA_SECRET}
registration:
activation-url-format: ${ACTIVATION_URL_FORMAT:https://www.${FAF_DOMAIN}/account/activate?username=%s&token=%s}
subject: ${REGISTRATION_EMAIL_SUBJECT:FAF user registration}
html-format: ${REGISTRATION_EMAIL_BODY:"Registration email body for user {0} with activation link {1}"}
replay:
download-url-format: ${REPLAY_DOWNLOAD_URL_FORMAT:https://replays.${FAF_DOMAIN}/%s}
steam:
realm: ${STEAM_REALM:https://api.${FAF_DOMAIN}}
api-key: ${STEAM_API_KEY}
link-to-steam-redirect-url-format: ${STEAM_LINK_REDIRECT_URL_FORMAT:https://api.${FAF_DOMAIN}/users/linkToSteam?token=%s}
steam-password-reset-redirect-url-format: ${STEAM_PASSWORD_RESET_REDIRECT_URL_FORMAT:https://api.${FAF_DOMAIN}/users/requestPasswordResetViaSteam}
tutorial:
thumbnail-url-format: ${TUTORIAL_THUMBNAIL_URL_FORMAT:https://content.${FAF_DOMAIN}/faf/tutorials/thumbs/%s}

spring:
application:
Expand All @@ -41,6 +93,10 @@ spring:
minimum-idle: 2
maximum-pool-size: 12
league-datasource:
url: jdbc:mariadb://${LEAGUE_DATABASE_ADDRESS:127.0.0.1}/${LEAGUE_DATABASE_NAME:faf-league}?useSSL=false
name: faf-league
username: ${LEAGUE_DATABASE_USERNAME:faf-league-service}
password: ${LEAGUE_DATABASE_PASSWORD}
configuration:
connection-test-query: SELECT 1 FROM DUAL
minimum-idle: 2
Expand All @@ -57,7 +113,7 @@ spring:
serialization:
WRITE_DATES_AS_TIMESTAMPS: false
profiles:
active: ${API_PROFILE:dev}
active: ${API_PROFILE}
servlet:
multipart:
max-file-size: 350MB
Expand Down Expand Up @@ -101,3 +157,5 @@ logging:
console: "%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%36.36X{requestId:- no request context}]){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wEx"
level:
com.faforever: ${LOG_LEVEL:info}
file:
path: ${LOG_FILE_DIRECTORY:}

0 comments on commit 3f23007

Please sign in to comment.