From e419cabe09a5b19ee700e8eb0ced67b2657c629b Mon Sep 17 00:00:00 2001 From: Pauli Jokela Date: Mon, 1 Aug 2016 11:09:50 +0300 Subject: [PATCH] Initial commit --- .dockerignore | 7 +++++ .gitignore | 42 ++++++++++++++++++++++++++++++ Dockerfile | 55 ++++++++++++++++++++++++++++++++++++++++ README.md | 24 ++++++++++++++++++ docker_build.sh | 3 +++ docker_build_force.sh | 3 +++ docker_push.sh | 4 +++ docker_run.sh | 8 ++++++ install.txt | 6 +++++ start_starbound.sh | 59 +++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 211 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 README.md create mode 100755 docker_build.sh create mode 100755 docker_build_force.sh create mode 100755 docker_push.sh create mode 100755 docker_run.sh create mode 100755 install.txt create mode 100755 start_starbound.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ba0230f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +.env +*.log +starbound_data +.DS_Store +docker_*.sh +.git/ +.git* diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f2af4f8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,42 @@ +.env +starbound_data/ + +# Docker project generated files to ignore +# if you want to ignore files created by your editor/tools, +# please consider a global .gitignore https://help.github.com/articles/ignoring-files +*.exe +*.exe~ +*.orig +*.rej +*.test +.*.swp +.DS_Store +.bashrc +.dotcloud +.flymake* +.git/ +.gopath/ +.hg/ +.vagrant* +Vagrantfile +a.out +autogen/ +bin +build_src +bundles/ +docker/docker +dockerversion/version_autogen.go +docs/AWS_S3_BUCKET +docs/GITCOMMIT +docs/GIT_BRANCH +docs/VERSION +docs/_build +docs/_static +docs/_templates +docs/changed-files +# generated by man/md2man-all.sh +man/man1 +man/man5 +man/man8 +pyenv +vendor/pkg/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..09208bb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,55 @@ +FROM ubuntu:16.04 + +MAINTAINER didstopia + +# Setup the locales +RUN locale-gen en_US.UTF-8 +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US:en +ENV LC_ALL en_US.UTF-8 + +# Fixes apt-get warnings +ENV DEBIAN_FRONTEND noninteractive + +# Run a quick apt-get update/upgrade +RUN apt-get update && apt-get upgrade -y && apt-get dist-upgrade -y && apt-get autoremove -y + +# Install dependencies, mainly for SteamCMD +RUN apt-get install -y \ + ca-certificates \ + software-properties-common \ + python-software-properties \ + lib32gcc1 \ + libstdc++6 \ + curl \ + wget \ + libvorbisfile3 + +# Run as root +USER root + +# Create and set the steamcmd folder as a volume +RUN mkdir -p /steamcmd/starbound +VOLUME ["/steamcmd/starbound"] + +# Add the steamcmd installation script +ADD install.txt /install.txt + +# Copy the startup script +ADD start_starbound.sh /start.sh + +# Set the current working directory +WORKDIR / + +# Expose necessary ports +EXPOSE 21025/tcp + +# Setup default environment variables for the server +ENV STEAM_USERNAME "" +ENV STEAM_PASSWORD "" + +# Cleanup +ENV DEBIAN_FRONTEND newt + +# Start the server +ENTRYPOINT ["./start.sh"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..b9e39ed --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# Starbound server that runs inside a Docker container + +**NOTE**: This image will install/update on startup. The path ```/steamcmd/starbound``` can be mounted on the host for data persistence. + +# How to run the server +1. Set the environment variables you wish to modify from below (note the Steam credentials) +2. Optionally mount ```/steamcmd/starbound``` somewhere on the host or inside another container to keep your data safe +3. Enjoy! + +*Be sure to edit `starbound_server.config` to further customize your installation.* + +The following environment variables are available: +``` +STEAM_USERNAME (DEFAULT: "" - Required for installing/updating Starbound) +STEAM_PASSWORD (DEFAULT: "" - Required for installing/updating Starbound) +``` + +# Updating the server + +As long as you have both your `STEAM_USERNAME` and `STEAM_PASSWORD` set, simply restarting the container should trigger the update procedure. + +# Anything else + +If you need help, have questions or bug submissions, feel free to contact me **@Dids** on Twitter. diff --git a/docker_build.sh b/docker_build.sh new file mode 100755 index 0000000..f7f513f --- /dev/null +++ b/docker_build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +docker build -t didstopia/starbound-server:latest . diff --git a/docker_build_force.sh b/docker_build_force.sh new file mode 100755 index 0000000..f65ff69 --- /dev/null +++ b/docker_build_force.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +docker build --no-cache -t didstopia/starbound-server:latest . diff --git a/docker_push.sh b/docker_push.sh new file mode 100755 index 0000000..f6f1cbe --- /dev/null +++ b/docker_push.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +docker tag didstopia/starbound-server:latest didstopia/starbound-server:latest +docker push didstopia/starbound-server:latest \ No newline at end of file diff --git a/docker_run.sh b/docker_run.sh new file mode 100755 index 0000000..b95b9e2 --- /dev/null +++ b/docker_run.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +./docker_build.sh + +# Run a vanilla server +docker run -p 0.0.0.0:21025:21025/tcp --env-file .env -v $(pwd)/starbound_data:/steamcmd/starbound --name starbound-server -d didstopia/starbound-server:latest + +docker logs -f starbound-server diff --git a/install.txt b/install.txt new file mode 100755 index 0000000..85729e9 --- /dev/null +++ b/install.txt @@ -0,0 +1,6 @@ +@sSteamCmdForcePlatformType linux +login anonymous +force_install_dir /steamcmd/starbound +app_info_update 1 +app_update 211820 validate +quit diff --git a/start_starbound.sh b/start_starbound.sh new file mode 100755 index 0000000..c1bee42 --- /dev/null +++ b/start_starbound.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash + +# Define the exit handler +exit_handler() +{ + echo "Shutdown signal received" + kill -SIGINT "$child" +} + +# Trap specific signals and forward to the exit handler +trap 'exit_handler' SIGHUP SIGINT SIGQUIT SIGTERM + +# Create the necessary folder structure +if [ ! -d "/steamcmd/starbound/linux" ]; then + echo "Creating folder structure.." + mkdir -p /steamcmd/starbound/linux +fi + +# Install/update steamcmd +echo "Installing/updating steamcmd.." +curl -s http://media.steampowered.com/installer/steamcmd_linux.tar.gz | tar -v -C /steamcmd -zx + +# Check that username and password are both set +if [ ! -z "$STEAM_USERNAME" ] || [ ! -z "$STEAM_PASSWORD" ]; then + # Setup username/password for Steam + sed -i "s/login anonymous/login $STEAM_USERNAME $STEAM_PASSWORD/g" /install.txt +fi + +# Check that Starbound exists in the first place +if [ ! -f "/steamcmd/starbound/linux/starbound_server" ]; then + # Check that username and password are both set, otherwise quit with error + if [ -z "$STEAM_USERNAME" ] || [ -z "$STEAM_PASSWORD" ]; then + echo "Error: you must set both your Steam username and password to install the server" + exit 1 + fi + # Install Starbound from install.txt + echo "Installing/updating Starbound.." + bash /steamcmd/steamcmd.sh +runscript /install.txt +else + # Check that username and password are both set, otherwise skip update + if [ -z "$STEAM_USERNAME" ] || [ -z "$STEAM_PASSWORD" ]; then + echo "Steam username or password not set, skipping update.." + exit 1 + else + # Install Starbound from install.txt + echo "Installing Starbound.." + bash /steamcmd/steamcmd.sh +runscript /install.txt + fi +fi + +# Set the working directory +cd /steamcmd/starbound/linux + +# Run the server +echo "Starting Starbound.." +./starbound_server 2>&1 & + +child=$! +wait "$child"