Skip to content

Commit aa8ba7d

Browse files
committed
Perform crazy refactor to Symfony
1 parent 49e0e6c commit aa8ba7d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+9120
-414
lines changed

.dockerignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
templates/webserver/website/config/secrets/prod/prod.decrypt.private.php
2+
templates/webserver/website/public/.tmb/
3+
templates/webserver/website/public/bundles/
4+
templates/webserver/website/var/
5+
templates/webserver/website/vendor/
6+
templates/webserver/website/.env.local.php
7+
templates/webserver/website/donation_log.txt

.gitignore

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
MobileForces.zip
1+
MobileForces*.zip
22
hosts
33
vars.yml
4-
templates/gameserver/scripts/compress.sh
5-
templates/gameserver/services/mobileforces-gameserver.service
6-
templates/gameserver/services/mobileforces-fastdl.service
7-
templates/masterserver/services/mobileforces-masterserver.service
8-
templates/webserver/vhosts/mobileforces.conf
9-
templates/webserver/website/donations.db
10-
templates/webserver/website/admin/elFinder-*
11-
!templates/webserver/website/admin/elFinder-*.zip
12-
templates/webserver/website/includes/php/kofi.php
13-
templates/webserver/website/includes/php/variables.php
4+
templates/webserver/website/.env.local.php
5+
templates/webserver/website/config/secrets/prod/prod.decrypt.private.php
6+
templates/webserver/website/public/.tmb/
7+
templates/webserver/website/public/bundles/
8+
templates/webserver/website/var/
9+
templates/webserver/website/vendor/
10+
templates/webserver/website/donation_log.txt

Dockerfile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
ARG PHP_VER=8.4
2+
FROM php:${PHP_VER}-fpm-alpine AS base
3+
4+
WORKDIR /var/www/html
5+
6+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
7+
8+
COPY templates/webserver/website .
9+
10+
RUN export APP_ENV=prod APP_DEBUG=0 && \
11+
composer install --no-dev --optimize-autoloader && \
12+
composer dump-env prod && rm -f .env
13+
14+
FROM php:${PHP_VER}-fpm-alpine
15+
16+
COPY --from=base /var/www/html /var/www/html
17+
18+
EXPOSE 9000
19+
20+
CMD ["sh", "-c", "ADMIN_PASSWORD=${ADMIN_PASSWORD} php bin/console doctrine:migrations:migrate -n; php-fpm"]

README.md

+22-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ This project allows you to automatically provision a Mobile Forces game server t
66

77
The project is deployed on Hetzner at https://mf.nofisto.com through GitHub Actions and uses Cloudflare as a CDN and domain registrar, the root of the website code can be found at: `templates/webserver`
88

9+
symfony new website --version="7.2.x"
10+
911
# Setup instructions
1012

1113
Put your MobileForces.zip in the root folder and run
@@ -17,16 +19,29 @@ You may configure various options in the vars.yml file, by deafult this playbook
1719

1820
The Ansible playbook transfers game files, installs necessary packages and sets up Systemd services for the game server, master server and FastDL of game files through an Apache2 web server which is also used for the website, an SSL certificate is automatically added to it by using Let's Encrypt's certbot tool, these steps are made in a modular way and can be excluded
1921

20-
# Potential improvements
22+
symfony check:requirements
2123

22-
https://www.ericmacedo.com/generating-code-from-templates-using-python-and-jinja2.html
24+
```
25+
export APP_SECRET=secret KOFI_TOKEN=token
26+
ADMIN_PASSWORD=P@ssword123! php bin/console doctrine:migrations:migrate
27+
symfony server:start
28+
```
2329

24-
# Thanks to
30+
```
31+
KOFI_NAME=filipmania
32+
KOFI_TARGET=12.49
33+
KOFI_CURRENCY=EUR
34+
KOFI_STARTDATE="2023-10-22 15:35:11"
35+
```
36+
37+
php bin/console make:migration
2538

26-
https://github.com/333networks/Masterserver-Qt5 for their master server implementing the Gamespy v0 protocol
39+
curl -L -H "Content-Type: application/json" -d @data.json http://127.0.0.1:8000/donate_notify
40+
41+
# Thanks to
2742

28-
https://github.com/OldUnreal/UnrealTournamentPatches for their updated System64 packages
43+
https://github.com/333networks/Masterserver-Qt5 for the master server implementing the Gamespy v0 protocol
2944

30-
https://github.com/Studio-42/elFinder for the php file manager
45+
https://github.com/Studio-42/elFinder and https://github.com/helios-ag/FMElfinderBundle for the file manager
3146

32-
https://github.com/twbs/bootstrap for bootstrap customizeation and compilation with only selected components
47+
https://github.com/OldUnreal/UnrealTournamentPatches for the updated System64 packages

compose.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
services:
2+
app:
3+
build:
4+
context: .
5+
volumes:
6+
- .:/src
7+
8+
apache:
9+
image: httpd:alpine
10+
depends_on:
11+
- app
12+
ports:
13+
- 80:80
14+
volumes:
15+
- ./src:/var/www/html
16+
17+
volumes:
18+
static:

handlers/apache.yml

-5
This file was deleted.

playbook.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@
1313
ansible.builtin.user:
1414
name: "{{ server_user }}"
1515

16-
- name: Ensure install directory exists
16+
- name: Ensure directories exist
1717
ansible.builtin.file:
18-
path: "{{ install_path }}/"
18+
path: "{{ item }}"
1919
state: directory
2020
owner: "{{ server_user }}"
2121
group: "{{ server_user }}"
2222
mode: "755"
23+
loop:
24+
- "{{ install_path }}"
25+
- "{{ website_path }}"
2326

2427
- name: Install common dependencies
2528
ansible.builtin.package:
@@ -51,4 +54,3 @@
5154

5255
handlers:
5356
- ansible.builtin.import_tasks: handlers/systemctl.yml
54-
- ansible.builtin.import_tasks: handlers/apache.yml

tasks/create_apache_webserver.yml

+63-67
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
name: "{{ item }}"
55
state: latest
66
loop:
7+
- composer
78
- libapache2-mpm-itk
8-
- libapache2-mod-php
9+
- php-fpm
910
- php-sqlite3
11+
- php-xml
1012
- python3-certbot-apache
1113

1214
- name: Create virtual host for the mf website
@@ -15,95 +17,89 @@
1517
dest: /etc/apache2/sites-available/mobileforces.conf
1618
mode: "644"
1719

18-
- name: Ensure website directories exist
19-
ansible.builtin.file:
20-
path: "{{ website_path }}/{{ item }}"
21-
state: directory
22-
owner: "{{ server_user }}"
23-
group: "{{ server_user }}"
24-
mode: "755"
25-
loop:
26-
- ""
27-
- admin
28-
- includes/
29-
- includes/php/
30-
- includes/css
31-
- includes/images
32-
- includes/js
33-
34-
- name: Copy static files into the webserver folder
20+
- name: Copy website files
3521
ansible.builtin.copy:
36-
src: "templates/webserver/website/{{ item[0] }}"
37-
dest: "{{ website_path }}/{{ item[1] }}"
22+
src: "templates/webserver/website/{{ item }}"
23+
dest: "{{ website_path }}/"
3824
owner: "{{ server_user }}"
3925
group: "{{ server_user }}"
4026
mode: "644"
4127
loop:
42-
- [index.php, index.php]
43-
- [stats.php, stats.php]
44-
- [donate_notify.php, donate_notify.php]
45-
- [favicon.ico, favicon.ico]
46-
- [admin/, admin/]
47-
- [includes/css/, includes/css/]
48-
- [includes/images/, includes/images/]
49-
- [includes/js/, includes/js/]
50-
- [includes/php/body.php, includes/php/body.php]
51-
- [includes/php/db.php, includes/php/db.php]
28+
- bin
29+
- config
30+
- migrations
31+
- public
32+
- src
33+
- templates
34+
- .env
35+
- composer.json
36+
- composer.lock
37+
- symfony.lock
38+
- sync_paypal.php
5239

53-
- name: Copy dynamic website files
54-
ansible.builtin.template:
55-
src: "templates/webserver/website/{{ item[0] }}"
56-
dest: "{{ website_path }}/{{ item[1] }}"
57-
owner: "{{ server_user }}"
58-
group: "{{ server_user }}"
59-
mode: "644"
60-
loop:
61-
- [includes/php/kofi.j2, includes/php/kofi.php]
62-
- [includes/php/cookies.j2, includes/php/cookies.php]
63-
- [../kofi_sync_paypal.j2, ../kofi_sync_paypal.php]
40+
- name: Install website
41+
ansible.builtin.shell: |
42+
cd "{{ website_path }}" &&
43+
export APP_ENV=prod APP_DEBUG=0 &&
44+
composer install --no-dev --optimize-autoloader &&
45+
composer dump-env prod && rm -f .env &&
46+
ADMIN_PASSWORD="{{ AdminPassword }}" php bin/console doctrine:migrations:migrate -n
47+
become_user: "{{ server_user }}"
6448

65-
- name: Remove previous verisons of elFinder
66-
ansible.builtin.shell: "rm -rf {{ website_path }}/admin/elFinder-*"
49+
- name: Enable the mobileforces website
50+
ansible.builtin.shell:
51+
cmd: a2enmod proxy_fcgi speling mpm_event && a2dismod mpm_prefork && a2ensite mobileforces.conf
52+
creates: /etc/apache2/sites-enabled/mobileforces.conf
6753

68-
- name: Extract elFinder zip onto server
69-
ansible.builtin.unarchive:
70-
src: "{{ item }}"
71-
dest: "{{ website_path }}/admin/"
72-
owner: "{{ server_user }}"
73-
group: "{{ server_user }}"
74-
mode: "755"
75-
with_fileglob:
76-
- "templates/webserver/elFinder-*.zip"
54+
- name: Request LE certificate
55+
ansible.builtin.command:
56+
cmd: "certbot --apache -n --email {{ ServerAdmin }} --agree-tos --no-redirect -d {{ ServerName }}"
57+
creates: /etc/apache2/sites-enabled/mobileforces-le-ssl.conf
7758

78-
- name: Install & configure elFinder for MF
79-
ansible.builtin.shell: cd "{{ website_path }}"/admin/elFinder-*/php && mv connector.minimal.php-dist connector.minimal.php && sed -i "s/uploadAllow' => array(/uploadAllow' => array('application\/octet-stream', 'text\/html', /g" connector.minimal.php
59+
- name: Get PHP version
60+
ansible.builtin.shell: readlink -f /usr/bin/php | grep -oP '/usr/bin/php\K.+'
61+
register: php
8062

81-
- name: Create symbolic links for elFinder
82-
ansible.builtin.shell: "cd {{ website_path }}/admin/elFinder-*/files && ln -f -s {{ item }} ."
63+
- name: Configure PHP fpm pool
64+
ansible.builtin.replace:
65+
path: "/etc/php/{{ php.stdout }}/fpm/pool.d/www.conf"
66+
regexp: "{{ item[0] }}"
67+
replace: "{{ item[1] }}"
8368
loop:
84-
- "{{ game_path }}"
85-
- "{{ website_path }}"
69+
- [= www-data, "= {{ server_user }}"]
70+
- [/run/php/php8.3-fpm.sock, /run/php/www.sock]
8671

87-
- name: Request LE certificate
88-
ansible.builtin.shell: "certbot --apache -n --email {{ ServerAdmin }} --agree-tos --no-redirect -d {{ ServerName }}"
72+
- name: Reload the apache and PHP fpm services
73+
ansible.builtin.service:
74+
name: "{{ item }}"
75+
state: reloaded
76+
loop:
77+
- apache2
78+
- "php{{ php.stdout }}-fpm"
8979

9080
- name: Allow the website to restart game services
9181
ansible.builtin.template:
9282
src: templates/webserver/scripts/01-mobileforces.j2
93-
dest: /etc/polkit-1/rules.d/01-mobileforces
83+
dest: /etc/polkit-1/rules.d/01-mobileforces.rules
9484
owner: root
9585
group: root
96-
mode: "440"
97-
98-
- name: Enable the mobileforces website
99-
ansible.builtin.shell: a2enmod speling && a2ensite mobileforces.conf
100-
notify: Reload apache
86+
mode: "644"
10187

10288
- name: Create cron job for syncing paypal
10389
ansible.builtin.cron:
10490
name: Gets transfer fees for donations
10591
minute: 0
10692
hour: 4
10793
user: "{{ server_user }}"
108-
job: "php {{ install_path }}/kofi_sync_paypal.php"
94+
job: "PAYPAL_CLIENTID={{ paypal_clientid }} PAYPAL_SECRETKEY={{ paypal_secretkey }} php {{ website_path }}/sync_paypal.php"
10995
cron_file: mobileforces-kofi_sync_paypal
96+
97+
- name: Create cron job for cleaning the site
98+
ansible.builtin.cron:
99+
name: Clean the site
100+
minute: 30
101+
hour: 4
102+
weekday: 0
103+
user: "{{ server_user }}"
104+
job: "cd {{ website_path }} && rm -rf donation_log.txt var/cache var/log && php bin/console cache:warmup"
105+
cron_file: mobileforces-clean

0 commit comments

Comments
 (0)