diff --git a/CHANGELOG.md b/CHANGELOG.md index e2ad489..48cbae9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## Changelog +### V2.5.0 + +#### Breaking Changes + +- Reformatted the mods section to allow users to specify a mod version so it wont try to pull the latest if you don't want it too. This refactor introduces a custom tool [factorio-mod-downloader](https://github.com/SQLJames/factorio-mod-downloader) as an image, which is a simple golang tool, which simplifies the script and improves logging. + ### V2.4.1 #### Non-Breaking Changes diff --git a/charts/factorio-server-charts/Chart.yaml b/charts/factorio-server-charts/Chart.yaml index 9e94ad1..ad4a7e5 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.4.1 +version: 2.5.0 # 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 f4cc415..0d94354 100644 --- a/charts/factorio-server-charts/templates/deployment.yaml +++ b/charts/factorio-server-charts/templates/deployment.yaml @@ -39,7 +39,9 @@ spec: - -ec - | mkdir -p /factorio/configs + mkdir -p /factorio/mods mkdir -p /factorio/config + echo $VERSION > /factorio/mods/factorioVersion cp --verbose /deployed-configs/* /factorio/configs if [ -f "/rcon-pw/rconpw" ]; then cp --verbose /rcon-pw/rconpw /factorio/configs/rconpw @@ -82,14 +84,12 @@ spec: {{- end }} {{- if .Values.mods.enabled }} - name: download-factorio-mods - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} + image: "{{ .Values.mods.image.repository }}:{{ .Values.mods.image.tag }}" + imagePullPolicy: {{ .Values.mods.image.pullPolicy }} command: - /bin/bash - -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" diff --git a/charts/factorio-server-charts/templates/mod-downloader-configmap.yaml b/charts/factorio-server-charts/templates/mod-downloader-configmap.yaml index 3efe95f..9412542 100644 --- a/charts/factorio-server-charts/templates/mod-downloader-configmap.yaml +++ b/charts/factorio-server-charts/templates/mod-downloader-configmap.yaml @@ -19,103 +19,28 @@ data: exit 0 fi modDir=/factorio/mods - MOD_BASE_URL="https://mods.factorio.com" - declare -a officialMods - officialMods=( - {{- range .Values.mods.portal }} - {{ . }} - {{- end }} - ) - declare -A unofficialMods - {{- range .Values.mods.unofficial }} - unofficialMods[{{ .name | quote}}]={{ .url | quote}} - {{- end }} - function print_step() - { - echo "$1" - } - function print_success() - { - echo "$1" - } - function print_failure() - { - echo "$1" - } - function downloadUnofficial() { - 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 - - if [[ -z ${TOKEN:-} ]]; then - TOKEN="$(cat /account/token)" - fi - - if [[ -z ${USERNAME:-} ]]; then - echo "You need to provide your Factorio username to update mods." - fi - - if [[ -z ${TOKEN:-} ]]; then - echo "You need to provide your Factorio token to update mods." - fi - 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 - print_success " Custom mod not on $MOD_BASE_URL, skipped." - return 0 - fi - MOD_INFO=$(echo "$MOD_INFO_JSON" | jq -j --arg version "$VERSION" ".releases|reverse|map(select(.info_json.factorio_version as \$mod_version | \$version | startswith(\$mod_version)))[0]|.file_name, \";\", .download_url, \";\", .sha1") - echo $MOD_INFO - MOD_FILENAME=$(echo "$MOD_INFO" | cut -f1 -d";") - MOD_URL=$(echo "$MOD_INFO" | cut -f2 -d";") - MOD_SHA1=$(echo "$MOD_INFO" | cut -f3 -d";") - if [[ $MOD_FILENAME == null ]]; then - print_failure " Not compatible with version" - return 0 - fi - print_step "Downloading..." - FULL_URL="$MOD_BASE_URL$MOD_URL?username=$USERNAME&token=$TOKEN" - echo $FULL_URL - HTTP_STATUS=$(curl --silent -L -w "%{http_code}" -o "$modDir/$MOD_FILENAME" "$FULL_URL") - - if [[ $HTTP_STATUS != 200 ]]; then - print_failure " Download failed: Code $HTTP_STATUS." - rm -f "$modDir/$MOD_FILENAME" - return 1 - fi - - if [[ ! -f $modDir/$MOD_FILENAME ]]; then - print_failure " Downloaded file missing!" - return 1 - fi + FACTORIOVERSION="$(cat /factorio/mods/factorioVersion)" + USERNAME="$(cat /account/username)" + TOKEN="$(cat /account/token)" + if [[ -z ${USERNAME:-} ]]; then + echo "You need to provide your Factorio username to update mods." + fi - if ! [[ $(sha1sum "$modDir/$MOD_FILENAME") =~ $MOD_SHA1 ]]; then - print_failure " SHA1 mismatch!" - rm -f "$modDir/$MOD_FILENAME" - return 1 + if [[ -z ${TOKEN:-} ]]; then + echo "You need to provide your Factorio token to update mods." + fi + {{- range .Values.mods.portal }} + if [ -z {{ .version | quote }} ]; then + /usr/local/bin/factorio-mod-downloader download official --name {{ .name | quote}} --destination $modDir --factorioVersion $FACTORIOVERSION --user $USERNAME --token $TOKEN + else + /usr/local/bin/factorio-mod-downloader download official --name {{ .name | quote}} --destination $modDir --factorioVersion $FACTORIOVERSION --user $USERNAME --token $TOKEN --version {{ .version | quote}} fi + {{- end }} + + {{- range .Values.mods.unofficial }} + /usr/local/bin/factorio-mod-downloader download unofficial --url {{ .url | quote}} --name {{ .name | quote}} --destination $modDir + {{- end }} - print_success " Download complete." - } - mkdir -p $modDir - for key in "${!unofficialMods[@]}"; do - downloadUnofficial "${unofficialMods[$key]}" $key - done - - if [ -f "/account/username" ]; then - if [ -f "/account/token" ]; then - echo "server is running version $VERSION" - for officialMod in ${officialMods[*]}; do - downloadofficial $officialMod $USERNAME $TOKEN - done - fi - fi # Mark the update as complete by creating the flag file touch "$FLAG_FILE" echo "Mod update completed." diff --git a/charts/factorio-server-charts/values.yaml b/charts/factorio-server-charts/values.yaml index 01bcd35..16ac567 100644 --- a/charts/factorio-server-charts/values.yaml +++ b/charts/factorio-server-charts/values.yaml @@ -147,12 +147,19 @@ persistence: ## @param mods.portal List of official mods to be downloaded from Factorio Mod Portal ## @param mods.unofficial List of unofficial mods name and url to download into the mods folder mods: + image: + repository: "ghcr.io/sqljames/factorio-mod-downloader" + ## Container image pull policy + pullPolicy: Always + ## Overrides the image tag whose default is the chart appVersion. + tag: "1.0.1" + ## You should set an fix version, i.e.: + # tag: "1.1.37" enabled: false # in order to use the mods portal you will need to specify the username and token in the server_settings. portal: [] -# - Krastorio2 -# - StorageTank2_Updated -# - early-robots +# - name: factorissimo-2-notnotmelon +# version: 3.5.11 # unofficial section is meant to just allow you to download and place folders into the mods folder. # we will not check version compatibility automatically with these downloads. # you can encounter an error if the file names dont match what the mod is expecting for example