Skip to content
Open
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
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
COMPOSE_PROJECT_NAME=hlstatsx-community-edition
49 changes: 49 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name-template: 'v$RESOLVED_VERSION 🌈'
tag-template: 'v$RESOLVED_VERSION'
categories:
- title: '🚀 Features'
labels:
- 'feature'
- 'enhancement'
- 'change'
- title: '🐛 Bug Fixes'
labels:
- 'fix'
- 'bug'
- title: '🖊️ Refactors'
labels:
- 'refactor'
- title: '👗 Style'
labels:
- 'style'
- title: '📝 Documentation'
labels:
- 'docs'
- 'documentation'
- title: '🧰 Maintenance'
label: 'chore'
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
version-resolver:
major:
labels:
- 'breaking'
minor:
labels:
- 'feature'
- 'enhancement'
- 'change'
- 'refactor'
patch:
labels:
- 'fix'
- 'bug'
- 'style'
- 'docs'
- 'documentation'
- 'chore'
default: patch
sort-by: title
template: |
## Changes

$CHANGES
189 changes: 189 additions & 0 deletions .github/workflows/ci-master-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
name: ci-master-pr

on:
push:
branches:
- master
tags:
- '**'
pull_request:
branches:
- master

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-test-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-test-

- name: Print buildx and compose
run: |
set -eu
docker buildx ls
docker compose version

- name: Test (integration)
run: |
set -eu
docker compose up --build -d
docker compose -f docker-compose.test.yml up

build:
strategy:
matrix:
variant:
- web-nginx
- web-php
- daemon
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Display system info (linux)
run: |
set -e
hostname
whoami
cat /etc/*release
lscpu
free
df -h
pwd
docker info
docker version

# See: https://github.com/docker/build-push-action/blob/v2.6.1/docs/advanced/cache.md#github-cache
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ matrix.variant }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-${{ matrix.variant }}-
${{ runner.os }}-buildx-

# This step generates the docker tags
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
${{ github.repository }}
# type=ref,event=pr generates tag(s) on PRs only. E.g. 'pr-123-<variant>', 'pr-123-abc0123-<variant>'
# type=ref,event=branch generates tag(s) on branch only. E.g. 'master-<variant>', 'master-abc0123-<variant>'
# type=ref,event=tag generates tag(s) on tags only. E.g. 'v0.0.0-<variant>', 'v0.0.0-abc0123-<variant>'
tags: |
type=ref,suffix=-${{ matrix.variant }},event=pr
type=ref,suffix=-{{sha}}-${{ matrix.variant }},event=pr
type=ref,suffix=-${{ matrix.variant }},event=branch
type=ref,suffix=-{{sha}}-${{ matrix.variant }},event=branch
type=ref,suffix=-${{ matrix.variant }},event=tag
type=ref,suffix=-{{sha}}-${{ matrix.variant }},event=tag
# Disable 'latest' tag
flavor: |
latest=false

- name: Login to Docker Hub registry
# Run on master and tags
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_REGISTRY_USER }}
password: ${{ secrets.DOCKERHUB_REGISTRY_PASSWORD }}

- name: Build (PRs)
# Run on pull requests
if: github.event_name == 'pull_request'
uses: docker/build-push-action@v3
with:
file: Dockerfile.${{ matrix.variant }}
context: '.'
platforms: linux/amd64
push: false
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

- name: Build and push
# Run on master and tags
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v3
with:
file: Dockerfile.${{ matrix.variant }}
context: '.'
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

update-draft-release:
needs: [test, build]
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5
with:
config-name: release-drafter.yml
publish: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

publish-draft-release:
needs: [test, build]
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5
with:
config-name: release-drafter.yml
publish: true
name: ${{ github.ref_name }} # E.g. 'master' or 'v1.2.3'
tag: ${{ github.ref_name }} # E.g. 'master' or 'v1.2.3'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

update-dockerhub-description:
needs: [test, build]
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKERHUB_REGISTRY_USER }}
password: ${{ secrets.DOCKERHUB_REGISTRY_PASSWORD }}
repository: ${{ github.repository }}
short-description: ${{ github.event.repository.description }}
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/.idea
/web/.idea
/.vscode
/.vagrant
/.vscode/*
!/.vscode/launch.json
/.vagrant
/web/hlstatsimg/progress
/web/hlstatsimg/graph
29 changes: 29 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"pathMappings": {
"/web": "${workspaceRoot}/web",
},
"xdebugSettings": {
"max_data": 10000,
"max_children": 10000
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
86 changes: 86 additions & 0 deletions Dockerfile.daemon
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
FROM perl:5.38.0-slim-buster AS base

# Install modules
RUN set -eux; \
apt-get update; \
apt-get install -y build-essential; \
\
cpanm DBI; \
\
# Install DBD::mysql, requires mysql 8. See: https://stackoverflow.com/q/4729722
apt-get update; \
apt-get install -y wget; \
# See: https://dev.mysql.com/downloads/repo/apt/
wget -q https://dev.mysql.com/get/mysql-apt-config_0.8.28-1_all.deb; \
DEBIAN_FRONTEND=noninteractive apt install -y ./mysql-apt-config_*; \
apt-get update; \
apt-get install -y libmysqlclient-dev; \
apt-get install -y libmysqlclient21; \
cpanm DBD::mysql; \
# apt purge --auto-remove -y mysql-community-client; \
# apt purge --auto-remove -y mysql-server; \
apt purge --auto-remove -y libmysqlclient-dev; \
apt purge --auto-remove -y mysql-apt-config; \
rm -fv ./mysql-apt-config_*; \
\
cpanm Geo::IP::PurePerl; \
cpanm GeoIP2::Database::Reader; \
cpanm MaxMind::DB::Reader; \
cpanm Syntax::Keyword::Try; \
\
# Optional modules: Email
cpanm Email::Sender::Simple; \
apt-get purge --auto-remove -y build-essential; \
rm -rf /var/lib/apt/lists/* /root/.cpan/ /root/.cpanm/

# Install tools
RUN set -eux; \
apt-get update; \
apt-get install -y \
procps \
# Cron tools
cron \
curl \
wget \
openssl \
&& rm -rf /var/lib/apt/lists/*

RUN set -eux; \
mkdir -p /scripts /scripts/GeoLiteCity; \
cd /scripts/GeoLiteCity; \
# Download the GeoIP binary. Maxmind discontinued distributing the GeoLite Legacy databases. See: https://support.maxmind.com/geolite-legacy-discontinuation-notice/
# So let's download it from our fork of GeoLiteCity.dat
wget -qO- https://github.com/startersclan/GeoLiteCity-data/raw/c14d99c42446f586e3ca9c89fe13714474921d65/GeoLiteCity.dat > GeoLiteCity.dat; \
chmod 666 GeoLiteCity.dat; \
# Download the GeoIP2 binary. Maxmind discontinued distributing the GeoLite2 databases publicly, so a license key is needed. See: https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-geolite2-databases/
# In order to obtain the secret MAXMIND_LICENSE_KEY, we assume we have a sidecar secrets-server which will serve the secret MAXMIND_LICENSE_KEY at: http://localhost:8000/MAXMIND_LICENSE_KEY
wget -qO- https://cdn.jsdelivr.net/npm/geolite2-city@1.0.0/GeoLite2-City.mmdb.gz > GeoLite2-City.mmdb.gz; \
gzip -d GeoLite2-City.mmdb.gz; \
chmod 666 GeoLite2-City.mmdb; \
ls -al

# Copy scripts and set permissions
COPY scripts /scripts2
RUN set -eux; \
ls /scripts2 | grep -v GeoLiteCity | while read -r i; do mv -v "/scripts2/$i" /scripts; done; \
mv -v /scripts2/GeoLiteCity/* /scripts/GeoLiteCity/; \
rm -rf /scripts2; \
find /scripts; \
find /scripts -type d -exec chmod 750 {} \;; \
find /scripts -type f -exec chmod 640 {} \;; \
find /scripts -type f -name '*.sh' -exec chmod 750 {} \;; \
find /scripts -type f -name '*.pl' -exec chmod 750 {} \;; \
find /scripts -type f -name 'run_*' -exec chmod 750 {} \;;

EXPOSE 27500/udp

STOPSIGNAL SIGINT

WORKDIR /scripts

CMD ["perl", "./hlstats.pl"]

RUN
FROM base AS dev

FROM base AS prod
18 changes: 18 additions & 0 deletions Dockerfile.web-nginx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM nginx:1.21-alpine AS base

WORKDIR /web

FROM base AS dev

FROM base AS prod

# Set permissions for 'nginx' user
# COPY --chown=nginx:nginx --chmod=640 /web /web
COPY ./web /web
RUN set -eux; \
chown -R nginx:nginx /web; \
find /web -type d -exec chmod 750 {} \; ; \
find /web -type f -exec chmod 640 {} \; ;

# Add default configs
COPY config/web/nginx/nginx.conf /etc/nginx/nginx.conf
Loading