This guide will walk you through setting up branch deploys for your Amazon ECS (Elastic Container Service) application using Cased. We’ll cover the basic steps to get you started with a more robust CI/CD pipeline.
Prerequisites
- An AWS account with ECS set up
- A GitHub repository for your application
- A Cased account
Step 1: Connect Cased to Your Services
-
Connect Cased to GitHub:
- Go to the Cased connections page and select the GitHub option.
- Click “Install GitHub App” and follow the prompts to give Cased access to your repository.
-
Connect Cased to AWS:
- In your AWS console, create a new IAM role named “CasedRole” using the policy provided in the Cased documentation.
- Copy the Role ARN.
- In Cased, go to the AWS Connections page and enter the Role ARN and your AWS region.
Step 2: Set Up Your Project in Cased
- In Cased, go to the Deploys section and click “Create new project”.
- Select your GitHub repository and click “Create Project”.
Step 3: Create Deployment Targets
- In your project page, click “Create new target”.
- Create two targets: one for staging and one for production. For each:
- Name the target (e.g., “staging”, “production”)
- Select a GitHub Actions workflow (we’ll create this in the next step)
- If it’s the production target, check the “production” box
Step 4: Create a GitHub Actions Workflow
- In your GitHub repository, create a new file:
.github/workflows/cased-deploy.yml
- Use this basic workflow as a starting point:
name: Cased ECS Deploy
on:
workflow_dispatch:
inputs:
branch:
required: true
target_name:
required: true
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.branch }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: your-aws-region
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: your-ecr-repo-name
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
- name: Update ECS service
run: |
aws ecs update-service --cluster your-ecs-cluster --service your-ecs-service --force-new-deployment
- name: Notify Cased of deployment
uses: cased/cased-deploy-action@v2
with:
branch_name: ${{ github.event.inputs.branch }}
target: ${{ github.event.inputs.target_name }}
cased_token: ${{ secrets.CASED_TOKEN }}
Make sure to replace your-aws-region
, your-ecr-repo-name
, your-ecs-cluster
, and your-ecs-service
with your actual values.
Step 5: Set Up Secrets
In your GitHub repository settings, add these secrets:
AWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
for AWS accessCASED_TOKEN
from your Cased account settings
Step 6: Deploy a Branch
Now you’re ready to deploy:
- In Cased, go to your project’s deploy page.
- Select the target you want to deploy to (e.g., “staging”).
- Choose the branch you want to deploy.
- Click “Deploy”.
Cased will trigger the GitHub Actions workflow, which will build your Docker image, push it to ECR, update your ECS service, and notify Cased of the deployment.
Step 7: Monitor and Analyze
After deployment:
- Check the deployment status in Cased.
- Monitor for any anomalies that Cased detects.
- If issues occur, use Cased’s log analysis features to investigate.
Conclusion
This setup allows you to easily deploy any branch to your ECS environment through Cased. It provides the benefits of branch deploys - increased safety, easy rollbacks, and better visibility - while leveraging the power of ECS for your containerized applications.
Remember to adjust and expand this workflow based on your specific needs, such as adding more sophisticated testing or approval processes before production deploys.