Skip to content

Commit c6a4d78

Browse files
author
James Rhoat
authored
Merge pull request #14 from SQLJames/feature/allow-server-id.json
updating to allow users to add mods
2 parents e109abe + cda4dc3 commit c6a4d78

File tree

5 files changed

+174
-5
lines changed

5 files changed

+174
-5
lines changed

charts/factorio-server-charts/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ sources:
2020
# This is the chart version. This version number should be incremented each time you make changes
2121
# to the chart and its templates, including the app version.
2222
# Versions are expected to follow Semantic Versioning (https://semver.org/)
23-
version: 1.0.10
23+
version: 1.0.11
2424

2525
# This is the version number of the application being deployed. This version number should be
2626
# incremented each time you make changes to the application. Versions are not expected to

charts/factorio-server-charts/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,5 +249,29 @@ https://github.com/kubernetes/kubernetes/blob/59876df736c41093363f4c198aeec05e29
249249
Releases are published using the official helm release action in github.
250250
https://github.com/helm/chart-releaser-action
251251

252+
## installing mods
253+
254+
change enabled to true, follow comments below.
255+
256+
If the factorio server doesn't start, check that the logs don't have an error with the mods. They are pretty verbose
257+
```
258+
mods:
259+
enabled: true
260+
# in order to use the mods portal you will need to specify the username and token in the server_settings.
261+
# name is determined by the url, it will be the last part of the url, not the title of the mod.
262+
portal:
263+
- Krastorio2
264+
- StorageTank2_Updated
265+
- early-robots
266+
# unofficial section is meant to just allow you to download and place folders into the mods folder.
267+
# we will not check version compatibility automatically with these downloads.
268+
# you can encounter an error if the file names dont match what the mod is expecting for example
269+
#Error Util.cpp:83: Failed to load mod "Squeak-Through": Filename of mod
270+
# /factorio/mods/Squeak-Through.zip doesn't match the expected Squeak Through_1.8.2.zip (case sensitive!)
271+
unofficial:
272+
- url: "https://github.com/Suprcheese/Squeak-Through/archive/refs/tags/1.8.2.zip"
273+
name: "Squeak Through_1.8.2.zip"
274+
```
275+
252276
## Readme
253277
Readme was generated from the [chart-doc-gen](https://github.com/kubepack/chart-doc-gen) tool.

charts/factorio-server-charts/templates/deployment.yaml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@ spec:
4141
mountPath: /factorio
4242
- name: {{ template "factorio-server-charts.fullname" . }}-serversettingsconfig
4343
mountPath: /deployed-configs
44+
{{- if .Values.mods.enabled }}
45+
- name: download-factorio-mods
46+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
47+
imagePullPolicy: {{ .Values.image.pullPolicy }}
48+
command:
49+
- /bin/bash
50+
- -ec
51+
- |
52+
mkdir -p /factorio/mods
53+
bash /scripts/mod-downloader.sh
54+
securityContext:
55+
runAsUser: 0
56+
volumeMounts:
57+
- name: datadir
58+
mountPath: /factorio
59+
- name: {{ template "factorio-server-charts.fullname" . }}-mod-downloader-configmap
60+
mountPath: /scripts
61+
{{- end }}
4462
containers:
4563
- name: {{ template "factorio-server-charts.fullname" . }}
4664
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
@@ -90,4 +108,6 @@ spec:
90108
- name: {{ template "factorio-server-charts.fullname" . }}-serversettingsconfig
91109
configMap:
92110
name: {{ template "factorio-server-charts.fullname" . }}-serversettingsconfig
93-
111+
- name: {{ template "factorio-server-charts.fullname" . }}-mod-downloader-configmap
112+
configMap:
113+
name: {{ template "factorio-server-charts.fullname" . }}-mod-downloader-configmap
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ template "factorio-server-charts.fullname" . }}-mod-downloader-configmap
5+
labels:
6+
app: {{ template "factorio-server-charts.fullname" . }}
7+
chart: {{ template "factorio-server-charts.fullname" . }}
8+
release: "{{ .Release.Name }}"
9+
heritage: "{{ .Release.Service }}"
10+
data:
11+
#credit to the factoriotools/factorio-docker team, most of this logic came from them
12+
# https://github.com/factoriotools/factorio-docker/blob/master/docker/files/update-mods.sh
13+
mod-downloader.sh: |
14+
modDir=/factorio/mods
15+
MOD_BASE_URL="https://mods.factorio.com"
16+
declare -a officialMods
17+
officialMods=(
18+
{{- range .Values.mods.portal }}
19+
{{ . }}
20+
{{- end }}
21+
)
22+
declare -A unofficialMods
23+
{{- range .Values.mods.unofficial }}
24+
unofficialMods[{{ .name | quote}}]={{ .url | quote}}
25+
{{- end }}
26+
function print_step()
27+
{
28+
echo "$1"
29+
}
30+
function print_success()
31+
{
32+
echo "$1"
33+
}
34+
function print_failure()
35+
{
36+
echo "$1"
37+
}
38+
function downloadUnofficial() {
39+
cd $modDir;curl -L -o $2 $1
40+
}
41+
function downloadofficial() {
42+
if [[ -z ${USERNAME:-} ]]; then
43+
USERNAME="$(jq -j ".username" "/factorio/configs/server-settings.json")"
44+
fi
45+
46+
if [[ -z ${TOKEN:-} ]]; then
47+
TOKEN="$(jq -j ".token" "/factorio/configs/server-settings.json")"
48+
fi
49+
50+
if [[ -z ${USERNAME:-} ]]; then
51+
echo "You need to provide your Factorio username to update mods."
52+
fi
53+
54+
if [[ -z ${TOKEN:-} ]]; then
55+
echo "You need to provide your Factorio token to update mods."
56+
fi
57+
MOD_INFO_URL="$MOD_BASE_URL/api/mods/$1"
58+
MOD_INFO_JSON=$(curl --silent "$MOD_INFO_URL")
59+
#echo "$MOD_INFO_URL $MOD_INFO_JSON"
60+
if ! echo "$MOD_INFO_JSON" | jq -e .name >/dev/null; then
61+
print_success " Custom mod not on $MOD_BASE_URL, skipped."
62+
return 0
63+
fi
64+
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")
65+
echo $MOD_INFO
66+
MOD_FILENAME=$(echo "$MOD_INFO" | cut -f1 -d";")
67+
MOD_URL=$(echo "$MOD_INFO" | cut -f2 -d";")
68+
MOD_SHA1=$(echo "$MOD_INFO" | cut -f3 -d";")
69+
if [[ $MOD_FILENAME == null ]]; then
70+
print_failure " Not compatible with version"
71+
return 0
72+
fi
73+
print_step "Downloading..."
74+
FULL_URL="$MOD_BASE_URL$MOD_URL?username=$USERNAME&token=$TOKEN"
75+
echo $FULL_URL
76+
HTTP_STATUS=$(curl --silent -L -w "%{http_code}" -o "$modDir/$MOD_FILENAME" "$FULL_URL")
77+
78+
if [[ $HTTP_STATUS != 200 ]]; then
79+
print_failure " Download failed: Code $HTTP_STATUS."
80+
rm -f "$modDir/$MOD_FILENAME"
81+
return 1
82+
fi
83+
84+
if [[ ! -f $modDir/$MOD_FILENAME ]]; then
85+
print_failure " Downloaded file missing!"
86+
return 1
87+
fi
88+
89+
if ! [[ $(sha1sum "$modDir/$MOD_FILENAME") =~ $MOD_SHA1 ]]; then
90+
print_failure " SHA1 mismatch!"
91+
rm -f "$modDir/$MOD_FILENAME"
92+
return 1
93+
fi
94+
95+
print_success " Download complete."
96+
}
97+
mkdir -p $modDir
98+
for key in "${!unofficialMods[@]}"; do
99+
downloadUnofficial "${unofficialMods[$key]}" $key
100+
done
101+
{{- if and .Values.server_settings.username .Values.server_settings.token }}
102+
echo "server is running version $VERSION"
103+
for officialMod in ${officialMods[*]}; do
104+
downloadofficial $officialMod $USERNAME $TOKEN
105+
done
106+
{{- end }}
107+
108+
109+
110+
111+

charts/factorio-server-charts/values.yaml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ image:
2121
## 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!
2222
service:
2323
type: LoadBalancer
24-
port: 34197
24+
port: 30000
2525
## If you are able in your cluster to map an external IP, set it here
2626
# externalIPs:
2727
# - "192.168.0.1"
@@ -30,8 +30,7 @@ service:
3030
# nodePort: ""
3131
## Examples:
3232
## NodePort setup
33-
# type: NodePort
34-
# nodePort: ""
33+
3534
## ClusterIp setup
3635
# ClusterIP:
3736
# port: 34197
@@ -90,6 +89,21 @@ persistence:
9089

9190

9291
#### factorio application configuration ####
92+
mods:
93+
enabled: false
94+
# in order to use the mods portal you will need to specify the username and token in the server_settings.
95+
portal:
96+
- Krastorio2
97+
- StorageTank2_Updated
98+
- early-robots
99+
# unofficial section is meant to just allow you to download and place folders into the mods folder.
100+
# we will not check version compatibility automatically with these downloads.
101+
# you can encounter an error if the file names dont match what the mod is expecting for example
102+
#Error Util.cpp:83: Failed to load mod "Squeak-Through": Filename of mod
103+
# /factorio/mods/Squeak-Through.zip doesn't match the expected Squeak Through_1.8.2.zip (case sensitive!)
104+
unofficial:
105+
- url: "https://github.com/Suprcheese/Squeak-Through/archive/refs/tags/1.8.2.zip"
106+
name: "Squeak Through_1.8.2.zip"
93107

94108
factorioServer:
95109
# specify a save name

0 commit comments

Comments
 (0)