Skip to content

Latest commit

 

History

History
203 lines (129 loc) · 6.45 KB

File metadata and controls

203 lines (129 loc) · 6.45 KB

Bet-dapp - SOP

Pre-requisites

Tools

  • Docker
  • AWS CLI
  • Terraform (Only if you need to change the infra. Not necessary to deploy new versions in the instance)

AWS Access

You must configure access to the Nano-testnet account in AWS.

Run the following command:

aws configure sso

Set the following values when asked:

  • SSO Session Name: nano-testnet
  • SSO Start URL: https://hathorlabs.awsapps.com/start
  • SSO Region: us-east-1
  • SSO Registration Scopes: sso:account:access
  • In the accounts list, select Nano-testnet
  • CLI default client region: us-east-1
  • CLI default output format: None
  • CLI profile name: nano-testnet

Login to the account using the following command:

aws sso login --profile nano-testnet

Deploying new versions

Building and pushing the production image

aws ecr get-login-password --region ap-southeast-1 --profile nano-testnet | docker login --username AWS --password-stdin 471112952246.dkr.ecr.ap-southeast-1.amazonaws.com

docker build  --platform linux/amd64 -t 471112952246.dkr.ecr.ap-southeast-1.amazonaws.com/bet-dapp:latest .

docker push 471112952246.dkr.ecr.ap-southeast-1.amazonaws.com/bet-dapp:latest

Building and pushing the staging image

aws ecr get-login-password --region ap-southeast-1 --profile nano-testnet | docker login --username AWS --password-stdin 471112952246.dkr.ecr.ap-southeast-1.amazonaws.com

docker build  --platform linux/amd64 --build-arg ENVIRONMENT=staging --build-arg NEXT_PUBLIC_URL="https://staging.betting.hathor.network/" -t 471112952246.dkr.ecr.ap-southeast-1.amazonaws.com/bet-dapp:staging-latest .

docker push 471112952246.dkr.ecr.ap-southeast-1.amazonaws.com/bet-dapp:staging-latest

Accessing the instance

# Get the instance IP from its name tag
aws ec2 describe-instances --profile nano-testnet --filters "Name=tag:Name,Values=bet-dapp" --query "Reservations[*].Instances[*].PublicIpAddress" --output text --region ap-southeast-1

ssh ec2-user@<instance-ip>

To access the staging instance, just change the name tag to bet-dapp-staging.

Login to Docker in the instance

aws ecr get-login-password --region ap-southeast-1 | sudo docker login --username AWS --password-stdin 471112952246.dkr.ecr.ap-southeast-1.amazonaws.com

Pulling the latest image

The following should be run inside the EC2 instance

# Inside the home directory (/home/ec2-user)
sudo docker compose pull

Restarting the service

The following should be run inside the EC2 instance

# Inside the home directory (/home/ec2-user)
# Running this will pick up any changes in the configuration and recreate the container
sudo docker compose up -d

Other operations in the instance

Checking logs

The following should be run inside the EC2 instance

# Inside the home directory (/home/ec2-user)
sudo docker compose logs bet-dapp -f

Stopping the service

The following should be run inside the EC2 instance

# Inside the home directory (/home/ec2-user)
sudo docker compose down

Starting the service

The following should be run inside the EC2 instance

# Inside the home directory (/home/ec2-user)
sudo docker compose up -d

Inspecting the DynamoDB table in AWS

Go to https://hathorlabs.awsapps.com/start and login to the Nano-testnet account.

You can find the table at:

Click Explore table items to see the items in the table.

Infra changes

The infra is currently defined in https://github.com/HathorNetwork/ops-tools/tree/master/terraform/bet-dapp

Make sure to run make terraform-init to setup the Terraform environment.

Updating the DybamoDB table definition

The table is defined in the file terraform/bet-dapp/dynamodb.tf

Refer to the Terraform documentation for more information on how to define the table.

Apply the changes in staging by running:

make apply-staging

Apply the changes in production by running:

make apply

You'll be prompted to review the changes before they are applied.

Changing the instance security group, instance type or other configurations

The instance is defined in the file terraform/bet-dapp/ec2.tf

Refer to the Terraform documentation on the following resources for more information on how to define the instance:

Apply the changes in staging by running:

make apply-staging

Apply the changes in production by running:

make apply

You'll be prompted to review the changes before they are applied.

Changing the instance provisioning script

The provisioning script is defined in the file terraform/bet-dapp/scripts/provision-instance.yaml.tftpl

It's a cloud-init script that runs when the instance is created.

If changes are needed inside the instance, ideally they should be written in this script and the instance should be recreated by running make apply for production, or make apply-staging for staging.

This will generate a downtime in the service, so it should be done with caution. To avoid this, you could create a new instance first, test the changes and then switch the Elastic IP to the new instance. Or just make the changes in the running instance, if you're in a hurry, then update the script later.

The Elastic IP is defined in the file terraform/bet-dapp/ec2.tf

Changing the Cloudfront configuration

We had to add a rule in the Cloudfront distribution we use to serve hathor.network, in order to have the bet-dapp served under https://hathor.network/betting2024

To update this, you should: