Skip to content

Commit efd6e95

Browse files
committed
fix: workflow yaml location
1 parent b908758 commit efd6e95

File tree

3 files changed

+308
-0
lines changed

3 files changed

+308
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM ubuntu:noble AS build-game
2+
RUN apt-get update && apt-get install -y \
3+
build-essential \
4+
clang \
5+
libcurl4-openssl-dev \
6+
&& rm -rf /var/lib/apt/lists/*
7+
8+
WORKDIR /core
9+
COPY ./server .
10+
11+
RUN make re
12+
13+
FROM ubuntu:noble AS release
14+
RUN apt-get update && apt-get install -y \
15+
libcurl4 \
16+
jq \
17+
curl \
18+
&& rm -rf /var/lib/apt/lists/*
19+
20+
WORKDIR /core
21+
COPY --from=build-game /core/server ./server
22+
COPY --from=build-game /core/data ./data
23+
24+
COPY ./.github/workflows/server-docker-entrypoint.sh ./docker-entrypoint.sh
25+
COPY ./my-core-bot/configs ./configs
26+
27+
RUN mkdir replays && chmod +x ./docker-entrypoint.sh
28+
29+
ENTRYPOINT [ "./docker-entrypoint.sh", "./server", "./configs/server-config.json", "./configs/soft-config.json" ]
30+
CMD [ "--default-arg" ]
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/bin/bash
2+
# Docker entrypoint script for game server
3+
# Conditionally uploads replay and sends results to RabbitMQ based on environment variables
4+
5+
set -euo pipefail
6+
7+
# Configuration
8+
UPLOAD_REPLAY="${UPLOAD_REPLAY:-false}"
9+
SEND_RESULTS="${SEND_RESULTS:-false}"
10+
REPLAY_FILE="${REPLAY_FILE:-./replays/replay_latest.json}"
11+
12+
# Script paths
13+
UPLOAD_SCRIPT="/core/data/scripts/upload_replay_to_s3.sh"
14+
RABBITMQ_SCRIPT="/core/data/scripts/send_misc_to_rabbitmq.sh"
15+
16+
echo "=== Game Server Entrypoint ==="
17+
echo "UPLOAD_REPLAY: $UPLOAD_REPLAY"
18+
echo "SEND_RESULTS: $SEND_RESULTS"
19+
echo "REPLAY_FILE: $REPLAY_FILE"
20+
21+
# Function to run the main game server
22+
run_game_server() {
23+
echo "Starting game server..."
24+
# Run the game server in the background and wait for it
25+
"$@" &
26+
local game_pid=$!
27+
28+
# Wait for the game server to finish
29+
wait $game_pid
30+
local exit_code=$?
31+
32+
echo "Game server finished with exit code: $exit_code"
33+
return $exit_code
34+
}
35+
36+
# Function to handle post-game processing
37+
post_game_processing() {
38+
echo "=== Post-game processing ==="
39+
40+
# Check if replay file exists
41+
if [[ ! -f "$REPLAY_FILE" ]]; then
42+
echo "Warning: Replay file not found: $REPLAY_FILE"
43+
echo "Skipping post-game processing"
44+
return 0
45+
fi
46+
47+
# Upload replay to S3 if enabled
48+
if [[ "$UPLOAD_REPLAY" == "true" ]]; then
49+
echo "Uploading replay to S3..."
50+
if [[ -x "$UPLOAD_SCRIPT" ]]; then
51+
if "$UPLOAD_SCRIPT" "$REPLAY_FILE"; then
52+
echo "✓ Replay upload completed successfully"
53+
else
54+
echo "✗ Replay upload failed"
55+
# Continue processing even if upload fails
56+
fi
57+
else
58+
echo "Error: Upload script not found or not executable: $UPLOAD_SCRIPT"
59+
fi
60+
else
61+
echo "Skipping replay upload (UPLOAD_REPLAY not set to true)"
62+
fi
63+
64+
# Send results to RabbitMQ if enabled
65+
if [[ "$SEND_RESULTS" == "true" ]]; then
66+
echo "Sending results to RabbitMQ..."
67+
if [[ -x "$RABBITMQ_SCRIPT" ]]; then
68+
if "$RABBITMQ_SCRIPT" "$REPLAY_FILE"; then
69+
echo "✓ Results sent to RabbitMQ successfully"
70+
else
71+
echo "✗ Failed to send results to RabbitMQ"
72+
# Continue processing even if RabbitMQ fails
73+
fi
74+
else
75+
echo "Error: RabbitMQ script not found or not executable: $RABBITMQ_SCRIPT"
76+
fi
77+
else
78+
echo "Skipping RabbitMQ results (SEND_RESULTS not set to true)"
79+
fi
80+
81+
echo "=== Post-game processing completed ==="
82+
}
83+
84+
# Validate that required scripts exist if features are enabled
85+
if [[ "$UPLOAD_REPLAY" == "true" && ! -f "$UPLOAD_SCRIPT" ]]; then
86+
echo "Error: UPLOAD_REPLAY is enabled but script not found: $UPLOAD_SCRIPT"
87+
exit 1
88+
fi
89+
90+
if [[ "$SEND_RESULTS" == "true" && ! -f "$RABBITMQ_SCRIPT" ]]; then
91+
echo "Error: SEND_RESULTS is enabled but script not found: $RABBITMQ_SCRIPT"
92+
exit 1
93+
fi
94+
95+
# Make scripts executable if they exist
96+
[[ -f "$UPLOAD_SCRIPT" ]] && chmod +x "$UPLOAD_SCRIPT"
97+
[[ -f "$RABBITMQ_SCRIPT" ]] && chmod +x "$RABBITMQ_SCRIPT"
98+
99+
# Run the main game server with all provided arguments
100+
echo "Running game server with arguments: $*"
101+
if run_game_server "$@"; then
102+
game_exit_code=0
103+
else
104+
game_exit_code=$?
105+
fi
106+
107+
echo "Game server exited with code: $game_exit_code"
108+
109+
# Only run post-game processing if either feature is enabled
110+
if [[ "$UPLOAD_REPLAY" == "true" || "$SEND_RESULTS" == "true" ]]; then
111+
post_game_processing
112+
else
113+
echo "No post-game processing enabled"
114+
fi
115+
116+
echo "Entrypoint script completed"
117+
exit $game_exit_code

.github/workflows/server.yaml

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
name: "server build, push"
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
- dev
9+
pull_request:
10+
11+
env:
12+
REGISTRY_IMAGE: ghcr.io/42core-team/game-server
13+
14+
concurrency:
15+
group: "${{ github.workflow }} @ ${{ github.ref_name }}"
16+
cancel-in-progress: true
17+
18+
jobs:
19+
# Job for pull requests - only compile and test, don't push
20+
test-build:
21+
if: github.event_name == 'pull_request'
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
include:
26+
- architecture: amd64
27+
runner: ubuntu-24.04
28+
platform: linux/amd64
29+
- architecture: arm64
30+
runner: ubuntu-24.04-arm
31+
platform: linux/arm64
32+
33+
runs-on:
34+
- ${{ matrix.runner }}
35+
steps:
36+
- name: Checkout repository
37+
uses: actions/checkout@v4
38+
39+
- name: Set up Docker Buildx
40+
uses: docker/setup-buildx-action@v3
41+
42+
- name: Build (test only)
43+
uses: docker/build-push-action@v6
44+
with:
45+
context: ${{ github.workspace }}
46+
file: .github/workflows/server-Dockerfile
47+
platforms: ${{ matrix.platform }}
48+
push: false
49+
cache-from: type=gha
50+
cache-to: type=gha,mode=max
51+
52+
# Job for pushes to main branches - build and push
53+
build:
54+
if: github.event_name != 'pull_request'
55+
strategy:
56+
fail-fast: false
57+
matrix:
58+
include:
59+
- architecture: amd64
60+
runner: ubuntu-24.04
61+
platform: linux/amd64
62+
- architecture: arm64
63+
runner: ubuntu-24.04-arm
64+
platform: linux/arm64
65+
runs-on:
66+
- ${{ matrix.runner }}
67+
steps:
68+
- name: Checkout repository
69+
uses: actions/checkout@v4
70+
71+
- name: Prepare
72+
run: |
73+
platform=${{ matrix.platform }}
74+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
75+
76+
# - name: Set up QEMU
77+
# uses: docker/setup-qemu-action@v3
78+
79+
- name: Set up Docker Buildx
80+
uses: docker/setup-buildx-action@v3
81+
82+
- name: Docker meta
83+
id: meta
84+
uses: docker/metadata-action@v5
85+
with:
86+
images: ${{ env.REGISTRY_IMAGE }}
87+
88+
- name: Login to GitHub Container Registry
89+
uses: docker/login-action@v3
90+
with:
91+
registry: ghcr.io
92+
username: ${{ github.actor }}
93+
password: ${{ secrets.GITHUB_TOKEN }}
94+
95+
- name: Build and push by digest
96+
id: build
97+
uses: docker/build-push-action@v6
98+
with:
99+
context: ${{ github.workspace }}
100+
file: .github/workflows/server-Dockerfile
101+
platforms: ${{ matrix.platform }}
102+
labels: ${{ steps.meta.outputs.labels }}
103+
tags: ${{ env.REGISTRY_IMAGE }}
104+
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
105+
cache-from: type=gha
106+
cache-to: type=gha,mode=max
107+
108+
- name: Export digest
109+
run: |
110+
mkdir -p ${{ runner.temp }}/digests
111+
digest="${{ steps.build.outputs.digest }}"
112+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
113+
114+
- name: Upload digest
115+
uses: actions/upload-artifact@v4
116+
with:
117+
name: digests-${{ env.PLATFORM_PAIR }}
118+
path: ${{ runner.temp }}/digests/*
119+
if-no-files-found: error
120+
retention-days: 1
121+
122+
merge:
123+
if: github.event_name != 'pull_request'
124+
runs-on: ubuntu-24.04
125+
needs: build
126+
steps:
127+
- name: Download digests
128+
uses: actions/download-artifact@v4
129+
with:
130+
path: ${{ runner.temp }}/digests
131+
pattern: digests-*
132+
merge-multiple: true
133+
134+
- name: Login to GitHub Container Registry
135+
uses: docker/login-action@v3
136+
with:
137+
registry: ghcr.io
138+
username: ${{ github.actor }}
139+
password: ${{ secrets.GITHUB_TOKEN }}
140+
141+
- name: Set up Docker Buildx
142+
uses: docker/setup-buildx-action@v3
143+
144+
- name: Docker meta
145+
id: meta
146+
uses: docker/metadata-action@v5
147+
with:
148+
images: ${{ env.REGISTRY_IMAGE }}
149+
tags: |
150+
type=raw,value=${{ github.ref_name }}
151+
type=raw,value=${{ github.ref_name }}-${{ github.sha }}
152+
153+
- name: Create manifest list and push
154+
working-directory: ${{ runner.temp }}/digests
155+
run: |
156+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
157+
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
158+
159+
- name: Inspect image
160+
run: |
161+
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}

0 commit comments

Comments
 (0)