From 487dd22c3926e40ea6f5504ee528c99030240bf0 Mon Sep 17 00:00:00 2001 From: James Rhoat Date: Sun, 3 Nov 2024 11:18:14 -0500 Subject: [PATCH 1/2] fixing mod encoding --- CHANGELOG.md | 6 ++++++ charts/factorio-server-charts/Chart.yaml | 2 +- charts/factorio-server-charts/templates/deployment.yaml | 6 +++++- .../templates/mod-downloader-configmap.yaml | 4 +++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dbc24a..5ed1a6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## Changelog +### V2.2.1 + +#### Non-Breaking Changes + +- Fixing mod download script to encode spaces properly, fixes [Issue 42](https://github.com/SQLJames/factorio-server-charts/issues/42) + ### V2.2.0 #### Non-Breaking Changes diff --git a/charts/factorio-server-charts/Chart.yaml b/charts/factorio-server-charts/Chart.yaml index 057c278..34f1543 100644 --- a/charts/factorio-server-charts/Chart.yaml +++ b/charts/factorio-server-charts/Chart.yaml @@ -20,7 +20,7 @@ sources: # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 2.2.0 +version: 2.2.1 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/charts/factorio-server-charts/templates/deployment.yaml b/charts/factorio-server-charts/templates/deployment.yaml index 8532aa6..08f7227 100644 --- a/charts/factorio-server-charts/templates/deployment.yaml +++ b/charts/factorio-server-charts/templates/deployment.yaml @@ -85,10 +85,14 @@ spec: imagePullPolicy: {{ .Values.image.pullPolicy }} command: - /bin/bash - - -ec + - -ecx - | mkdir -p /factorio/mods + ls -alth /scripts + echo "Running mod-downloader.sh script..." bash /scripts/mod-downloader.sh + echo "Finished mod-downloader.sh script" + ls -althR /factorio/mods {{- with .Values.securityContext }} securityContext: {{- toYaml . | nindent 12 }} diff --git a/charts/factorio-server-charts/templates/mod-downloader-configmap.yaml b/charts/factorio-server-charts/templates/mod-downloader-configmap.yaml index 57a3d96..d563596 100644 --- a/charts/factorio-server-charts/templates/mod-downloader-configmap.yaml +++ b/charts/factorio-server-charts/templates/mod-downloader-configmap.yaml @@ -39,6 +39,8 @@ data: cd $modDir;curl -L -o $2 $1 } function downloadofficial() { + MOD_NAME="$1" + MOD_NAME_ENCODED="${1// /%20}" if [[ -z ${USERNAME:-} ]]; then USERNAME="$(cat /account/username)" fi @@ -54,7 +56,7 @@ data: if [[ -z ${TOKEN:-} ]]; then echo "You need to provide your Factorio token to update mods." fi - MOD_INFO_URL="$MOD_BASE_URL/api/mods/$1" + MOD_INFO_URL="$MOD_BASE_URL/api/mods/$MOD_NAME_ENCODED" MOD_INFO_JSON=$(curl --silent "$MOD_INFO_URL") # echo "$MOD_INFO_URL $MOD_INFO_JSON" if ! echo "$MOD_INFO_JSON" | jq -e .name >/dev/null; then From 7674546a27adc953fd81d63b0944810de51d281a Mon Sep 17 00:00:00 2001 From: James Rhoat Date: Sun, 3 Nov 2024 11:26:10 -0500 Subject: [PATCH 2/2] adding update mod check on mod script to avoid it always updating mods --- CHANGELOG.md | 1 + .../factorio-server-charts/templates/deployment.yaml | 3 +++ .../templates/mod-downloader-configmap.yaml | 11 ++++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ed1a6b..f3745a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ #### Non-Breaking Changes - Fixing mod download script to encode spaces properly, fixes [Issue 42](https://github.com/SQLJames/factorio-server-charts/issues/42) +- Adding update mod check on mod script to avoid it always updating mods, fixes part of[Issue 45](https://github.com/SQLJames/factorio-server-charts/issues/45) ### V2.2.0 diff --git a/charts/factorio-server-charts/templates/deployment.yaml b/charts/factorio-server-charts/templates/deployment.yaml index 08f7227..e316c04 100644 --- a/charts/factorio-server-charts/templates/deployment.yaml +++ b/charts/factorio-server-charts/templates/deployment.yaml @@ -97,6 +97,9 @@ spec: securityContext: {{- toYaml . | nindent 12 }} {{- end }} + env: + - name: UPDATE_MODS_ON_START + value: {{ .Values.factorioServer.update_mods_on_start | quote }} volumeMounts: - name: datadir mountPath: /factorio diff --git a/charts/factorio-server-charts/templates/mod-downloader-configmap.yaml b/charts/factorio-server-charts/templates/mod-downloader-configmap.yaml index d563596..3efe95f 100644 --- a/charts/factorio-server-charts/templates/mod-downloader-configmap.yaml +++ b/charts/factorio-server-charts/templates/mod-downloader-configmap.yaml @@ -11,6 +11,13 @@ data: # credit to the factoriotools/factorio-docker team, most of this logic came from them # https://github.com/factoriotools/factorio-docker/blob/master/docker/files/update-mods.sh mod-downloader.sh: | + FLAG_FILE="/factorio/mods/.mod_update_complete" + + # Check if flag file exists and UPDATE_MODS_ON_START is not true + if [[ -f "$FLAG_FILE" && "${UPDATE_MODS_ON_START}" != "true" ]]; then + echo "Mod update already completed previously. Skipping." + exit 0 + fi modDir=/factorio/mods MOD_BASE_URL="https://mods.factorio.com" declare -a officialMods @@ -109,7 +116,9 @@ data: done fi fi - + # Mark the update as complete by creating the flag file + touch "$FLAG_FILE" + echo "Mod update completed."