Преглед изворни кода

ci: build server image without needing to export

Bryan Lee пре 1 година
родитељ
комит
52ff115e35
3 измењених фајлова са 68 додато и 8 уклоњено
  1. 8 2
      README.md
  2. 59 5
      build/server/Dockerfile
  3. 1 1
      build/server/README.md

+ 8 - 2
README.md

@@ -10,11 +10,17 @@ We use a central Linux server that serves as the first contact for game clients.
 
 Refer to the [server setup document](server/README.md).
 
-## Authentication Server
+## Authentication
 
 Different platforms require different authentication strategies, including Steam, Apple Game Center, Google Play Games Services, and OAuth 2.0. All authentication strategies are consolidated and managed by our authentication server.
 
-Refer to the [authentication document](project/authentication/README.md).
+Refer to the [client-side authentication document](project/authentication/README.md) or the [authentication server document](authentication/README.md).
+
+An NGINX proxy provides TLS by forwarding ports defined below:
+
+| Internal service port | External port with TLS | Protocol | Description             |
+| --------------------- | ---------------------- | -------- | ----------------------- |
+| `18000`               | `8000`                 | HTTP     | The authentication API. |
 
 ## Game Server
 

+ 59 - 5
build/server/Dockerfile

@@ -1,15 +1,69 @@
-FROM ubuntu:20.04
+# syntax=docker/dockerfile:1
+
+################################################################################
+# Create a stage for downloading the engine and templates.
+FROM debian:bullseye-slim AS prebuild
+
+WORKDIR /build
+
+ARG GODOT_ENGINE_URL=https://downloads.tuxfamily.org/godotengine/4.2/Godot_v4.2-stable_linux.x86_64.zip
+ARG GODOT_EXPORT_TEMPLATES_URL=https://downloads.tuxfamily.org/godotengine/4.2/Godot_v4.2-stable_export_templates.tpz
+
+RUN apt-get update && apt-get -qq -y install curl unzip
+
+# Download the Godot executable.
+RUN curl -o godot.zip ${GODOT_ENGINE_URL}
+
+# Download the Godot export templates.
+RUN curl -o export_templates.zip ${GODOT_EXPORT_TEMPLATES_URL}
+
+# Unpack Godot executable.
+RUN unzip godot.zip -d godot && mv godot/* /bin/godot
+
+# Unpack Godot export templates.
+RUN unzip export_templates.zip -d export_templates && mv export_templates/* /export_templates
+
+################################################################################
+# Create a stage for building the application.
+FROM debian:bullseye-slim as build
+
+ARG GODOT_VERSION=4.2.stable
+ARG SERVER_EXPORT_PRESET_NAME=Server
+
+WORKDIR /build
+
+# Copy the engine and export templates from the "prebuild" stage.
+COPY --from=prebuild /bin/godot /bin/
+COPY --from=prebuild /export_templates /export_templates
+
+# Setup export templates.
+RUN mkdir -p $HOME/.local/share/godot/export_templates && \
+	mv /export_templates $HOME/.local/share/godot/export_templates/${GODOT_VERSION}
+
+# Mount the project in the image.
+RUN --mount=type=bind,source=project,target=project,readonly \
+	<<EOF
+set -e
+/bin/godot --headless --path project --export-release "${SERVER_EXPORT_PRESET_NAME}" ../server
+EOF
+
+################################################################################
+# Create a new stage for running the application that contains the minimal
+# runtime dependencies for the application. This often uses a different base
+# image from the build stage where the necessary files are copied from the build
+# stage.
+FROM debian:bullseye-slim AS final
 
 WORKDIR /app
 
-# Copy the binaries into the container
-COPY . ./
+# Copy the executable from the "build" stage.
+COPY --from=build /build .
 
 # Fix permissions
-RUN chmod +x server.x86_64
+RUN chmod +x server
 
 # Expose the port that the application listens on.
 EXPOSE 9000
 
 # Run the application.
-CMD ./server.x86_64 --server --headless
+CMD ["./server", "--server", "--headless"]

+ 1 - 1
build/server/README.md

@@ -7,7 +7,7 @@ Make sure to have Docker installed.
 To build the game server image, run the command below from the repository root:
 
 ```bash
-docker build --platform linux/x86_64 --tag {custom_tag} -f build/server/Dockerfile export/server
+docker build --platform linux/x86_64 --tag {custom_tag} -f build/server/Dockerfile .
 ```
 
 ## Pushing images to Docker Hub