PhlexPlexico / G5API

An express API for CS2 Servers using MatchZy and PugSharp to record and manage matches.
MIT License
98 stars 31 forks source link

[BUG]Problems with the start-up docker-compose as a local set up #216

Closed MJPetermann closed 2 years ago

MJPetermann commented 2 years ago

Hi, I'm currently trying to set up a local CS:GO tournament and would therefore like to run the API and web interface locally. I already tried setting both up using the docker-compose.yml the last three days, but ran into issues in the process.

The Error Every time docker compose is run, it displays this error message:

G5API | yarn run v1.22.19 G5API | $ MYSQL_FLAGS="-CONNECT_WITH_DB" db-migrate --env production --config config/production.json db:create get5 G5API | [ERROR] SyntaxError: Unexpected token } in JSON at position 377 G5API | at JSON.parse () G5API | at exports.parse (/Get5API/node_modules/rc/lib/utils.js:15:17) G5API | at addConfigFile (/Get5API/node_modules/rc/index.js:30:20) G5API | at module.exports (/Get5API/node_modules/rc/index.js:46:20) G5API | at module.exports (/Get5API/node_modules/db-migrate/lib/commands/set-default-argv.js:122:47) G5API | at new dbmigrate (/Get5API/node_modules/db-migrate/api.js:75:10) G5API | at Object.module.exports.getInstance (/Get5API/node_modules/db-migrate/index.js:85:10) G5API | at /Get5API/node_modules/db-migrate/bin/db-migrate:32:25 G5API | at /Get5API/node_modules/resolve/lib/async.js:142:25 G5API | at maybeRealpath (/Get5API/node_modules/resolve/lib/async.js:50:9) G5API | error Command failed with exit code 1. G5API | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

What i've tried Due to a similar error in issue #148 I tried using the solutions you gave there, but wasn't successful with that. Here's a list of what I've tried:

Every time I got the same error as shown above, with the only change seen in the unexpected token. It changed position every time I changed values in the docker-compose.yml in front of the SQLUSER in the g5api section. The full docker-compose.yml is attached.

Now, I'm not sure if I can use the G5API in conjunction with the Web interface on a local network without exposing them publicly. So is it possible? I'm sorry if it's a simple issue, I've overlooked or didn't get something clearly written in the docs. I read everything in the docker-compose and configuration section twice or more and still am unsure on if I misunderstood something. Also, I'm neither someone who gets to work with Docker and networking often, nor is English my first language.

the docker-compose.yml

version: "3.7"

services:
  redis:
    image: redis:6
    command: redis-server --requirepass <passRedis>
    container_name: redis
    networks:
      - get5
    restart: always

  get5db:
    image: yobasystems/alpine-mariadb
    container_name: get5db
    restart: always
    networks:
      - get5
    environment:
      - MYSQL_ROOT_PASSWORD=<passMaria>
      - MYSQL_DATABASE=get5
      - MYSQL_USER=get5
      - MYSQL_PASSWORD=<passG5SQL>

  caddy:
    image: lucaslorentz/caddy-docker-proxy:ci-alpine
    container_name: caddy-reverse-proxy
    restart: unless-stopped
    networks:
      - get5
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - 80:80
      - 443:443
    environment:
      - CADDY_INGRESS_NETWORKS=get5

  g5api:
    image: ghcr.io/phlexplexico/g5api:latest
    depends_on:
      - get5db
    container_name: G5API
    networks:
      - get5
    labels:
      caddy: <mydomain>.duckdns.org
      caddy.handle_path: /api/*
      caddy.handle_path.0_reverse_proxy: "{{upstreams 3301}}"
    volumes:
      - ./public:/Get5API/public
    environment:
      - NODE_ENV=production
      - PORT=3301
      - DBKEY=<dbkey>
      - STEAMAPIKEY=<steamapikey>
      - HOSTNAME=https://<mydomain>.duckdns.org
      - SHAREDSECRET=<supersecretsecret>
      - CLIENTHOME=https://<mydomain>.duckdns.org
      - APIURL=https://<mydomain>.duckdns.org/api
      - SQLUSER=get5
      - SQLPASSWORD=<passG5SQL>
      - SQLPORT=3306
      - DATABASE=get5
      - SQLHOST=get5db
      - ADMINS=76561198355583930
      - SUPERADMINS=76561198355583930
      - REDISURL=redis://:<passRedis>@redis:6379
      - REDISTTL=86400
      - USEREDIS=true
      - UPLOADDEMOS=false
      - LOCALOGINS=true
    restart: always

  g5v:
    image: ghcr.io/phlexplexico/g5v:latest
    depends_on:
      - g5api
    container_name: G5V-Front-End
    networks:
      - get5
    restart: always
    labels:
      caddy: <mydomain>.duckdns.org
      caddy.reverse_proxy: "{{upstreams}}"

networks:
  get5:
    external: true
PhlexPlexico commented 2 years ago

Hey there! I'll have some time to hopefully look into this later tonight, but one thing I would try is maybe try using a password without special characters.

IPs will work, you'll just have to remove port 443 so that caddy doesn't attempt to assign an https certificate :) see if that works?

MJPetermann commented 2 years ago

Thank you for your fast answer! The <> are placeholders for the real password. Sorry if that wasn't clear enough. Trying to remove port 443 didn't do anything.

One thing I forgot to mention is that I can access the web interface with Duckdns, but not with just an IP.

PhlexPlexico commented 2 years ago

That is very odd! I'll try and reproduce in my Environment here with docker and my lan IP to see if I can get it working :)

And yeah I know it was replaced, but I'm still unsure about any special characters like !%# may cause issues but I'll try here first and get back to you. Usually when docker is reporting this it's usually something wonky with the compose file

PhlexPlexico commented 2 years ago

Wow, my bad. I ran into this earlier when adjusting my docker-compose file and forgot to commit. LOCALOGINS should be LOCALLOGINS. I've updated the docker-compose file so if you pull you should get the change for it :) apologies for that!

MJPetermann commented 2 years ago

Yeah! That worked. Thank you for your really fast answer. While this issue is resolved, I still have an issue with opening the web-interface with a local IP. It seems like caddy is still redirecting me to https even after removing port 443.

PhlexPlexico commented 2 years ago

Oh! Simple fix, just in the labels -> caddy on g5v and g5api just use http://192.168.1.242, this will disable https I think, and maybe remove 443 from the ports since you're not using it

So it would look something like this! image

image

PhlexPlexico commented 2 years ago

Hey @MJPetermann

Has there been any updates? Note that I think there may be some issues if you're running virtualization (mainly, WSL2), because I think there is a bunch of other firewall/windows work that would have to be done in order to get it to spin up properly, but in any case all my containers were running through HTTP by doing the above setup.

Thanks!

MJPetermann commented 2 years ago

Yes, there's an update! I've got it all running locally. Thank you! Rcon Commands and loading the match config do work, but not the stats/veto data. Is it possible to get that running on a local network? (It all works if set it up with duckdns, but that isn't feasible in the lan-environment of the tournament.)

The errors probably In the game-server's console

L 08/05/2022 - 13:07:32: [G5WS.smx] [ERR] API request failed, HTTP status code: 500
L 08/05/2022 - 13:07:32: [G5WS.smx] [ERR] Response:
{
    "message": "Error on game server.",
    "response": "Not a correct API Key."
}
L 08/05/2022 - 14:03:25: [G5WS.smx] [ERR] API request failed, HTTP status code: 500
L 08/05/2022 - 14:03:25: [G5WS.smx] [ERR] Response:
{
    "message": "Not a correct API Key."
}

In the web-console

GET http://192.168.178.108/api/mapstats/1 404 (Not Found)
GET http://192.168.178.108/api/vetoes/1 404 (Not Found)

In the G5API console

G5API     | 0|G5API  | GET /mapstats/1 404 5.685 ms - 29
G5API     | 0|G5API  | ::ffff:172.18.0.3 - - [05/Aug/2022:14:01:03 +0000] "GET /mapstats/1 HTTP/1.1" 404 29 "http://192.168.178.108/match/1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"
G5API     | 0|G5API  | Not a correct API Key.
G5API     | 0|G5API  | POST /match/1/map/0/update 500 12.519 ms - 36
G5API     | 0|G5API  | ::ffff:172.18.0.3 - - [05/Aug/2022:14:01:10 +0000] "POST /match/1/map/0/update HTTP/1.1" 500 36 "-" "sm-ripext/1.3.1"
G5API     | 0|G5API  | POST /match/1/map/0/player/76561198355583930/update 500 15.520 ms - 36
G5API     | 0|G5API  | ::ffff:172.18.0.3 - - [05/Aug/2022:14:01:10 +0000] "POST /match/1/map/0/player/76561198355583930/update HTTP/1.1" 500 36 "-" "sm-ripext/1.3.1"
G5API     | 0|G5API  | POST /match/1/map/0/player/76561199166843742/update 500 7.009 ms - 36
G5API     | 0|G5API  | ::ffff:172.18.0.3 - - [05/Aug/2022:14:01:10 +0000] "POST /match/1/map/0/player/76561199166843742/update HTTP/1.1" 500 36 "-" "sm-ripext/1.3.1"
G5API     | 0|G5API  | GET /vetoes/1 404 5.666 ms - 30
G5API     | 0|G5API  | ::ffff:172.18.0.3 - - [05/Aug/2022:14:01:13 +0000] "GET /vetoes/1 HTTP/1.1" 404 30 "http://192.168.178.108/match/1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"
G5API     | 0|G5API  | GET /mapstats/1 404 5.719 ms - 29
G5API     | 0|G5API  | ::ffff:172.18.0.3 - - [05/Aug/2022:14:01:13 +0000] "GET /mapstats/1 HTTP/1.1" 404 29 "http://192.168.178.108/match/1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"
G5API     | 0|G5API  | PUT /match/1/map/0/round/1/backup/EQBB94TAMZGZ01254RXYY7F3 500 11.247 ms - 81
G5API     | 0|G5API  | ::ffff:172.18.0.3 - - [05/Aug/2022:14:01:15 +0000] "PUT /match/1/map/0/round/1/backup/EQBB94TAMZGZ01254RXYY7F3 HTTP/1.1" 500 81 "-" "sm-ripext/1.3.1"
G5API     | 0|G5API  | GET /vetoes/1 404 5.533 ms - 30
G5API     | 0|G5API  | ::ffff:172.18.0.3 - - [05/Aug/2022:14:01:23 +0000] "GET /vetoes/1 HTTP/1.1" 404 30 "http://192.168.178.108/match/1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"
G5API     | 0|G5API  | GET /mapstats/1 404 5.457 ms - 29
G5API     | 0|G5API  | ::ffff:172.18.0.3 - - [05/Aug/2022:14:01:23 +0000] "GET /mapstats/1 HTTP/1.1" 404 29 "http://192.168.178.108/match/1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"
G5API     | 0|G5API  | GET /vetoes/1 404 5.512 ms - 30
G5API     | 0|G5API  | ::ffff:172.18.0.3 - - [05/Aug/2022:14:01:33 +0000] "GET /vetoes/1 HTTP/1.1" 404 30 "http://192.168.178.108/match/1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"
PhlexPlexico commented 2 years ago

Hmmm that's very odd. Since you're running docker, I believe you can call the following and retrieve the actual 500 error codes (or what they're outputting) here -

docker container exec -it G5API sh
/Get5API # cd /root/.pm2/logs
~/.pm2/logs # ls -la
total 32
drwxr-xr-x    2 root     root          4096 Aug  9 18:22 .
drwxr-xr-x    5 root     root          4096 Aug  9 18:22 ..
-rw-r--r--    1 root     root             0 Aug  9 18:22 G5API-error-0.log
-rw-r--r--    1 root     root         24208 Aug  9 20:15 G5API-out-0.log
~/.pm2/logs #

If there is any data in G5API-error-0.log that will help debug this. By the sounds of it, it may be curl on the Rest In Pawn extension trying to send data and it may not be working. By any chance are your game servers windows servers?

Thanks!

MJPetermann commented 2 years ago

The error message in G5API-error-0.log is: Not a correct API Key. My game servers are on Linux in a docker container run/managed by pterodactyl.

PhlexPlexico commented 2 years ago

Okay so this is usually because the body of the POST request from the game server are empty, usually. I know there's been issues with this, I think I had reported this here https://github.com/ErikMinekus/sm-ripext/issues/71

You can download the artifacts here for your OS. I think it should fix the error you're having.

I think this is an error on sm-ripext, or any possible firewall rules, which was also mentioned by another user here - https://github.com/PhlexPlexico/G5API/issues/183

Let me know if any of those fix the issues you're running into, but if we need to, we could add in some debug statements in the docker container to check, but I'm almost positive this is the problem that you're running into, since regular RCON commands work, but any sm-ripext calls are failing.

Thanks!

MJPetermann commented 2 years ago

Downloading the artifacts fixed the Issue. I can now see the Veto and matchstats. I'm very thankful for your help. U provided a quick and good solution for all of my Issues. You explained everything perfectly. Thank you:)

PhlexPlexico commented 2 years ago

Any time! Gl with the LAN! 😁