FROM ubuntu:18.04

LABEL Name=docker-steamcmd Version=1.5.0 Maintainer="Dave Jansen - Pretty Basic"

## Defaults
# Note: Query Port cannot be between 27020 and 27050 due to Steam using those ports.
ENV \
  PORT_STEAM=27015 \
  STEAMCMD_URL="https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz" \
  USER_STEAM_ID=1000 \
  DIR_STEAMCMD=/opt/steamcmd \
  DIR_GAME=/opt/game \
  DIR_USER=/opt/user \
  DIR_APP=/opt/app

# Start by updating and installing the required packages
RUN set -ex; \
  apt-get -y update; \
  apt-get -y upgrade; \
  apt-get install -y curl lib32gcc1; \
  rm -rf /var/lib/{apt,dpkg,cache,log}/;

# Create a user and usergroup for Steam, and adjust open file limitations.
# This is required for certain games, so let's set it by default
RUN \
  ulimit -n 100000; \
  set -ex; \
  addgroup \
    -gid ${USER_STEAM_ID} \
    steam; \
  adduser \
	  --disabled-login \
	  --shell /bin/bash \
  	--gecos "" \
    --gid ${USER_STEAM_ID} \
    --uid ${USER_STEAM_ID} \
	  steam; \ 
  mkdir -p ${DIR_STEAMCMD} ${DIR_GAME} ${DIR_USER} ${DIR_APP}; \
  cd $DIR_STEAMCMD; \
  curl -sqL ${STEAMCMD_URL} | tar zxfv -; \
  chown -R steam:steam ${DIR_STEAMCMD} ${DIR_GAME} ${DIR_USER} ${DIR_APP};

# Make sure everything is run as the Steam user from the steam dir
USER steam
WORKDIR ${DIR_STEAMCMD}

# Announce the default Steam ports
# Note: You should open game-specific port too.
EXPOSE ${PORT_STEAM}/udp

# Optional: Initial run with anonymous login
# This should stay disabled when using Docker Hub to auto-build, for example
# RUN [ "./steamcmd.sh", "+@NoPromptForPassword 1", "+login anonymous",  "+quit" ]

ENTRYPOINT [ "./steamcmd.sh" ]
