Skip to content

Commit 8a0260e

Browse files
authored
feature: use backup path on game server (#112)
1 parent 607f09f commit 8a0260e

File tree

15 files changed

+102
-4
lines changed

15 files changed

+102
-4
lines changed

async-server-provisioner/config/custom-environment-variables.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ datadog:
1717
api_key: DD_API_KEY
1818

1919
cloudGame:
20+
ansibleBranch: CLOUD_GAME_ANSIBLE_BRANCH
2021
apiUrl: CLOUD_GAME_API_URL
2122
apiToken: CLOUD_GAME_API_TOKEN

async-server-provisioner/config/default.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ datadog:
1919
api_key: placeholder
2020

2121
cloudGame:
22+
ansibleBranch: main
2223
apiUrl: http://host.docker.internal:1337
2324
apiToken: placeholder

async-server-provisioner/src/entities/GameInstance.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export interface GameInstance {
22
name: string;
33
dockerImage: string;
44
ports: GameInstancePort[];
5+
backupPaths: GameInstanceBackupPath[];
56
}
67

78
export enum GameInstancePortType {
@@ -15,12 +16,18 @@ export interface GameInstancePort {
1516
type: GameInstancePortType;
1617
}
1718

19+
export interface GameInstanceBackupPath {
20+
name: string;
21+
path: string;
22+
}
23+
1824
export function gameInstanceFactory(row: any): GameInstance {
1925
const gameVersion = row.data.attributes.game_version;
2026
return {
2127
name: row.data.attributes.name,
2228
dockerImage: gameVersion.data.attributes.docker_image,
2329
ports: gameVersion.data.attributes.ports.map(parseGameInstancePort),
30+
backupPaths: gameVersion.data.attributes.backup_paths.map(parseGameInstanceBackupPaths),
2431
};
2532
}
2633

@@ -31,3 +38,10 @@ function parseGameInstancePort(raw: any): GameInstancePort {
3138
type: (GameInstancePortType as any)[raw.type],
3239
};
3340
}
41+
42+
function parseGameInstanceBackupPaths(raw: any): GameInstanceBackupPath {
43+
return {
44+
name: raw.name,
45+
path: raw.path,
46+
};
47+
}

async-server-provisioner/src/entities/MinecraftTFConfig.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export interface MinecraftTFConfig {
1515
port: string;
1616
description: string;
1717
}[];
18+
backup_paths: {
19+
path: string;
20+
}[];
1821
};
1922
datadog: {
2023
enabled: boolean;
@@ -25,7 +28,7 @@ export interface MinecraftTFConfig {
2528
export function mcTFConfToTFArgs(mfConfig: MinecraftTFConfig): string {
2629
return `-var='metadata=${JSON.stringify(mfConfig.metadata)}' -var='server=${JSON.stringify(
2730
mfConfig.server
28-
)}' -var='datadog=${JSON.stringify(mfConfig.datadog)}'`;
31+
)}' -var='datadog=${JSON.stringify(mfConfig.datadog)}' -var='ansible_branch=${config.get('cloudGame.ansibleBranch')}'`;
2932
}
3033

3134
export function createMinecraftTFConfigFromGameConfig(mfConfig: GameDeployment): MinecraftTFConfig {
@@ -43,6 +46,9 @@ export function createMinecraftTFConfigFromGameConfig(mfConfig: GameDeployment):
4346
port: `${port.port}`,
4447
description: port.name,
4548
})),
49+
backup_paths: mfConfig.gameInstance.backupPaths.map((p) => ({
50+
path: p.path,
51+
})),
4652
},
4753
datadog: {
4854
enabled: config.get('datadog.enabled'),

async-server-provisioner/src/repositories/GameDeploymentRepository.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ query($id: ID) {
3434
port
3535
type
3636
}
37+
backup_paths {
38+
name
39+
path
40+
}
3741
}
3842
}
3943
}

infrastructure/ansible/roles/game-server-start/tasks/main.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
when: datadog.enabled
44
- include_tasks: game-server-watcher.yml
55

6+
- name: Fetch docker image
7+
shell: /usr/bin/docker pull {{ server.docker_image }}
8+
- name: Create mount paths
9+
file:
10+
path: "/mnt/bakup/{{ item.path }}"
11+
state: directory
12+
mode: "0777"
13+
loop: "{{ server.backup_paths }}"
614
- name: Create game-server systemd service
715
template:
816
src: game-server.service

infrastructure/ansible/roles/game-server-start/templates/game-server.service

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ RemainAfterExit=true
99
ExecStartPre=-/usr/bin/docker rm -f game-server
1010
ExecStart=/usr/bin/docker run -i --name game-server \
1111
--net host \
12+
{% for p in server.backup_paths %}
13+
-v /mnt/bakup/{{ p.path }}:{{p.path}} \
14+
{% endfor %}
1215
{{ server.docker_image }}
1316
TimeoutStopSec=300
1417

infrastructure/ansible/roles/game-server-start/vars/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
server:
33
docker_image: placeholder
4+
backup_paths:
5+
- path: placeholder
46
datadog:
57
enabled: true
68
api_key: placeholder
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
FROM steamcmd/steamcmd:latest
22

3-
RUN useradd steamuser -d /home/steamuser
3+
RUN addgroup steamuser \
4+
&& useradd --create-home --shell /bin/bash -g steamuser steamuser
45

56
WORKDIR /home/steamuser
67

78
RUN steamcmd +force_install_dir /home/steamuser/SatisfactoryDedicatedServer +login anonymous +app_update 1690800 -beta public validate +quit \
89
&& chown -R steamuser /home/steamuser/SatisfactoryDedicatedServer
910

1011
USER steamuser
12+
ENV HOME=/home/steamuser
13+
ENV USER=steamuser
1114

1215
ENTRYPOINT ["/bin/bash"]
13-
CMD ["./SatisfactoryDedicatedServer/FactoryServer.sh"]
16+
CMD ["/home/steamuser/SatisfactoryDedicatedServer/FactoryServer.sh", "-Port=7777", "-BeaconPort=15000", "-ServerQueryPort=15777", "-multihome=\"0.0.0.0\""]

infrastructure/terraform/02-game-server/files/startup.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ aws:
1010
# game server start varibales
1111
server:
1212
docker_image: ${game_server_image}
13+
backup_paths:
14+
%{ for p in backup_paths }
15+
- path: ${p.path}
16+
%{ endfor }
1317
datadog:
1418
enabled: ${datadog_enabled}
1519
api_key: ${datadog_api_key}

infrastructure/terraform/02-game-server/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ module "game_server" {
7777
aws_access_key_id = data.terraform_remote_state.aws_platform.outputs.access_keys["game_user.cloud-game"].access_key_id
7878
aws_secret_access_key = data.terraform_remote_state.aws_platform.outputs.access_keys["game_user.cloud-game"].secret_access_key
7979
ansible_branch = var.ansible_branch
80+
81+
backup_paths = [for path in var.server.backup_paths : { path = path.path }]
8082
}
8183
}
8284
}

infrastructure/terraform/02-game-server/variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ variable "server" {
1616
port = string
1717
description = string
1818
}))
19+
20+
backup_paths = list(object({
21+
path = string
22+
}))
1923
})
2024
}
2125

infrastructure/terraform/02-game-server/vars/test.tfvars

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ server = {
88
image = "68074861"
99
docker_image = "cloudgame/minecraft:vanilla-1.18.2"
1010
ports = []
11+
backup_paths = [{ path = "isso" }]
1112
}
1213

1314
datadog = {

infrastructure/terraform/modules/server/.terraform.lock.hcl

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

infrastructure/terraform/modules/server/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ variable "network" {
4747
variable "user_data" {
4848
type = object({
4949
path = string
50-
vars = map(string)
50+
vars = any
5151
})
5252
default = {
5353
path = ""

0 commit comments

Comments
 (0)