How can I set up deployments to ECS or EKS?
To deploy to AWS ECS or EKS, you need to set up your own server and configure a Shell server.
As a first step, you need to deploy to a server of your own so that your image is present on your infrastructure. During this step, you can make use of DeployHQ's features, such as our build pipeline or any additional steps or complexity you wish to add to this process.
Once this is done, the next step will be to set up a shell server
on DeployHQ, which will take the deployed image (or files) that you just deployed to your server, and run additional commands on top to set up a deployment to your ECS or EKS service.
For example, you can run something like this on your DeployHQ shell server:
#!/bin/bash
#Set environment variables
AWS_REGION="your-aws-region"
CLUSTER_NAME="your-ecs-or-eks-cluster-name"
SERVICE_NAME="your-service-name"
IMAGE_TAG="your-image-tag"
TASK_DEFINITION_FILE="task-definition.json"
#Create or update the task definition
aws ecs register-task-definition \
--family $SERVICE_NAME \
--container-definitions file://$TASK_DEFINITION_FILE \
--region $AWS_REGION
#Get the latest task definition ARN
TASK_DEFINITION_ARN=$(aws ecs describe-task-definitions \
--family $SERVICE_NAME \
--region $AWS_REGION \
--query 'taskDefinitions[0].taskDefinitionArn' \
--output text)
#Update the service
aws ecs update-service \
--cluster $CLUSTER_NAME \
--service $SERVICE_NAME \
--task-definition $TASK_DEFINITION_ARN \
--force-new-deployment \
--region $AWS_REGION
#Wait for the service to stabilize
aws ecs wait service-stable \
--cluster $CLUSTER_NAME \
--service $SERVICE_NAME \
--region $AWS_REGION
The above code will set up your service, and perform the necessary set up to effectively deploy a new image to your Amazon service. If needed, you can modify this approach to adapt it to different situations or even services with DeployHQ shell server's flexibility.