...
This is the process needed to push updated code to an API Server instance. Note that you can build the binary on the instance, but if you do, you should also push it to ECR to keep a persistent copy of our server code.
Code Block |
---|
# If logged into the server, log out now and log back in to reset the shell environment
# From your developer machine log into the server
aws ssm start-session --target i-0a0612957e4895917 --region us-east-2
# This process needs to be completed as root
sudo su -
# Get local credentials for our ECR repository.
aws ecr get-login-password --region us-east-2 \
| docker login --username AWS \
--password-stdin 747101682576.dkr.ecr.us-east-2.amazonaws.com
# Pull the latest Docker container
docker pull 747101682576.dkr.ecr.us-east-2.amazonaws.com/r2d2-server:prod
# Stop the running service.
systemctl stop r2d2.service
# Remove the current container.
docker rm r2d2-api-service
# Re-start the prod service container.
docker run -d --name r2d2-api-service -p 80:80 \
-e MYSQL_USER='r2d2' \
-e MYSQL_DATABASE='r2d2' \
-e MYSQL_HOST='r2d2-api-prod-rdsinstance-eja4eofrohvy.cg24vilqoa8w.us-east-2.rds.amazonaws.com' \
747101682576.dkr.ecr.us-east-2.amazonaws.com/r2d2-server:prod \
run_r2d2_app --port 80 --nodebug
# Restart the systemd service.
systemctl start r2d2.service
# Check the output logs
docker logs -f r2d2-api-service |
...