Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Aterfax committed Apr 25, 2024
1 parent 2b07aa3 commit 42cb27d
Show file tree
Hide file tree
Showing 21 changed files with 338 additions and 3 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/docker-publish-dockermod-dcsserverbot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Build and Publish DCS-World-Dedicated-Server-Docker-Mod-dcsserverbot Image

on:
push:
branches: [main]
schedule:
# * is a special character in YAML so you have to quote this string
- cron: '0 9 * * 6'

workflow_dispatch:

jobs:
build-and-push-docker-image:
name: Build DCS-World-Dedicated-Server-Docker-Mod-dcsserverbot image and push to repositories
runs-on: ubuntu-latest
steps:

- name: Checkout code
uses: actions/checkout@v4

- name: Force permissions fix.
run: sudo apt-get update && sudo apt-get install dos2unix -y && cd docker && bash dos2unix.sh

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

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to Github Packages
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get current date
id: date
run: echo "DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV

- name: Build image and push to Docker Hub and GitHub Container Registry
uses: docker/build-push-action@v5
with:
context: ./docker
file: ./docker/Dockerfile.DockerMod.dcsserverbot
push: true
tags: |
aterfax/dcs-world-dedicated-server-mod-dcsserverbot:latest
ghcr.io/aterfax/dcs-world-dedicated-server-mod-dcsserverbot:latest
aterfax/dcs-world-dedicated-server-mod-dcsserverbot:${{ env.DATE }}
ghcr.io/aterfax/dcs-world-dedicated-server-mod-dcsserverbot:${{ env.DATE }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
37 changes: 37 additions & 0 deletions .github/workflows/docker-test-dockermod-dcsserverbot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build DCS-World-Dedicated-Server-Docker-Mod-dcsserverbot Image

on:
# run it during pull request
pull_request:

workflow_dispatch:

jobs:
# define job to build and publish docker image
build-docker-image:
name: Build DCS-World-Dedicated-Server-Docker-Mod-dcsserverbot image only
# run only when code is compiling and tests are passing
runs-on: ubuntu-latest

# steps to perform in job
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Force permissions fix.
run: sudo apt-get update && sudo apt-get install dos2unix -y && cd docker && bash dos2unix.sh

# setup Docker build action
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Build image only
uses: docker/build-push-action@v5
with:
context: ./docker
file: ./docker/Dockerfile.DockerMod.dcsserverbot
push: false

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ AUTOSTART=0
TIMEOUT=60
# ENABLE_DCS_RETRIBUTION should be 1 or 0 and controls if DCS Retribution will install automatically.
# Requires you have added DOCKER_MODS=aterfax/dcs-world-dedicated-server-mod-retribution:latest to compose file.
ENABLE_DCS_RETRIBUTION=1
ENABLE_DCS_RETRIBUTION=1
# DCS Server Bot requires you have added DOCKER_MODS=aterfax/dcs-world-dedicated-server-mod-dcsserverbot:latest
# DCSSBAUTOINSTALL controls if DCSSB is set to autoinstall AND autoupdate.
DCSSBAUTOINSTALL=0
# DCSSBAUTOSTART controls if DCSSB is set to autostart.
DCSSBAUTOSTART=0
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ services:
- TIMEOUT=${TIMEOUT:-30}
- ENABLE_DCS_RETRIBUTION=${ENABLE_DCS_RETRIBUTION:-0}
- DOCKER_MODS=aterfax/dcs-world-dedicated-server-mod-retribution:latest
- DCSSBAUTOINSTALL=${DCSSBAUTOINSTALL:-0}
- DCSSBAUTOSTART=${DCSSBAUTOSTART:-0}
# DCS Server Bot requires you have added DOCKER_MODS=aterfax/dcs-world-dedicated-server-mod-dcsserverbot:latest
ports:
# Webtop WebGUI ports
- '3000:3000/tcp' # Webtop HTTP port - TCP only.
Expand Down
5 changes: 5 additions & 0 deletions docker-compose/Dedicated-Server-Postgres-Adminer/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ TIMEOUT=60
# ENABLE_DCS_RETRIBUTION should be 1 or 0 and controls if DCS Retribution will install automatically.
# Requires you have added DOCKER_MODS=aterfax/dcs-world-dedicated-server-mod-retribution:latest to compose file.
ENABLE_DCS_RETRIBUTION=0
# DCS Server Bot requires you have added DOCKER_MODS=aterfax/dcs-world-dedicated-server-mod-dcsserverbot:latest
# DCSSBAUTOINSTALL controls if DCSSB is set to autoinstall AND autoupdate.
DCSSBAUTOINSTALL=0
# DCSSBAUTOSTART controls if DCSSB is set to autostart.
DCSSBAUTOSTART=0

POSTGRES_USER=DCSServerBot
POSTGRES_PASSWORD=123123123123
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ services:
- ENABLE_DCS_RETRIBUTION=${ENABLE_DCS_RETRIBUTION:-0}
# ENABLE_DCS_RETRIBUTION also requires the DOCKER_MODS Environment variable set as below to function
# DOCKER_MODS=aterfax/dcs-world-dedicated-server-mod-retribution:latest
- DCSSBAUTOINSTALL=${DCSSBAUTOINSTALL:-0}
- DCSSBAUTOSTART=${DCSSBAUTOSTART:-0}
# DCS Server Bot requires you have added DOCKER_MODS=aterfax/dcs-world-dedicated-server-mod-dcsserverbot:latest
ports:
# Webtop WebGUI ports
- '3000:3000/tcp' # Webtop HTTP port - TCP only.
Expand Down
7 changes: 6 additions & 1 deletion docker-compose/Dedicated-Server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ AUTOSTART=0
TIMEOUT=60
# ENABLE_DCS_RETRIBUTION should be 1 or 0 and controls if DCS Retribution will install automatically.
# Requires you have added DOCKER_MODS=aterfax/dcs-world-dedicated-server-mod-retribution:latest to compose file.
ENABLE_DCS_RETRIBUTION=0
ENABLE_DCS_RETRIBUTION=0
# DCS Server Bot requires you have added DOCKER_MODS=aterfax/dcs-world-dedicated-server-mod-dcsserverbot:latest
# DCSSBAUTOINSTALL controls if DCSSB is set to autoinstall AND autoupdate.
DCSSBAUTOINSTALL=0
# DCSSBAUTOSTART controls if DCSSB is set to autostart.
DCSSBAUTOSTART=0
3 changes: 3 additions & 0 deletions docker-compose/Dedicated-Server/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ services:
- ENABLE_DCS_RETRIBUTION=${ENABLE_DCS_RETRIBUTION:-0}
# ENABLE_DCS_RETRIBUTION also requires the DOCKER_MODS Environment variable set as below to function
# DOCKER_MODS=aterfax/dcs-world-dedicated-server-mod-retribution:latest
- DCSSBAUTOINSTALL=${DCSSBAUTOINSTALL:-0}
- DCSSBAUTOSTART=${DCSSBAUTOSTART:-0}
# DCS Server Bot requires you have added DOCKER_MODS=aterfax/dcs-world-dedicated-server-mod-dcsserverbot:latest
ports:
# Webtop WebGUI ports
- '3000:3000/tcp' # Webtop HTTP port - TCP only.
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ FROM lscr.io/linuxserver/webtop:latest
LABEL maintainer="Aterfax"

# Wine 64Bit for running EXE
RUN apk add --no-cache wine freetype wget cabextract xdotool xdg-utils xvfb xvfb-run git python3 python3-dev py3-pip 7zip make cmake gcc g++ gfortran innoextract
RUN apk add --no-cache wine freetype wget cabextract xdotool xdg-utils xvfb xvfb-run git python3 python3-dev py3-pip 7zip make cmake gcc g++ gfortran innoextract build-base linux-headers

# Download the latest winetricks script (master="latest version") from Github.
RUN wget https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks && chmod +x winetricks
Expand Down
25 changes: 25 additions & 0 deletions docker/Dockerfile.DockerMod.dcsserverbot
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# DCS-World-Dedicated-Server-Docker-Mod-DCSServerBot Dockerfile.
# aterfax/dcs-world-dedicated-server-mod-dcsserverbot
#
# We need busybox or we have no shell commands.
FROM busybox AS buildstage

# Ensure the s6 user contents.d folder exists prior to touch
RUN mkdir -p /root-layer/etc/s6-overlay/s6-rc.d/user/contents.d/

# Add the s6 scripting / helper functions for DCSServerBot auto install and update.
COPY ./src/s6-services/s6-init-dcssb-auto-installer-updater-oneshot /root-layer/etc/s6-overlay/s6-rc.d/init-dcssb-auto-installer-updater-oneshot
RUN touch /root-layer/etc/s6-overlay/s6-rc.d/user/contents.d/init-dcssb-auto-installer-updater-oneshot

# Add start dependency to server autostart to ensure DCSServerBot is installed before start.
COPY ./src/s6-services/s6-init-dcssb-auto-start-longrun /root-layer/etc/s6-overlay/s6-rc.d/init-dcssb-auto-start-longrun
RUN touch /root-layer/etc/s6-overlay/s6-rc.d/user/contents.d/init-dcssb-auto-start-longrun

FROM scratch
LABEL maintainer="Aterfax"

# Add files from buildstage - note you can only run a single command here.
# Subsequent COPY commands will add new layers which will be ignored by
# the container.
COPY --from=buildstage /root-layer/ /
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash

# Source the log helper after setting the prefix
log_prefix="s6-init-dcssb-auto-installer-updater-oneshot"
source /app/dcs_server/logger_function

handle_error() {
local exit_code="$?"
echo -e "Error occurred (Exit code: $exit_code)"
exit "$exit_code"
}
trap handle_error ERR

# Check if DCSSBAUTOINSTALL environment variable is set to 1
if [ "${DCSSBAUTOINSTALL}" != "1" ]; then
echo "DCSSBAUTOINSTALL is not set to 1. Exiting."
exit 0
fi

# Set the directory path
repo_dir="/config/DCSServerBot"

# Set the Git repository URL
repo_url="https://github.com/Special-K-s-Flightsim-Bots/DCSServerBot.git"

# Needed to export into the EOF subshell.
export repo_dir
export repo_url

if [ -d "$repo_dir" ]; then
# Ensure that the repo folder is owned by the user from the container.
lsiown -R abc:users $repo_dir
fi

# Note single quotes 'EOF' to prevent variable expansion.
sudo -E -u abc bash <<'EOF'
# Function to clone Git repository
clone_git_repo() {
local repo_url="$1"
local repo_dir="$2"
echo "Cloning Git repository to $repo_dir..."
git clone "$repo_url" "$repo_dir"
}
# Check if the directory exists
if [ -d "$repo_dir" ]; then
# Check if it's a Git repository
# Change to the directory
cd "$repo_dir" || exit 1
# Check if it's a Git repository
if git rev-parse --git-dir > /dev/null 2>&1; then
# It's a Git repository, check if it matches the specified URL
remote_url=$(git config --get remote.origin.url)
if [ "$remote_url" == "$repo_url" ]; then
# It's the correct Git repository, pull the latest changes
echo "Correct Git repository found. Pulling the latest changes..."
git pull
else
# It's not the correct Git repository, show an error message
echo "Error: The existing Git repository does not match the specified URL."
echo "Exiting."
exit 1
fi
else
# It's not a Git repository, check if it's empty
if [ -z "$(ls -A)" ]; then
# It's an empty directory, call the function to clone the Git repository
clone_git_repo "$repo_url" "$repo_dir"
else
# It's not an empty directory, show an error message
echo "Error: The directory exists but is not a Git repository, and it is not empty."
echo "Exiting."
exit 1
fi
fi
else
# Directory doesn't exist, call the function to clone the Git repository
echo "Installing DCSSB."
clone_git_repo "$repo_url" "$repo_dir"
fi
# Now ensure that Python is installed.
download_python() {
local MAX_RETRIES=3
local RETRY_COUNT=0
local URL="https://www.python.org/ftp/python/3.11.6/python-3.11.6-amd64.exe"
local DOWNLOAD_PATH="/config/python-3.11.6-amd64.exe"
local MD5SUM="4a501c073d0d688c033d43f85e22d77e"
local INSTALL_PATH="/config/.wine/drive_c/users/abc/AppData/Local/Programs/Python/Python311/"
# Check if the installation directory exists
if [ ! -d "$INSTALL_PATH" ]; then
while [ "$RETRY_COUNT" -lt "$MAX_RETRIES" ]; do
echo -e "Python installation not found. Downloading..."
wget --progress=bar:force -O "$DOWNLOAD_PATH" "$URL" || true
DOWNLOADED_MD5SUM=$(md5sum "$DOWNLOAD_PATH" | awk '{print $1}')
# Check if the MD5 checksum matches
if [ "$DOWNLOADED_MD5SUM" == "$MD5SUM" ]; then
echo -e "Download successful. MD5 checksum matches."
# Invoke the installer with Wine
wine "$DOWNLOAD_PATH" /quiet InstallAllUsers=0 PrependPath=1 Include_test=0
break
else
echo -e "Download failed. MD5 checksum does not match. Retrying in 5 seconds..."
RETRY_COUNT=$((RETRY_COUNT + 1))
sleep 5
fi
done
if [ "$RETRY_COUNT" -ge "$MAX_RETRIES" ]; then
echo -e "Download retry count exceeded. Downloading failed."
fi
else
echo -e "Python is already installed at: $INSTALL_PATH"
fi
}
# Call the function
download_python
EOF

exit 0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/init-dcssb-auto-installer-updater-oneshot/run
Empty file.
55 changes: 55 additions & 0 deletions docker/src/s6-services/s6-init-dcssb-auto-start-longrun/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash

# Source the log helper after setting the prefix
log_prefix="s6-init-dcssb-auto-start-longrun"
source /app/dcs_server/logger_function

handle_error() {
local exit_code="$?"
echo -e "Error occurred (Exit code: $exit_code)"
exit "$exit_code"
}
trap handle_error ERR

# Get / set env vars and timeout value for server check interval.
DCSSBAUTOSTART="${DCSSBAUTOSTART:-0}"
TIMEOUT="${TIMEOUT:-30}"

# Check if DCSSBAUTOINSTALL environment variable is set to 1
if [ "${DCSSBAUTOSTART}" != "1" ]; then
echo "DCSSBAUTOSTART is not set to 1. Exiting."
exit 0
fi

# Set the directory path
repo_dir="/config/DCSServerBot"

while true; do
startup_iterator=1
pid=""
if [ $startup_iterator -eq 1 ]; then
echo "Starting DCSSB Server"
cd /config/DCSServerBot/
sudo -E -u abc bash -c 'wine /config/DCSServerBot/run.cmd' &
pid=$! # This grabs the PID of the running DCSSB process and keeps it for later if needed.
echo "Server PID="$pid
startup_iterator=0
#echo "Sleeping: $TIMEOUT"
sleep $TIMEOUT
fi

while true; do
# Check if the service is still alive.
if ps -p "$pid" > /dev/null; then
echo "############### Server still running. ###############" $(date +"%d-%m-%y-%T")
#echo "Sleeping: $TIMEOUT"
sleep $TIMEOUT
else
startup_iterator=1
restarts=$((restarts + 1))
break # Restart server
fi
done
done

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Loading

0 comments on commit 42cb27d

Please sign in to comment.