Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Docker images for HttpsProxy and PresenceServer #660

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,40 @@ jobs:
permissions:
contents: read
packages: write
strategy:
matrix:
service:
- name: GameServer
dockerfile: Dockerfile
container_id: refresh
- name: HttpsProxy
dockerfile: HttpsProxy.Dockerfile
container_id: refresh-httpsproxy
- name: PresenceServer
dockerfile: PresenceServer.Dockerfile
container_id: refresh-presenceserver
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
uses: docker/login-action@v3.3.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step below will fill in things like name, description, etc. from the repository.
# It's helpful for us because it also fills in the version information automatically depending on how the job was invoked.
# See https://github.com/docker/metadata-action#basic
- name: Extract metadata (tags, labels) for Docker
- name: Extract metadata for ${{ matrix.service.name }}
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
uses: docker/metadata-action@v5.5.1
with:
images: ghcr.io/littlebigrefresh/refresh
- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
images: ghcr.io/${{ github.repository_owner }}/${{ matrix.service.container_id }}
- name: Build and push ${{ matrix.service.name }}
uses: docker/build-push-action@v6.7.0
with:
context: .
file: ${{ matrix.service.dockerfile }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build stage
FROM mcr.microsoft.com/dotnet/sdk:8.0.203-bookworm-slim AS build
FROM mcr.microsoft.com/dotnet/sdk:8.0.401-1-bookworm-slim AS build
WORKDIR /build

COPY *.sln ./
Expand All @@ -19,7 +19,7 @@ RUN dotnet publish Refresh.GameServer -c Release --property:OutputPath=/build/pu

# Final running container

FROM mcr.microsoft.com/dotnet/runtime:8.0.3-bookworm-slim AS final
FROM mcr.microsoft.com/dotnet/runtime:8.0.8-bookworm-slim AS final

# Add non-root user
RUN set -eux && \
Expand All @@ -36,6 +36,9 @@ COPY --from=build /build/publish/publish /refresh/app
COPY --from=build /build/scripts/docker-entrypoint.sh /refresh

RUN chown -R refresh:refresh /refresh && \
chmod +x /refresh/docker-entrypoint.sh
chmod +x /refresh/docker-entrypoint.sh

ENTRYPOINT ["/refresh/docker-entrypoint.sh"]
ENV PRIV_CMD gosu
ENV PRIV_USER refresh

ENTRYPOINT ["/refresh/docker-entrypoint.sh", "GameServer"]
42 changes: 42 additions & 0 deletions HttpsProxy.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Build stage
FROM mcr.microsoft.com/dotnet/sdk:8.0.401-1-alpine3.20 AS build
WORKDIR /build

COPY *.sln ./
COPY **/*.csproj ./

RUN dotnet sln list | grep ".csproj" \
| while read -r line; do \
mkdir -p $(dirname $line); \
mv $(basename $line) $(dirname $line); \
done;

RUN dotnet restore --use-current-runtime

COPY . .

RUN dotnet publish Refresh.HttpsProxy -c Release --property:OutputPath=/build/publish/ --no-restore --no-self-contained

# Final running container

FROM mcr.microsoft.com/dotnet/runtime:8.0.8-alpine3.20 AS final

# Add non-root user
RUN set -eux && \
apk add --no-cache su-exec && \
su-exec nobody true && \
addgroup -g 1001 refresh && \
adduser -D -h /refresh -u 1001 -G refresh refresh && \
mkdir -p /refresh/data && \
mkdir -p /refresh/app

COPY --from=build /build/publish/publish /refresh/app
COPY --from=build /build/scripts/docker-entrypoint.sh /refresh

RUN chown -R refresh:refresh /refresh && \
chmod +x /refresh/docker-entrypoint.sh

ENV PRIV_CMD su-exec
ENV PRIV_USER refresh:refresh

ENTRYPOINT ["/refresh/docker-entrypoint.sh", "HttpsProxy"]
42 changes: 42 additions & 0 deletions PresenceServer.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Build stage
FROM mcr.microsoft.com/dotnet/sdk:8.0.401-1-alpine3.20 AS build
WORKDIR /build

COPY *.sln ./
COPY **/*.csproj ./

RUN dotnet sln list | grep ".csproj" \
| while read -r line; do \
mkdir -p $(dirname $line); \
mv $(basename $line) $(dirname $line); \
done;

RUN dotnet restore --use-current-runtime

COPY . .

RUN dotnet publish Refresh.PresenceServer -c Release --property:OutputPath=/build/publish/ --no-restore --no-self-contained

# Final running container

FROM mcr.microsoft.com/dotnet/runtime:8.0.8-alpine3.20 AS final

# Add non-root user
RUN set -eux && \
apk add --no-cache su-exec && \
su-exec nobody true && \
addgroup -g 1001 refresh && \
adduser -D -h /refresh -u 1001 -G refresh refresh && \
mkdir -p /refresh/data && \
mkdir -p /refresh/app

COPY --from=build /build/publish/publish /refresh/app
COPY --from=build /build/scripts/docker-entrypoint.sh /refresh

RUN chown -R refresh:refresh /refresh && \
chmod +x /refresh/docker-entrypoint.sh

ENV PRIV_CMD su-exec
ENV PRIV_USER refresh:refresh

ENTRYPOINT ["/refresh/docker-entrypoint.sh", "PresenceServer"]
31 changes: 29 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3'
services:
gameserver:
image: refresh:latest
Expand All @@ -16,4 +15,32 @@ services:
interval: 5s
retries: 5
volumes:
- "./data:/refresh/data:z"
- "./data/gameserver:/refresh/data:z"
httpsproxy:
image: refresh-httpsproxy:latest
container_name: refresh-httpsproxy
build:
context: .
dockerfile: HttpsProxy.Dockerfile
restart: unless-stopped
ports:
- "10061:10061"
environment:
BUNKUM_DATA_FOLDER: /refresh/data
volumes:
- "./data/httpsproxy:/refresh/data:z"
profiles: ["optional-services"]
presenceserver:
image: refresh-presenceserver:latest
container_name: refresh-presenceserver
build:
context: .
dockerfile: PresenceServer.Dockerfile
restart: unless-stopped
ports:
- "10072:10072"
environment:
jvyden marked this conversation as resolved.
Show resolved Hide resolved
BUNKUM_DATA_FOLDER: /refresh/data
volumes:
- "./data/presenceserver:/refresh/data:z"
profiles: ["optional-services"]
5 changes: 2 additions & 3 deletions scripts/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
# so it must be changed again during the entrypoint
chown -R refresh:refresh /refresh/data

cd /refresh/data

exec gosu refresh /refresh/app/Refresh.GameServer
cd /refresh/data || exit $?

exec $PRIV_CMD "$PRIV_USER" "/refresh/app/Refresh.$1"
exit $? # Expose error code
Loading