Skip to content

Commit

Permalink
Disable Branches
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoparma88 committed May 28, 2024
1 parent f985ebc commit 4741444
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
14 changes: 5 additions & 9 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ name: CD

on:
push:
branches:
- main
# Uncomment and add the necessary branches to enable automatic deployment on AWS
# branches:
# - main

jobs:
deploy:
Expand All @@ -16,20 +17,18 @@ jobs:
uses: actions/checkout@v4

- name: Configure AWS credentials
if: ${{ secrets.AWS_ACCESS_KEY_ID != '' }}
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: ${{ vars.AWS_REGION }}

- name: Login to Amazon ECR
if: ${{ secrets.AWS_ACCESS_KEY_ID != '' }}
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build, tag, and push image to Amazon ECR
if: ${{ secrets.AWS_ACCESS_KEY_ID != '' }}

id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
Expand All @@ -41,12 +40,10 @@ jobs:
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Download task definition
if: ${{ secrets.AWS_ACCESS_KEY_ID != '' }}
run: |
aws ecs describe-task-definition --task-definition ${{ vars.ECS_TASK_DEFINITION }} --query taskDefinition > ${{ vars.ECS_TASK_DEFINITION_PATH }}
- name: Fill in the new image ID in the Amazon ECS task definition
if: ${{ secrets.AWS_ACCESS_KEY_ID != '' }}
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
Expand All @@ -55,10 +52,9 @@ jobs:
image: ${{ steps.build-image.outputs.image }}

- name: Deploy Amazon ECS task definition
if: ${{ secrets.AWS_ACCESS_KEY_ID != '' }}
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ vars.ECS_SERVICE }}
cluster: ${{ vars.ECS_CLUSTER }}
wait-for-service-stability: true
wait-for-service-stability: true
12 changes: 11 additions & 1 deletion docs/cd_with_aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Before you start, make sure you have the following:
3. **AWS Credentials**:
- AWS Access Key ID
- AWS Secret Access Key
- These credentials should have permissions to interact with ECR and ECS.
- These credentials should have permission to interact with ECR and ECS.

4. **GitHub Repository Setup**:
- Secrets: Add the following secrets to your GitHub repository:
Expand All @@ -29,3 +29,13 @@ Before you start, make sure you have the following:
- `CONTAINER_NAME`: The name of the container defined in your ECS task definition.
- `ECS_SERVICE`: The name of your ECS service.
- `ECS_CLUSTER`: The name of your ECS cluster.

5. **GitHub Actions Workflow**:
To set up the GitHub Actions workflow for continuous deployment to AWS, you need to modify the existing cd.yml file in the .github/workflows directory of your GitHub repository.
Uncomment the branches section under on: push: and add the necessary branches to enable automatic deployment. For example:

on:
push:
branches:
- main
- dev

0 comments on commit 4741444

Please sign in to comment.