Deploy your Unity WebGL game to Amazon's Elastic Container Service using this handy-dandy virtual environment.
- aws-cli
- ecs-cli
- jq
- a domain (guide)
- a TLS certificate (guide)
- an ECS cluster (guide) and service (guide)
- name your service with the name you will set in
config.json
- recommended: set your service behind an ALB (guide)
- name your service with the name you will set in
Create a CNAME under your domain that points to the ALB (guide). Use the TLS certificate to encrypt the traffic between the client and the ALB (guide). Then configure a target group to forward traffic to your service's tasks (guide). This tool doesn't touch on any of these things, but you should have this setup before hosting a game.
Last thing to note is to ensure that the ECS task role you use have ecr:* and logs:* permissions. It doesn't have to be that open, but ¯\_(ツ)_/¯.
Before you begin, be sure to have aws-cli and ecs-cli configured. If you don't already, follow this guide for aws-cli, and this guide for ecs-cli.
Once that's done, the first thing you need to do is fill out config.json
:
- build_dir: build directory (where you built to from Unity)
- name: the name for your ECR repository, task definition, and service
- tag: tag your deploy (usually "latest")
- cluster: name of your cluster
- network_mode: bridge, host, awsvpc, or none
- task_role_arn: role arn the containers will assume
- execution_role_arn: role arn that container agents and docker daemon will assume
- network_mode: bridge, host, awsvpc, or none (not implemented, uses default)
- cpu: CPU units
- memory: MiB units
Reminder: you must have a cluster and service ready before deployment.
If you're ready to go, here are the steps:
- In Unity:
- click File>Build Settings...
- click WebGL
- configure your build
- click Build and choose this repo as the destination
- Here:
- run
. deploy_env.sh
- run
deploy
- when done, run
deactivate
- run
deploy
will:
- login to ECR
- build the docker image (./Dockerfile)
- push the image to ECR
- create a new task definition revision
- update the service with the new task definiton
While in the deploy environment, you can:
ecr-login
: login to ECRbuild
: build the local docker imagepush
: push image (takes name fromconfig.json
.name) to ECRrevise
: create new task definition revisionupdate
: update the service with the new task definitiondeactivate
: deactivate deploy environment
That's the basic flow of things. You can always version control your builds and use this in something like Jenkins.