Skip to content

Commit 9271093

Browse files
committed
Download rulesets when building docker images
1 parent 436629b commit 9271093

3 files changed

Lines changed: 74 additions & 10 deletions

File tree

.github/workflows/push-to-github-packages.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ on:
77
env:
88
REGISTRY: ghcr.io
99
IMAGE_NAME: googuteam/osu-performance-server
10+
RULESET_REPO: GooGuTeam/custom-rulesets
1011

1112
jobs:
1213
build:
1314
runs-on: ubuntu-latest
1415
permissions:
1516
contents: read
1617
packages: write
18+
strategy:
19+
matrix:
20+
rulesets: [ true, false ]
1721

1822
steps:
1923
- name: Checkout repository
@@ -29,15 +33,31 @@ jobs:
2933
username: ${{ github.actor }}
3034
password: ${{ secrets.GITHUB_TOKEN }}
3135

36+
- name: Set Docker tags
37+
id: tags
38+
run: |
39+
if [ "${{ matrix.rulesets }}" = "true" ]; then
40+
echo "TAG_CUSTOM=true" >> $GITHUB_ENV
41+
echo "IMAGE_TAG_SHA=${{ github.sha }}-custom-rulesets" >> $GITHUB_ENV
42+
echo "IMAGE_TAG=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:custom-rulesets" >> $GITHUB_ENV
43+
else
44+
echo "TAG_CUSTOM=false" >> $GITHUB_ENV
45+
echo "IMAGE_TAG_SHA=${{ github.sha }}" >> $GITHUB_ENV
46+
echo "IMAGE_TAG=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_ENV
47+
fi
48+
3249
- name: Build and push Docker image
3350
uses: docker/build-push-action@v5
3451
with:
3552
context: .
3653
file: ./Dockerfile
3754
push: true
38-
tags: |
39-
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
40-
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
4155
platforms: linux/amd64,linux/arm64
4256
cache-from: type=gha
43-
cache-to: type=gha,mode=max
57+
cache-to: type=gha,mode=max
58+
build-args: |
59+
DOWNLOAD_RULESETS=${{ matrix.rulesets }}
60+
RULESET_REPO=${{ env.RULESET_REPO }}
61+
tags: |
62+
${{ env.IMAGE_TAG }}
63+
${{ env.IMAGE_TAG_SHA }}

Dockerfile

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,58 @@ RUN dotnet restore osu-performance-server.sln
1010

1111
COPY PerformanceServer/ PerformanceServer/
1212

13-
RUN dotnet nuget locals all --clear
14-
1513
ARG PUBLISH_CONFIGURATION=Release
1614
RUN dotnet publish PerformanceServer/PerformanceServer.csproj \
1715
-c $PUBLISH_CONFIGURATION \
1816
-o /app/publish
17+
18+
RUN dotnet nuget locals all --clear
1919

2020
# -------- Runtime Stage --------
2121
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
2222
WORKDIR /app
2323

24-
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
24+
ARG RULESET_REPO="GooGuTeam/custom-rulesets"
25+
ENV RULESET_REPO=${RULESET_REPO}
26+
ARG DOWNLOAD_RULESETS=false
27+
ENV DOWNLOAD_RULESETS=${DOWNLOAD_RULESETS}
28+
29+
RUN apt-get update && apt-get install -y curl jq && rm -rf /var/lib/apt/lists/*
30+
31+
VOLUME ["/data"]
2532

2633
ENV ASPNETCORE_URLS=http://0.0.0.0:8080 \
2734
SAVE_BEATMAP_FILES=false \
2835
BEATMAPS_PATH=/data/beatmaps \
2936
RULESETS_PATH=/data/rulesets \
3037
MAX_BEATMAP_FILE_SIZE=5242880
3138

32-
VOLUME ["/data"]
33-
3439
COPY --from=build /app/publish .
3540

41+
RUN mkdir -p /tmp/rulesets && \
42+
if [ "$DOWNLOAD_RULESETS" = "true" ]; then \
43+
echo "Fetching latest release from GitHub repo: $RULESET_REPO"; \
44+
API_URL="https://api.github.com/repos/${RULESET_REPO}/releases/latest"; \
45+
echo "API: $API_URL"; \
46+
ASSETS=$(curl -sL "$API_URL" | jq -r '.assets[] | select(.name | endswith(".dll")) | .browser_download_url'); \
47+
if [ -z "$ASSETS" ]; then \
48+
echo "No DLL assets found in the latest release."; \
49+
else \
50+
echo "$ASSETS" | while read -r url; do \
51+
echo "Downloading $url"; \
52+
curl -L -o "/tmp/rulesets/$(basename "$url")" "$url"; \
53+
done; \
54+
fi; \
55+
else \
56+
echo "Skipping ruleset download."; \
57+
fi
58+
3659
EXPOSE 8080
3760

3861
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
3962
CMD curl http://127.0.0.1:8080 || exit 1
4063

41-
ENTRYPOINT ["dotnet", "PerformanceServer.dll"]
64+
COPY entrypoint.sh /entrypoint.sh
65+
RUN chmod +x /entrypoint.sh
66+
67+
ENTRYPOINT ["/entrypoint.sh"]

entrypoint.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
set -e
3+
4+
mkdir -p /data/rulesets
5+
6+
for f in /tmp/rulesets/*.dll; do
7+
if [ -f "$f" ]; then
8+
dest="/data/rulesets/$(basename "$f")"
9+
if [ ! -f "$dest" ]; then
10+
echo "Copying $(basename "$f") to /data/rulesets"
11+
cp "$f" "$dest"
12+
else
13+
echo "$(basename "$f") already exists, skipping"
14+
fi
15+
fi
16+
done
17+
18+
exec dotnet /app/PerformanceServer.dll

0 commit comments

Comments
 (0)