Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/factorio-server-charts/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: 1.0.10
version: 1.0.11

# 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
Expand Down
24 changes: 24 additions & 0 deletions charts/factorio-server-charts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,5 +249,29 @@ https://github.com/kubernetes/kubernetes/blob/59876df736c41093363f4c198aeec05e29
Releases are published using the official helm release action in github.
https://github.com/helm/chart-releaser-action

## installing mods

change enabled to true, follow comments below.

If the factorio server doesn't start, check that the logs don't have an error with the mods. They are pretty verbose
```
mods:
enabled: true
# in order to use the mods portal you will need to specify the username and token in the server_settings.
# name is determined by the url, it will be the last part of the url, not the title of the mod.
portal:
- Krastorio2
- StorageTank2_Updated
- early-robots
# 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
#Error Util.cpp:83: Failed to load mod "Squeak-Through": Filename of mod
# /factorio/mods/Squeak-Through.zip doesn't match the expected Squeak Through_1.8.2.zip (case sensitive!)
unofficial:
- url: "https://github.com/Suprcheese/Squeak-Through/archive/refs/tags/1.8.2.zip"
name: "Squeak Through_1.8.2.zip"
```

## Readme
Readme was generated from the [chart-doc-gen](https://github.com/kubepack/chart-doc-gen) tool.
22 changes: 21 additions & 1 deletion charts/factorio-server-charts/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ spec:
mountPath: /factorio
- name: {{ template "factorio-server-charts.fullname" . }}-serversettingsconfig
mountPath: /deployed-configs
{{- if .Values.mods.enabled }}
- name: download-factorio-mods
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- /bin/bash
- -ec
- |
mkdir -p /factorio/mods
bash /scripts/mod-downloader.sh
securityContext:
runAsUser: 0
volumeMounts:
- name: datadir
mountPath: /factorio
- name: {{ template "factorio-server-charts.fullname" . }}-mod-downloader-configmap
mountPath: /scripts
{{- end }}
containers:
- name: {{ template "factorio-server-charts.fullname" . }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
Expand Down Expand Up @@ -90,4 +108,6 @@ spec:
- name: {{ template "factorio-server-charts.fullname" . }}-serversettingsconfig
configMap:
name: {{ template "factorio-server-charts.fullname" . }}-serversettingsconfig

- name: {{ template "factorio-server-charts.fullname" . }}-mod-downloader-configmap
configMap:
name: {{ template "factorio-server-charts.fullname" . }}-mod-downloader-configmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "factorio-server-charts.fullname" . }}-mod-downloader-configmap
labels:
app: {{ template "factorio-server-charts.fullname" . }}
chart: {{ template "factorio-server-charts.fullname" . }}
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
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: |
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() {
if [[ -z ${USERNAME:-} ]]; then
USERNAME="$(jq -j ".username" "/factorio/configs/server-settings.json")"
fi

if [[ -z ${TOKEN:-} ]]; then
TOKEN="$(jq -j ".token" "/factorio/configs/server-settings.json")"
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/$1"
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

if ! [[ $(sha1sum "$modDir/$MOD_FILENAME") =~ $MOD_SHA1 ]]; then
print_failure " SHA1 mismatch!"
rm -f "$modDir/$MOD_FILENAME"
return 1
fi

print_success " Download complete."
}
mkdir -p $modDir
for key in "${!unofficialMods[@]}"; do
downloadUnofficial "${unofficialMods[$key]}" $key
done
{{- if and .Values.server_settings.username .Values.server_settings.token }}
echo "server is running version $VERSION"
for officialMod in ${officialMods[*]}; do
downloadofficial $officialMod $USERNAME $TOKEN
done
{{- end }}





20 changes: 17 additions & 3 deletions charts/factorio-server-charts/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ image:
## The best way ist to define a ClusterIP service and define one or more externalIPs. Of course this IPs must be avaiable on the node the factorio runs the pod!
service:
type: LoadBalancer
port: 34197
port: 30000
## If you are able in your cluster to map an external IP, set it here
# externalIPs:
# - "192.168.0.1"
Expand All @@ -30,8 +30,7 @@ service:
# nodePort: ""
## Examples:
## NodePort setup
# type: NodePort
# nodePort: ""

## ClusterIp setup
# ClusterIP:
# port: 34197
Expand Down Expand Up @@ -90,6 +89,21 @@ persistence:


#### factorio application configuration ####
mods:
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
# 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
#Error Util.cpp:83: Failed to load mod "Squeak-Through": Filename of mod
# /factorio/mods/Squeak-Through.zip doesn't match the expected Squeak Through_1.8.2.zip (case sensitive!)
unofficial:
- url: "https://github.com/Suprcheese/Squeak-Through/archive/refs/tags/1.8.2.zip"
name: "Squeak Through_1.8.2.zip"

factorioServer:
# specify a save name
Expand Down