Architecture Center
Deploy and Run a Map Application for a Web Game on Alibaba Cloud

Deploy and Run a Map Application for a Web Game on Alibaba Cloud

Overview
This solution builds an interactive "Game of Thrones" map application powered by Leaflet, PostgreSQL, PostGIS, and Redis on Alibaba Cloud.
Reference Architecture
Steps
Deploy Resources
Use this main.tf file in Terraform to provision ECS, EIP, ApsaraDB for Redis, and ApsaraDB RDS for PostgreSQL instances from this solution.
The ECS instance information will be listed after the Terraform script execution is completed.
eip_ecs: The public EIP of the ECS for gamp map application host
rds_pg_url: The connection endpoint URL of RDS PostgreSQL
rds_pg_port: The connection endpoint port of RDS PostgreSQL
redis_url: The connection endpoint URL of Redis
Set up Sample Data in RDS PostgreSQL
1. In the Alibaba Cloud website Console, click Elastic Compute Service, copy an ECS instance's IP address and log on to this ECS instance remotely.
The default account name and password of the ECS instance are:
Account Name: root
Password: Aliyun-test
2. Download the prepared data script:
wget https://cdn.patricktriest.com/atlas-of-thrones/atlas_of_thrones.sql
3. Install the PostgreSQL client:
apt update && apt -y install postgresql-client
4. Connect to the PostgreSQL instance:
Note: Replace YOUR-POSTGRESQL-ADDRESS with the connection address of your PostgreSQL instance, and use the password the_best_passsword.
psql -h YOUR-POSTGRESQL-ADDRESS -p 5432 -U patrick -d atlas_of_thrones
5. Install the PostGIS extension:
Note: If the extension already exists, ignore the prompt and proceed.
CREATE EXTENSION postgis;
6. Exit the client.
\q
7. Load the downloaded SQL dump into your newly created database: Note: Replace YOUR-POSTGRESQL-ADDRESS with the connection address of your PostgreSQL instance with the password the_best_passsword.
psql -h YOUR-POSTGRESQL-ADDRESS -p 5432 -U patrick -d atlas_of_thrones < atlas_of_thrones.sql
8. Log in to the "atlas_of_thrones" database:
psql -h YOUR-POSTGRESQL-ADDRESS -p 5432 -U patrick -d atlas_of_thrones
9. Get the list of available tables:
\dt
10. Inspect the schema of an individual table: \d kingdoms
11. Query data: SELECT name, claimedby, gid FROM kingdoms;
12. Exit the client: \q
Install Node.js
1. Download the Node.js installation package:
wget http://labex-ali-data.oss-us-west-1.aliyuncs.com/nodejs/node-v12.13.0-linux-x64.tar.xz
2. Decompress the installation package:
tar -xf node-v12.13.0-linux-x64.tar.xz
3. Move the unzipped directory to the /usr/local directory:
mv node-v12.13.0-linux-x64 /usr/local/node
4. Run the command vim /etc/profile, and add the following content to the file: export NODE_HOME=/usr/local/node
export PATH=$PATH:$NODE_HOME/bin
5. Activate the modification:
source /etc/profile
6. View the installed version, which indicates that the installation is completed:
node -v
npm -v
Deploy and Run the Demo Game Map Project
1. Install the Git tool:
apt -y install git
2. Download the project:
git clone -b labex https://github.com/andi1991/Atlas-Of-Thrones.git
3. Enter the project directory:
cd Atlas-Of-Thrones
4. Run the command vim .env, then copy the following content to the file: Note: Replace YOUR-POSTGRESQL-ADDRESS and YOUR-REDIS-ADDRESS with the connection addresses of your instances.
PORT=5000
DATABASE_URL=postgres://patrick:the_best_passsword@YOUR-POSTGRESQL-ADDRESS:5432/atlas_of_thrones?ssl=false
REDIS_HOST=YOUR-REDIS-ADDRESS
REDIS_PORT=6379
CORS_ORIGIN=http://localhost:8080
5. Install related dependencies:
npm install
6. Install the dependent package that reported the errors separately:
npm cache clean --force
npm i --unsafe-perm node-sass@4.14.1
7. Start the service:
npm run dev
8. Visit YOUR-ECS-PUBLIC-IP:8080c in the browser to see the map app.
Note: Replace YOUR-ECS-PUBLIC-IP with your ECS public IP address.

Database Migration Solution

Migrate to fully managed cloud databases.

Learn More >

Gaming Solutions

Fuel gaming businesses with agility, availability, and intelligence

Learn More >

Reach Alibaba Cloud experts for support

Contact Us
phone Contact Us