Bereite ein Container-Image mit deiner Gameserver-Software vor - Amazon GameLift

Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.

Bereite ein Container-Image mit deiner Gameserver-Software vor

Diese Dokumentation bezieht sich auf eine Funktion, die sich in der öffentlichen Vorschauversion befindet. Änderungen sind vorbehalten.

Der Container ist das grundlegendste Element einer GameLift Amazon-Containerflotte. Ihr Container umfasst Ihren Spieleserver zusammen mit seinen Abhängigkeiten wie SDKs, Software, Verzeichnissen und Dateien.

Um in einer Containerflotte zu funktionieren, muss dein Spieleserver unter Linux laufen und in das Server-SDK 5.x integriert sein.

Richte dein Arbeitsverzeichnis ein

In Ihrem Arbeitsverzeichnis legen Sie alle Dateien ab, die Sie zum Erstellen Ihres Container-Images benötigen, und definieren, wie Amazon es GameLift ausführt.

Um Ihr Container-Arbeitsverzeichnis einzurichten
  1. Erstellen Sie das Verzeichnis, in dem Sie mit Ihren GameLift Amazon-Container-Images arbeiten möchten.

    Beispielsweise:

    [~/]$ mkdir -p work/glc/gamebuild && cd work && find . . ./glc ./glc/gamebuild
  2. Klonen Sie den GameLift Amazon-Agenten.

    Beispielsweise:

    [~/work]$ git clone https://github.com/aws/amazon-gamelift-agent.git Cloning into 'amazon-gamelift-agent'...
  3. Erstellen Sie das GameLiftAgent mit Maven.

    Beispielsweise:

    [~/work]$ cd amazon-gamelift-agent

    [~/work/amazon-gamelift-agent]$ mvn clean compile assembly:single && \ mv target ../glc && cd .. && find glc
  4. Füge einen Spieleserver hinzu, der in das Server-SDK 5.x integriert, erstellt und in eine .ZIP Datei gepackt wurde.

  5. Kopiere deine .ZIP Datei nach. ~/work/glc/gamebuild/

Wenn du keinen SDK 5.x-Spieleserver hast, kannst du unser SimpleServerBeispielspiel herunterladen und verwenden, um es mit einer Containerflotte zu versuchen.

[~/work]$ curl -o glc/gamebuild/SimpleServer.zip \ 'https://ws-assets-prod-iad-r-iad-ed304a55c2ca1aee.s3.us-east-1.amazonaws.com/086bb355-4fdc-4e63-8ca7-af7cfc45d4f2/AmazonGameLiftSampleServerBinary.zip' && % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 5140k 100 5140k 0 0 12.3M 0 --:--:-- --:--:-- --:--:-- 12.3M glc glc/target glc/target/GameLiftAgent-1.0.jar glc/gamebuild glc/gamebuild/SimpleServer.zip

Erstelle dein Container-Image

Ihr Dockerfile spezifiziert die Umgebung, Software und Anweisungen zum Erstellen Ihres Containers.

Um Ihr Dockerfile zu erstellen
  1. Gehe in das Unterverzeichnisglc.

    [~/work]$ cd glc && find . ./target ./target/GameLiftAgent-1.0.jar ./gamebuild
  2. Erstellen und öffnen Sie ein neues Dockerfile.

    Beispielsweise:

    [~/work/glc]$ nano Dockerfile
  3. Kopieren Sie aus einer der folgenden Vorlagen und fügen Sie den Inhalt dann in Ihr Dockerfile ein.

Diese Vorlage enthält die Mindestanweisungen, die ein Container benötigt, um in einer GameLift Amazon-Flotte verwendet zu werden. Ändern Sie den Inhalt nach Bedarf für Ihren Spieleserver.

# Base image # ---------- # Add the base image that you want to use over here, # Make sure to use an image with the same architecture as the # Instance type you are planning to use on your fleets. # We require JDK to be installed in the base image, so that # it can be used to run the &AGS; Agent FROM public.ecr.aws/amazoncorretto/amazoncorretto:17-amd64 # # Game build directory # -------------------- # Add your game build to gamebuild directory and add the zip file name in the 'GAME_BUILD_ZIP' env variable below. # The game build provided over here needs to be integrated with gamelift server sdk. # This template assumes that the game build is in a zip format. ENV GAME_BUILD_ZIP="<ADD_GAME_BUILD_ZIP_FILE_NAME>" \ # # Default directory # ----------------- # Default directory, the value provided here should be where the game executable exists. # Provide this same value as your launch path in RuntimeConfiguration when creating a fleet. # Ref: https://docs.aws.amazon.com/gamelift/latest/apireference/API_ServerProcess.html GAME_EXECUTABLE="<ADD NAME OF EXECUTABLE WITHIN THE GAME BUILD>" \ HOME_DIR="/local/game" \ # # Registered compute in anywhere fleet (not used in container fleets) # ------------------------------------------------------------------- # Add the name for the registered compute in an anywhere fleet. # This environment variable is required only for anywhere fleets, but not for container fleets. # If it is set for container fleets, it will be overridden by Gamelift. GAMELIFT_COMPUTE_NAME="<ADD_COMPUTE_NAME>" \ # # Default Gamelift Agent jar # -------------------------- GAMELIFT_AGENT_EXEC="GameLiftAgent-1.0.jar" \ # # This env variable defines the name of the S3 bucket that stores the GameLift Agent logs. # This S3 bucket should exist in the customer AWS account. # In order to allow GameLift agent to upload logs to this s3 bucket, customers would need to # include s3:PutObject permission in the IAM role provided as instanceRoleArn during CreateFleet operation. GAMELIFT_AGENT_LOGS_BUCKET_NAME="<ADD NAME OF GAMELIFT AGENT LOGS S3 BUCKET>" \ # # ----------- # This env variable defines the name of the S3 bucket that stores the game session logs. # This S3 bucket should exist in the customer AWS account. # In order to allow GameLift agent to upload logs to this s3 bucket, customers would need to # include s3:PutObject permission in the IAM role provided as instanceRoleArn during CreateFleet operation. # ----------- GAME_SESSION_LOGS_BUCKET_NAME="<ADD NAME OF GAME SESSION LOGS S3 BUCKET>" \ # # ----------- GAMELIFT_AGENT_LOGS_PATH="/local/game/agentlogs/" \ # # NOT USED in container fleets - USED in Anywhere fleets # ---------------------------------------------------------- # Specifiy the type of compute resource used to host the game servers. # This env variable is required only for anywhere fleets, but not for container fleets. # If it is set for container fleets, it will be overridden by Gamelift. # # ----------- COMPUTE_TYPE="ANYWHERE" \ # # Specify the credential to be used for creating the client. # This env variable is required only for anywhere fleets, but not for container fleets. # If it is set for container fleets, it will be overridden by Gamelift. # # ----------- CREDENTIAL_PROVIDER="environment-variable" USER root # intall dependencies as necessary RUN yum install -y sudo \ unzip \ git \ shadow-utils \ iputils \ tar \ gcc \ make \ openssl-devel \ zlib-devel \ vim \ net-tools \ nc \ procps # Set up the ground for 'gamescale' user RUN groupadd -r gamescale -g 500 && \ useradd -u 500 -r -g gamescale -m -s /sbin/nologin -c "Gamescale user" gamescale && \ echo "gamescale ALL=(ALL) NOPASSWD: ALL" | (EDITOR="tee -a" visudo) && \ mkdir -p $HOME_DIR && \ mkdir $HOME_DIR/mono && \ chown -R gamescale:gamescale $HOME_DIR WORKDIR $HOME_DIR # extract game build as necessary COPY ./gamebuild/$GAME_BUILD_ZIP . RUN unzip ./$GAME_BUILD_ZIP -d ./ # copy Gamelift Agent jar COPY ./gameliftAgent/$GAMELIFT_AGENT_EXEC ./ # Add permissions to game build and gamelift agent jar RUN chmod +x ./$GAME_EXECUTABLE RUN chmod +x ./$GAMELIFT_AGENT_EXEC # Check if java is installed on the image, if not then the Agent will not be able to run RUN java --version USER gamescale ENV PATH="$PATH:$HOME_DIR/bin:$JAVA_HOME" # Change directory to bin WORKDIR $HOME_DIR # check path before starting the container RUN echo $PATH # Create logs directory for GameLift Agent & server processes RUN mkdir logs RUN mkdir agentlogs # Start the GameLift Agent ENTRYPOINT sleep 90 && java -jar $GAMELIFT_AGENT_EXEC -ip "192.168.1.1" -gslb "$GAME_SESSION_LOGS_BUCKET_NAME" -galb "$GAMELIFT_AGENT_LOGS_BUCKET_NAME" -galp "$GAMELIFT_AGENT_LOGS_PATH" -glc environment-variable
# Base image # ---------- # Add the base image that you want to use over here, # Make sure to use an image with the same architecture as the # Instance type you are planning to use on your fleets. # We require JDK to be installed in the base image, so that # it can be used to run the &AGS; Agent FROM public.ecr.aws/amazoncorretto/amazoncorretto:17-amd64 # # Game build directory # -------------------- # Add your game build to gamebuild directory and add the zip file name in the 'GAME_BUILD_ZIP' env variable below. # The game build provided over here needs to be integrated with gamelift server sdk. # This template assumes that the game build is in a zip format. ENV GAME_BUILD_ZIP="SimpleServer.zip" \ # # Default directory # ----------------- # Default directory, the value provided here should be where the game executable exists. # Provide this same value as your launch path in RuntimeConfiguration when creating a fleet. # Ref: https://docs.aws.amazon.com/gamelift/latest/apireference/API_ServerProcess.html GAME_EXECUTABLE="GameLiftSampleServer" \ HOME_DIR="/local/game" \ # # Registered compute in anywhere fleet (not used in container fleets) # ------------------------------------------------------------------- # Add the name for the registered compute in an anywhere fleet. # This environment variable is required only for anywhere fleets, but not for container fleets. # If it is set for container fleets, it will be overridden by Gamelift. GAMELIFT_COMPUTE_NAME="<ADD_COMPUTE_NAME>" \ # # Default Gamelift Agent jar # -------------------------- GAMELIFT_AGENT_EXEC="GameLiftAgent-1.0.jar" \ # # This env variable defines the name of the S3 bucket that stores the GameLift Agent logs. # This S3 bucket should exist in the customer AWS account. # In order to allow GameLift agent to upload logs to this s3 bucket, customers would need to # include s3:PutObject permission in the IAM role provided as instanceRoleArn during CreateFleet operation. GAMELIFT_AGENT_LOGS_BUCKET_NAME="<ADD NAME OF GAMELIFT AGENT LOGS S3 BUCKET>" \ # # ----------- # This env variable defines the name of the S3 bucket that stores the game session logs. # This S3 bucket should exist in the customer AWS account. # In order to allow GameLift agent to upload logs to this s3 bucket, customers would need to # include s3:PutObject permission in the IAM role provided as instanceRoleArn during CreateFleet operation. # ----------- GAME_SESSION_LOGS_BUCKET_NAME="<ADD NAME OF GAME SESSION LOGS S3 BUCKET>" \ # # ----------- GAMELIFT_AGENT_LOGS_PATH="/local/game/agentlogs/" \ # # NOT USED in container fleets - USED in Anywhere fleets # ---------------------------------------------------------- # Specifiy the type of compute resource used to host the game servers. # This env variable is required only for anywhere fleets, but not for container fleets. # If it is set for container fleets, it will be overridden by Gamelift. # # ----------- COMPUTE_TYPE="ANYWHERE" \ # # Specify the credential to be used for creating the client. # This env variable is required only for anywhere fleets, but not for container fleets. # If it is set for container fleets, it will be overridden by Gamelift. # # ----------- CREDENTIAL_PROVIDER="environment-variable" USER root # intall dependencies as necessary RUN yum install -y sudo \ unzip \ git \ shadow-utils \ iputils \ tar \ gcc \ make \ openssl-devel \ zlib-devel \ vim \ net-tools \ nc \ procps # Set up the ground for 'gamescale' user RUN groupadd -r gamescale -g 500 && \ useradd -u 500 -r -g gamescale -m -s /sbin/nologin -c "Gamescale user" gamescale && \ echo "gamescale ALL=(ALL) NOPASSWD: ALL" | (EDITOR="tee -a" visudo) && \ mkdir -p $HOME_DIR && \ mkdir $HOME_DIR/mono && \ chown -R gamescale:gamescale $HOME_DIR WORKDIR $HOME_DIR # extract game build as necessary COPY ./gamebuild/$GAME_BUILD_ZIP . RUN unzip ./$GAME_BUILD_ZIP -d ./ # copy Gamelift Agent jar COPY ./target/$GAMELIFT_AGENT_EXEC ./ # Add permissions to game build and gamelift agent jar RUN chmod +x ./$GAME_EXECUTABLE RUN chmod +x ./$GAMELIFT_AGENT_EXEC # Check if java is installed on the image, if not then the Agent will not be able to run RUN java --version USER gamescale ENV PATH "$PATH:$HOME_DIR/bin:$JAVA_HOME" # Change directory to bin WORKDIR $HOME_DIR # check path before starting the container RUN echo $PATH # Create logs directory for GameLift Agent & server processes RUN mkdir logs RUN mkdir agentlogs # Start the GameLift Agent ENTRYPOINT sleep 90 && java -jar $GAMELIFT_AGENT_EXEC -ip "192.168.1.1" -gslb "$GAME_SESSION_LOGS_BUCKET_NAME" -galb "$GAMELIFT_AGENT_LOGS_BUCKET_NAME" -galp "$GAMELIFT_AGENT_LOGS_PATH" -glc environment-variable
Anmerkung

Hinweis: Einige der Umgebungsvariablen in der Dockerfile können durch die überschrieben werden. ContainerDefinition

Um Ihr Container-Image zu erstellen
  1. Erstellen Sie Ihr Container-Image.

    Wenn Sie Ihren eigenen SDK 5.x-Server verwenden

    Sie können einen beliebigen lokalen Repository-Namen angeben.

    [~/work/glc]$ docker build -t <local repository name>:<optional tag> .
    Wenn Sie unser SimpleServer Beispiel verwenden
    [~/work/glc]$ docker build -t simple-server:version-1 . Successfully built 0123456789012 Successfully tagged simple-server:version-1
    Anmerkung

    In den folgenden Beispielen verwenden wir simpler-server als REPOSITORY Anfangswert und version-1 als Wert. TAG

  2. Sehen Sie sich die Liste der Bilder an und notieren Sie sich die Werte REPOSITORY undIMAGE ID. Sie benötigen sie in einem der folgenden Verfahren.

    [~/work/glc]$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE simple-server version-1 0123456789012 14 minutes ago 1.24GB

Übertragen Sie Ihr Container-Image auf Amazon ECR

Laden Sie Ihr Container-Image in ein privates Repository in Amazon ECR hoch. Wenn Sie eine Container-Gruppendefinition erstellen, verweisen Sie auf diesen Repository-Speicherort, GameLift sodass Amazon einen Snapshot Ihres Container-Images erstellen und ihn bei der Bereitstellung einer Containerflotte verwenden kann.

Anmerkung

Wenn Sie noch kein privates Amazon ECR-Repository haben, erstellen Sie eines.

Um Ihre Amazon ECR-Anmeldeinformationen zu erhalten
  • Bevor Sie Ihr Container-Image auf Amazon ECR übertragen können, müssen Sie Ihre AWS Anmeldeinformationen in temporärer Form abrufen und sie Docker zur Verfügung stellen. Besorgen Sie sich Ihre Amazon ECR-Anmeldeinformationen, damit sich Docker anmelden kann.

    [~/work/glc]$ aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin aws_account_id.dkr.ecr.us-west-2.amazonaws.com WARNING! Your password will be stored unencrypted in /home/user-name/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded
Um Ihr Container-Image an Amazon ECR zu übertragen
  1. Kopieren Sie die URI des privaten Amazon ECR-Repositorys, das Sie verwenden möchten.

  2. Wenden Sie ein Amazon ECR-Tag auf Ihr Container-Image an.

    [~/work/glc]$ docker tag <IMAGE ID from above> <Amazon ECR private repository URI>:<optional tag>
  3. Übertragen Sie Ihr Container-Image auf Amazon ECR

    [~/work/glc]$ docker image push <Amazon ECR private repository URI>