Skip to content

Commit

Permalink
Merge pull request #11 from startersclan/enhancement/web-add-env-var-…
Browse files Browse the repository at this point in the history
…config-support-for-web-config

Enhancement (web): Add env var config support for `web` config
  • Loading branch information
leojonathanoh committed Oct 30, 2023
2 parents 217b37a + 1a4e169 commit 5bc5f24
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 129 deletions.
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,24 @@ a PHP frontend.

## Usage (docker)

Tag convention: `<version>-<service>` or `<version>-<sha>-<service>`. For instance, for release `v1.2.3` on sha `0abcdef`:
`web` image (See [./web/config.php](./web/config.php) for supported environment variables∑):

- `web` image: `1-web`, `1.2-web`, `1.2.3-web`, `1-0abcdef-web`, `1.2-0abcdef-web`, `1.2.3-0abcdef-web`
- `daemon` image: `1-daemon`, `1.2-daemon`, `1.2.3-daemon`, `1-0abcdef-daemon`, `1.2-0abcdef-daemon`, `1.2.3-0abcdef-daemon`
```sh
docker run --rm -it -e DB_ADDR=db -e DB_NAME=hlstatsxce -e DB_USER=hlstatsxce -e DB_PASS=hlstatsxce -p 80:80 startersclan/hlstatsx-community-edition:1.7.0-web
```

`daemon` image:

```sh
docker run --rm -it -p 80:80 startersclan/hlstatsx-community-edition:1.7.0-web
docker run --rm -it -p 27500:27500/udp startersclan/hlstatsx-community-edition:1.7.0-daemon --help
# Use --help for usage
docker run --rm -it -p 27500:27500/udp startersclan/hlstatsx-community-edition:1.7.0-daemon --db-host=db:3306 --db-name=hlstatsxce --db-username=hlstatsxce --db-password=hlstatsxce #--help
```

∑The tag convention is `<version>-<service>` or `<version>-<sha>-<service>`. For instance, for release `v1.2.3` on sha `0abcdef`:

- `web` image tags: `1-web`, `1.2-web`, `1.2.3-web`, `1-0abcdef-web`, `1.2-0abcdef-web`, `1.2.3-0abcdef-web`
- `daemon` image tags: `1-daemon`, `1.2-daemon`, `1.2.3-daemon`, `1-0abcdef-daemon`, `1.2-0abcdef-daemon`, `1.2.3-0abcdef-daemon`

## Development

```sh
Expand Down Expand Up @@ -88,6 +96,8 @@ docker attach $( docker compose ps -q cstrike )
# CS 1.6 server - Exec into container
docker exec -it $( docker compose ps -q cstrike) bash

# daemon - Exec into container
docker exec -it $( docker compose ps -q daemon ) sh
# web - Exec into container
docker exec -it $( docker compose ps -q web ) sh
# Run awards
Expand Down
105 changes: 0 additions & 105 deletions config/web/config.php

This file was deleted.

3 changes: 3 additions & 0 deletions config/web/usr/local/etc/php-fpm.d/php-fpm.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
; Docs: https://www.php.net/manual/en/install.fpm.configuration.php
[global]
daemonize = no
error_log = /proc/self/fd/2
Expand All @@ -17,6 +18,8 @@ pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.process_idle_timeout = 10s
pm.max_requests = 500
; Enable php to read env vars
clear_env = no
catch_workers_output = yes
decorate_workers_output = no
chdir = /
Expand Down
7 changes: 6 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,16 @@ services:
- type=local,dest=/tmp/.buildx-cache-web,mode=max
volumes:
- ./web:/web
- ./config/web/config.php:/web/config.php:ro # Main config file
# - ./config/web/supervisor.conf:/supervisor.conf:ro
# - ./config/web/etc/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
# - ./config/web/usr/local/etc/php/conf.d/php.ini:/usr/local/etc/php/conf.d/php.ini:ro
# - ./config/web/usr/local/etc/php-fpm.d/php-fpm.conf:/usr/local/etc/php-fpm.d/php-fpm.conf:ro
environment:
- DB_ADDR=db
- DB_NAME=hlstatsxce
- DB_USER=hlstatsxce
- DB_PASS=hlstatsxce
- DB_DEBUG=0
ports:
- 8081:80
- 9000
Expand Down
43 changes: 25 additions & 18 deletions web/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Copyleft (L) 2008-20XX Nicholas Hastings ([email protected])
http://www.hlxcommunity.com
HLstatsX Community Edition is a continuation of
HLstatsX Community Edition is a continuation of
ELstatsNEO - Real-time player and clan rankings and statistics
Copyleft (L) 2008-20XX Malte Bayer ([email protected])
http://ovrsized.neo-soft.org/
Expand All @@ -18,7 +18,7 @@
HLstats - Real-time player and clan rankings and statistics for Half-Life
http://sourceforge.net/projects/hlstats/
Copyright (C) 2001 Simon Garner
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
Expand All @@ -36,54 +36,61 @@
For support and installation notes visit http://www.hlxcommunity.com
*/

if (!defined('IN_HLSTATS')) {
die('Do not access this file directly.');
if (!defined("IN_HLSTATS")) {
die("Do not access this file directly.");
}

function defineVar($name, $default) {
$value = getenv($name) ? getenv($name) : $default;
$value = gettype($default) == 'boolean' && $value == 'false' ? false : $value; // Fix string 'false' becoming true for boolean when using settype
settype($value, gettype($default));
define($name, $value);
}

// DB_ADDR - The address of the database server, in host:port format.
// (You might also try setting this to e.g. ":/tmp/mysql.sock" to
// use a Unix domain socket, if your mysqld is on the same box as
// your web server.)
define("DB_ADDR", 'localhost');
defineVar("DB_ADDR", 'localhost');

// DB_USER - The username to connect to the database as
define("DB_USER", '');
defineVar("DB_USER", '');

// DB_PASS - The password for DB_USER
define("DB_PASS", '');
defineVar("DB_PASS", '');

// DB_NAME - The name of the database
define("DB_NAME", '');
defineVar("DB_NAME", '');

// DB_TYPE - The database server type. Only "mysql" is supported currently
define("DB_TYPE", 'mysql');
defineVar("DB_TYPE", 'mysql');

// default 'utf8mb4'
define("DB_CHARSET", 'utf8mb4');
defineVar("DB_CHARSET", 'utf8mb4');

// default 'utf8mb4_unicode_ci'
define("DB_COLLATE", 'utf8mb4_unicode_ci');
defineVar("DB_COLLATE", 'utf8mb4_unicode_ci');

// DB_PCONNECT - Set to 1 to use persistent database connections. Persistent
// connections can give better performance, but may overload
// the database server. Set to 0 to use non-persistent
// connections.
define("DB_PCONNECT", 0);
defineVar("DB_PCONNECT", 0);

// INCLUDE_PATH - Filesystem path to the includes directory, relative to hlstats.php. This must be specified
// as a relative path.
//
// Under Windows, make sure you use forward slash (/) instead
// of back slash (\) and use absolute paths if you are having any issue.
define("INCLUDE_PATH", './includes');
defineVar("INCLUDE_PATH", './includes');


// PAGE_PATH - Filesystem path to the pages directory, relative to hlstats.php. This must be specified
// as a relative path.
//
// Under Windows, make sure you use forward slash (/) instead
// of back slash (\) and use absolute paths if you are having any issue.
define("PAGE_PATH", './pages');
defineVar("PAGE_PATH", './pages');


// PAGE_PATH - Filesystem path to the hlstatsimg directory, relative to hlstats.php. This must be specified
Expand All @@ -93,13 +100,13 @@
// of back slash (\) and use absolute paths if you are having any issue.
//
// Note: the progress directory under hlstatsimg must be writable!!
define("IMAGE_PATH", './hlstatsimg');
defineVar("IMAGE_PATH", './hlstatsimg');

// How often dynamicly generated images are updated (in seconds)
define("IMAGE_UPDATE_INTERVAL", 300);
defineVar("IMAGE_UPDATE_INTERVAL", 300);

define('GOOGLE_MAPS_API_KEY', "");
defineVar('GOOGLE_MAPS_API_KEY', "");

//define("DB_DEBUG", true);
defineVar("DB_DEBUG", false);

?>

0 comments on commit 5bc5f24

Please sign in to comment.