-
Notifications
You must be signed in to change notification settings - Fork 130
Add CD with github actions #704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
64137e5
add cd.yml
brunoparma88 f985ebc
add doc
brunoparma88 4741444
Disable Branches
brunoparma88 50fd383
comment on push
brunoparma88 6522376
fix main branch
brunoparma88 5663bdb
add on:
brunoparma88 70c5af6
add workflow_dispatch
brunoparma88 a1281ef
add-docker/build-push-action
brunoparma88 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
name: CD | ||
santib marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
on: | ||
workflow_dispatch: | ||
# push: | ||
# Uncomment and add the necessary branches to enable automatic deployment on AWS | ||
# branches: | ||
# - main | ||
|
||
jobs: | ||
deploy: | ||
name: Deploy on AWS ECS | ||
runs-on: ubuntu-latest | ||
environment: | ||
name: ${{ github.ref == 'refs/heads/main' && 'production' || github.ref_name }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- 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: ${{ vars.AWS_REGION }} | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Login to Amazon ECR | ||
uses: aws-actions/amazon-ecr-login@v1 | ||
|
||
- name: Build and push Docker image | ||
id: build-and-push | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.login-ecr.outputs.registry }}/${{ vars.ECR_REPOSITORY }}:${{ github.sha }} | ||
|
||
- name: Get the image digest | ||
id: image-digest | ||
run: echo "image=${{ steps.login-ecr.outputs.registry }}/${{ vars.ECR_REPOSITORY }}:${{ github.sha }}" >> $GITHUB_OUTPUT | ||
|
||
- name: Download task definition | ||
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 | ||
id: task-def | ||
uses: aws-actions/amazon-ecs-render-task-definition@v1 | ||
with: | ||
task-definition: ${{ vars.ECS_TASK_DEFINITION_PATH }} | ||
container-name: ${{ vars.CONTAINER_NAME }} | ||
image: ${{ steps.image-digest.outputs.image }} | ||
|
||
- name: Deploy Amazon ECS task definition | ||
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,47 @@ | ||||||
# Continuous Deployment with AWS | ||||||
|
||||||
This document explains how to set up Continuous Deployment (CD) with AWS using GitHub Actions. | ||||||
|
||||||
## Prerequisites | ||||||
|
||||||
Before you start, make sure you have the following: | ||||||
|
||||||
1. **AWS Account**: You need an AWS account. Sign up [here](https://aws.amazon.com/). | ||||||
|
||||||
2. **Amazon ECR (Elastic Container Registry) Setup**: | ||||||
- Create a new repository in Amazon ECR. | ||||||
- Note down the repository URI, which will be used in the GitHub Actions workflow. | ||||||
|
||||||
3. **AWS Credentials**: | ||||||
- AWS Access Key ID | ||||||
- AWS Secret Access Key | ||||||
- These credentials should have permission to interact with ECR and ECS. | ||||||
|
||||||
4. **Create Environments**: | ||||||
|
||||||
The GitHub Actions workflow will automatically deploy to the correct environment based on the branch being pushed to. The branch `main` will always be linked to the `production` environment, while other branches will use their own names as the environment. All environments added in GitHub must have the same name as the branches. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Grammarly suggestion
Suggested change
|
||||||
|
||||||
5. **GitHub Repository Setup**: | ||||||
- **Environment Secrets**: Add the following secrets to your GitHub environments (these are specific to each environment and not set at the repository level): | ||||||
- `AWS_ACCESS_KEY_ID`: Your AWS Access Key ID. | ||||||
- `AWS_SECRET_ACCESS_KEY`: Your AWS Secret Access Key. | ||||||
- **Environment Variables**: Add the following variables to your GitHub environments: | ||||||
- `AWS_REGION`: The region where your ECR and ECS are set up (e.g., `us-east-1`). | ||||||
- `ECR_REPOSITORY`: The name of your ECR repository. | ||||||
- `ECS_TASK_DEFINITION`: The ARN of your ECS task definition. | ||||||
- `ECS_TASK_DEFINITION_PATH`: The path to your ECS task definition file. | ||||||
- `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. | ||||||
|
||||||
6. **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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Grammarly suggestion
Suggested change
|
||||||
|
||||||
Uncomment the branches section under `on: push:` and add the necessary branches to enable automatic deployment. For example: | ||||||
|
||||||
```yaml | ||||||
on: | ||||||
push: | ||||||
branches: | ||||||
- main | ||||||
- dev |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.