Commit 39cbb9b9 authored by Kai Mallea's avatar Kai Mallea Committed by GitHub
Browse files

Merge pull request #6 from kaimallea/envvars

Use envvars with support for Google Cloud Platform Metadata
parents 068cc9d4 ad0d346c
......@@ -18,6 +18,4 @@ COPY containerfs /
WORKDIR /csgo
EXPOSE 27015/tcp 27020/tcp 27015/udp 27020/udp
CMD ["./start.sh"]
\ No newline at end of file
SHELL := /bin/bash
IMAGE_NAME ?= csgo-server
STEAM_ACCOUNT ?= changeme
......@@ -14,7 +16,10 @@ image: Dockerfile
run:
docker run \
-d \
-P \
-p 27015:27015/tcp \
-p 27015:27015/udp \
-p 27020:27020/udp \
-p 27020:27020/tcp \
-e "SERVER_HOSTNAME=test" \
-e "SERVER_PASSWORD=test" \
-e "RCON_PASSWORD=test" \
......
# csgo
# CSGO
The Dockerfile will build an image for running a Counter-Strike: Global Offensive dedicated server.
The Dockerfile will build an image for running a Counter-Strike: Global Offensive dedicated server in a container.
`start.sh` runs the server when the container starts.
### Build image
The server matchmaking rules live in `containerfs/csgo/csgo/matchmaking.cfg`.
```bash
docker build -t csgo-server .
```
_OR_
```bash
make
```
The game is ~16GB, so the initial build will take a bit to download, depending on your download speed. Subsequent builds on the same machine should take only a few seconds, assuming the initial build image is cached by docker.
Run the server in the background:
### Run a CSGO dedicated server
```bash
docker run \
-d \
-p 27015:27015/tcp \
-p 27015:27015/udp \
-p 27020:27020/udp \
-p 27020:27020/tcp \
-e "SERVER_HOSTNAME=hostname" \
-e "SERVER_PASSWORD=password" \
-e "RCON_PASSWORD=rconpassword" \
-e "STEAM_ACCOUNT=gamelogintoken" \
csgo-server
```
docker run \
-d \
-P \
-e "SERVER_HOSTNAME=test" \
-e "SERVER_PASSWORD=test" \
-e "RCON_PASSWORD=test" \
-e "STEAM_ACCOUNT=$(STEAM_ACCOUNT)" \
_OR_
```bash
make run
```
Valve requires a "Game Login Token" to run public servers. Confusingly, this token is also referred to as a steam account (it gets set on the server using `sv_setsteamaccount`). To get one, visit http://steamcommunity.com/dev/managegameservers. You'll need one for each server.
## Environment variable overrides
Below are the default values for environment variables that control the server configuration. Pass one or more of these to docker using the `-e` argument (example above) to override.
```bash
SERVER_HOSTNAME=An Amazing CSGO Server
SERVER_PASSWORD=changeme
RCON_PASSWORD=changeme
STEAM_ACCOUNT=changeme
CSGO_DIR=/csgo
IP=0.0.0.0
PORT=27015
TICKRATE=128
GAME_TYPE=0
GAME_MODE=1
MAP=de_dust2
MAPGROUP=mg_active
MAXPLAYERS=12
```
Use `docker ps` to see which ports to use, or use `-p` instead of `-P` to override.
\ No newline at end of file
See `containerfs/csgo/start.sh` to understand more. The command-line arguments are at the bottom of the file.
## Adding files, plugins, etc.
The directory `containerfs` (container filesystem) is the equivalent of the root path (`/`). Any files or plugins you want to add, simply put them in the correct paths under `containerfs`, and they will appear in the same location in the container (except `containerfs` will be replaced with `/`).
For example, by default, CSGO is installed in the root path `/csgo` within the docker image. I want my `matchmaking.cfg` file to live in the `cfg` directory, so I put that file in `containerfs/csgo/cfg/` and it appears in the right place inside the docker image (`/csgo/cfg/matchmaking.cfg`).
## Google Compute Engine Metadata
Passing `GOOGLE_METADATA=1` fetches default values for environment variables from Google Compute Engine's Project or Instance Metadata. Right now it defaults to project level, but you can simply override METADATA_URL to point to instance data.
See https://cloud.google.com/compute/docs/storing-retrieving-metadata#querying.
\ No newline at end of file
#!/bin/bash
export METADATA_URL="${METADATA_URL:-http://metadata.google.internal/computeMetadata/v1/project/attributes}"
export SERVER_HOSTNAME="${SERVER_HOSTNAME:-$(curl $METADATA_URL'/SERVER_HOSTNAME?alt=text' -H 'Metadata-Flavor: Google')}"
export SERVER_PASSWORD="${SERVER_PASSWORD:-$(curl $METADATA_URL'/SERVER_PASSWORD?alt=text' -H 'Metadata-Flavor: Google')}"
export RCON_PASSWORD="${RCON_PASSWORD:-$(curl $METADATA_URL'/RCON_PASSWORD?alt=text' -H 'Metadata-Flavor: Google')}"
export STEAM_ACCOUNT="${STEAM_ACCOUNT:-$(curl $METADATA_URL'/STEAM_ACCOUNT?alt=text' -H 'Metadata-Flavor: Google')}"
GOOGLE_METADATA=${GOOGLE_METADATA:-0}
export CSGO_DIR="${CSGO_DIR:-/csgo}"
if [ $GOOGLE_METADATA -eq 1 ]
then
METADATA_URL="${METADATA_URL:-http://metadata.google.internal/computeMetadata/v1/project/attributes}"
get_metadata () {
if [ -z "$1" ]
then
local result=""
else
local result=$(curl --progress-bar "$METADATA_URL/$1?alt=text" -H "Metadata-Flavor: Google")
fi
echo $result
}
export SERVER_HOSTNAME="${SERVER_HOSTNAME:-$(get_metadata SERVER_HOSTNAME)}"
export SERVER_PASSWORD="${SERVER_PASSWORD:-$(get_metadata SERVER_PASSWORD)}"
export RCON_PASSWORD="${RCON_PASSWORD:-$(get_metadata RCON_PASSWORD)}"
export STEAM_ACCOUNT="${STEAM_ACCOUNT:-$(get_metadata STEAM_ACCOUNT)}"
export CSGO_DIR="${CSGO_DIR:-$(get_metadata CSGO_DIR)}"
export IP="${IP:-$(get_metadata IP)}"
export PORT="${PORT:-$(get_metadata PORT)}"
export TICKRATE="${TICKRATE:-$(get_metadata TICKRATE)}"
export GAME_TYPE="${GAME_TYPE:-$(get_metadata GAME_TYPE)}"
export GAME_MODE="${GAME_MODE:-$(get_metadata GAME_MODE)}"
export MAP="${MAP:-$(get_metadata MAP)}"
export MAPGROUP="${MAPGROUP:-$(get_metadata MAPGROUP)}"
export MAXPLAYERS="${MAXPLAYERS:-$(get_metadata MAXPLAYERS)}"
else
export SERVER_HOSTNAME="${SERVER_HOSTNAME:-An Amazing CSGO Server}"
export SERVER_PASSWORD="${SERVER_PASSWORD:-changeme}"
export RCON_PASSWORD="${RCON_PASSWORD:-changeme}"
export STEAM_ACCOUNT="${STEAM_ACCOUNT:-changeme}"
export CSGO_DIR="${CSGO_DIR:-/csgo}"
export IP="${IP:-0.0.0.0}"
export PORT="${PORT:-27015}"
export TICKRATE="${TICKRATE:-128}"
export GAME_TYPE="${GAME_TYPE:-0}"
export GAME_MODE="${GAME_MODE:-1}"
export MAP="${MAP:-de_dust2}"
export MAPGROUP="${MAPGROUP:-mg_active}"
export MAXPLAYERS="${MAXPLAYERS:-12}"
fi
: ${CSGO_DIR:?"ERROR: CSGO_DIR IS NOT SET!"}
cd $CSGO_DIR
......@@ -23,12 +63,12 @@ SERVERCFG
-console \
-usercon \
-game csgo \
-tickrate 128 \
-maxplayers_override 24 \
+game_type 0 \
+game_mode 1 \
+mapgroup mg_active \
+map de_dust2 \
+ip 0.0.0.0 \
+exec matchmaking.cfg \
-tickrate $TICKRATE \
-port $PORT \
-maxplayers_override $MAXPLAYERS \
+game_type $GAME_TYPE \
+game_mode $GAME_MODE \
+mapgroup $MAPGROUP \
+map $MAP \
+ip $IP \
+sv_setsteamaccount $STEAM_ACCOUNT
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment