-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
338 additions
and
3 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
.github/workflows/docker-publish-dockermod-dcsserverbot.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ / |
Empty file.
Empty file.
132 changes: 132 additions & 0 deletions
132
docker/src/s6-services/s6-init-dcssb-auto-installer-updater-oneshot/run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
1 change: 1 addition & 0 deletions
1
docker/src/s6-services/s6-init-dcssb-auto-installer-updater-oneshot/type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
oneshot |
1 change: 1 addition & 0 deletions
1
docker/src/s6-services/s6-init-dcssb-auto-installer-updater-oneshot/up
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Empty file.
Empty file.
55 changes: 55 additions & 0 deletions
55
docker/src/s6-services/s6-init-dcssb-auto-start-longrun/run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
longrun |
Oops, something went wrong.