Add support of CF_API_KEY_FILE environment variable (#3396)

This commit is contained in:
Maxim Liven
2025-04-05 16:37:51 +03:00
committed by GitHub
parent 5b549c0483
commit 483cd3a1d8
5 changed files with 33 additions and 3 deletions

View File

@@ -6,7 +6,7 @@ A specific file can be omitted from each reference to allow for auto-selecting t
!!! warning "CurseForge API key usage"
A CurseForge API key must be allocated and set with `CF_API_KEY` [as described here](../types-and-platforms/mod-platforms/auto-curseforge.md#api-key).
A CurseForge API key must be allocated and set with `CF_API_KEY` (or `CF_API_KEY_FILE`) [as described here](../types-and-platforms/mod-platforms/auto-curseforge.md#api-key).
## Project-file references

View File

@@ -32,6 +32,19 @@ To manage a CurseForge modpack automatically with upgrade support, pinned or lat
docker run --env-file=.env itzg/minecraft-server
```
Alternately you can use [docker secrets](https://docs.docker.com/compose/how-tos/use-secrets/) with a `CF_API_KEY_FILE` environment variable:
```
service:
environment:
CF_API_KEY_FILE: /run/secrets/cf_api_key.secret
secrets:
- cf_api_key
secrets:
cf_api_key:
file: cf_api_key.secret
```
!!! note
Be sure to use the appropriate [image tag for the Java version compatible with the modpack](../../versions/java.md).

View File

@@ -730,6 +730,12 @@ alternatively, you can mount: <code>/etc/localtime:/etc/localtime:ro
<td><code></code></td>
<td>✅</td>
</tr>
<tr>
<td><code>CF_API_KEY_FILE</code></td>
<td>A path to a file inside of container that contains <strong>YOUR</strong> CurseForge (Eternal) API Key.</td>
<td><code></code></td>
<td>✅</td>
</tr>
<tr>
<td><code>CF_PAGE_URL</code></td>
<td>Pass a page URL to the modpack or a specific file</td>

View File

@@ -24,6 +24,11 @@ set -eu
resultsFile=/data/.install-curseforge.env
if [[ -n ${CF_API_KEY_FILE} ]]; then
CF_API_KEY="$(cat "${CF_API_KEY_FILE}")"
export CF_API_KEY
fi
isDebugging && set -x
ensureRemoveAllModsOff "MODPACK_PLATFORM=AUTO_CURSEFORGE"
@@ -61,7 +66,7 @@ if ! mc-image-helper install-curseforge "${args[@]}"; then
exit 1
fi
applyResultsFile ${resultsFile}
applyResultsFile "${resultsFile}"
resolveFamily
exec "${SCRIPTS:-/}start-setupWorld" "$@"

View File

@@ -13,6 +13,12 @@ set -e -o pipefail
: "${REMOVE_OLD_MODS_INCLUDE:=*.jar,*-version.json}"
sum_file=/data/.generic_pack.sum
if [[ -n ${CF_API_KEY_FILE} ]]; then
CF_API_KEY="$(cat "${CF_API_KEY_FILE}")"
export CF_API_KEY
fi
# shellcheck source=start-utils
. "${SCRIPTS:-/}start-utils"
isDebugging && set -x
@@ -195,7 +201,7 @@ function handleGenericPacks() {
# Disable mods
for mod in ${GENERIC_PACKS_DISABLE_MODS}; do
log Disabling $mod
log Disabling "$mod"
find "${base_dir}" -name "$mod" -exec mv {} {}.disabled -v \;
done