本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用您的遊戲伺服器軟體準備容器映像檔
本文件適用於公開預覽版本中的功能。內容可能變動。
容器是 Amazon GameLift 容器叢集中最基本的元素。您的容器包括遊戲伺服器,以及其相依性,例如 SDK、軟體、目錄和檔案。
若要在容器叢集中運作,您的遊戲伺服器必須在 Linux 上執行,並與伺服器 SDK 5.x 整合。
設定您的工作目錄
您的工作目錄是放置構建容器映像所需的所有文件並定義 Amazon 如何 GameLift 運行它的位置。
若要設定容器工作目錄
-
建立您要使用 Amazon GameLift 容器映像的目錄。
例如:
[~/]$
mkdir -p work/glc/gamebuild && cd work && find .. ./glc ./glc/gamebuild
-
例如:
[~/work]$
git clone https://github.com/aws/amazon-gamelift-agent.gitCloning into 'amazon-gamelift-agent'...
-
例如:
[~/work]$
cd amazon-gamelift-agent[~/work/amazon-gamelift-agent]$
mvn clean compile assembly:single && \ mv target ../glc && cd .. && find glc 新增與伺服器 SDK 5.x 整合的遊戲伺服器,並建立並封裝到
.ZIP
檔案中。-
將您的
.ZIP
檔案複製到~/work/glc/gamebuild/
.
如果您沒有 SDK 5.x 遊戲伺服器,您可以下載並使用我們的範例SimpleServer
[~/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
建立容器映像檔
您的 Docker 文件指定了構建容器的環境,軟件和指令。
建立您的碼頭檔
移至
glc
子目錄。[~/work]$
cd glc && find. ./target ./target/GameLiftAgent-1.0.jar ./gamebuild
創建並打開一個新的碼頭文件。
例如:
[~/work/glc]$
nano Dockerfile從以下模板之一複製,然後將內容粘貼到 Dockerfile 中。
此範本包含容器在 Amazon GameLift 叢集中使用所需的最低指令。視需要修改遊戲伺服器的內容。
# 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
注意
注意:Docker 檔案中的一些環境變數可以由. ContainerDefinition
若要建立容器映像檔
-
建立您的容器映像檔。
- 如果您使用自己的 SDK 5.x 服務器
-
您可以指定所需的任何本地存儲庫名稱。
[~/work/glc]$
docker build -t<local repository name>
:<optional tag>
. - 如果您正在使用我們的
SimpleServer
樣品 -
[~/work/glc]$
docker build -tsimple-server
:version-1
.Successfully built
0123456789012
Successfully tagged simple-server:version-1
注意
在下面的例子中,我們使用
更簡單的服務器
作為初始REPOSITORY
值,並version-1
作為值。TAG
-
檢視影像清單,並記下
REPOSITORY
和IMAGE ID
值。您將在下面的過程中需要它們。[~/work/glc]$
docker imagesREPOSITORY TAG IMAGE ID CREATED SIZE simple-server version-1
0123456789012
14 minutes ago 1.24GB
將您的容器映像推送到 Amazon ECR
將您的容器映像上傳到 Amazon ECR 中的私有儲存庫。建立容器群組定義時,您會參考此儲存庫位置,以便 Amazon GameLift 可以拍攝容器映像的快照,並在部署容器叢集時使用它。
注意
如果您還沒有 Amazon ECR 私有儲存庫,請建立一個。
獲取您的 Amazon ECR 憑據
-
在將容器映像推送至 Amazon ECR 之前,您必須先以臨時形式取得 AWS 登入資料並將其提供給 Docker。取得您的 Amazon ECR 登入資料,以便碼頭工人可以登入。
[~/work/glc]$
aws ecr get-login-password --regionus-west-2
| docker login --username AWS --password-stdinaws_account_id
.dkr.ecr.us-west-2
.amazonaws.comWARNING! 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
將您的容器映像推送到 Amazon ECR
複製您要使用的 Amazon ECR 私有儲存庫
的 URI。 將 Amazon ECR 標籤套用至您的容器映像檔。
[~/work/glc]$
docker tag<IMAGE ID from above>
<Amazon ECR private repository URI>
:<optional tag>
將您的容器映像推送到 Amazon ECR
[~/work/glc]$
docker image push<Amazon ECR private repository URI>