-
Notifications
You must be signed in to change notification settings - Fork 1
Enable manual trigger for ECS deployment workflow #141
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
2 commits
Select commit
Hold shift + click to select a range
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,89 @@ | ||
| # This workflow will build and push a new container image to Amazon ECR, | ||
| # and then will deploy a new task definition to Amazon ECS. | ||
| # It is triggered manually via workflow_dispatch. | ||
| # | ||
| # To use this workflow, you will need to complete the following set-up steps: | ||
| # | ||
| # 1. Create an ECR repository to store your images. | ||
| # For example: `aws ecr create-repository --repository-name my-ecr-repo --region us-east-2`. | ||
| # Set the `AWS_REGION` and `ECR_REPOSITORY` variables in your GitHub repository/environment settings. | ||
| # | ||
| # 2. Create an ECS task definition, an ECS cluster, and an ECS service. | ||
| # For example, follow the Getting Started guide on the ECS console: | ||
| # https://us-east-2.console.aws.amazon.com/ecs/home?region=us-east-2#/firstRun | ||
| # Set the `ECS_SERVICE` and `ECS_CLUSTER` variables in your GitHub repository/environment settings. | ||
| # | ||
| # 3. Store your ECS task definition as a JSON file in your repository. | ||
| # The format should follow the output of `aws ecs register-task-definition --generate-cli-skeleton`. | ||
| # Set the `ECS_TASK_DEFINITION` and `CONTAINER_NAME` variables in your GitHub repository/environment settings. | ||
| # | ||
| # 4. Configure GitHub OIDC for AWS and create an IAM role that GitHub Actions can assume. | ||
| # Store the IAM role ARN in a GitHub Actions secret named `AWS_ROLE_ARN`. | ||
| # See https://docs.github.com/en/actions/security-for-github-actions/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services | ||
| # for setup instructions and recommended IAM policies. | ||
|
|
||
| name: Deploy to Amazon ECS | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
|
|
||
| env: | ||
| AWS_REGION: ${{ vars.AWS_REGION }} | ||
| ECR_REPOSITORY: ${{ vars.ECR_REPOSITORY }} | ||
| ECS_SERVICE: ${{ vars.ECS_SERVICE }} | ||
| ECS_CLUSTER: ${{ vars.ECS_CLUSTER }} | ||
| ECS_TASK_DEFINITION: ${{ vars.ECS_TASK_DEFINITION }} | ||
| CONTAINER_NAME: ${{ vars.CONTAINER_NAME }} | ||
|
|
||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
|
|
||
| jobs: | ||
| deploy: | ||
| name: Deploy | ||
| runs-on: ubuntu-latest | ||
| environment: production | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Configure AWS credentials | ||
| uses: aws-actions/configure-aws-credentials@v1 | ||
| with: | ||
| role-to-assume: ${{ secrets.AWS_ROLE_ARN }} | ||
| aws-region: ${{ env.AWS_REGION }} | ||
|
|
||
elifouts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - name: Login to Amazon ECR | ||
| id: login-ecr | ||
| uses: aws-actions/amazon-ecr-login@v1 | ||
|
|
||
| - name: Build, tag, and push image to Amazon ECR | ||
| id: build-image | ||
| env: | ||
| ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
| IMAGE_TAG: ${{ github.sha }} | ||
| run: | | ||
| # Build a docker container and | ||
| # push it to ECR so that it can | ||
| # be deployed to ECS. | ||
| docker build -f backend/Dockerfile -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG backend | ||
| docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | ||
| echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT | ||
|
|
||
| - 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: ${{ env.ECS_TASK_DEFINITION }} | ||
| container-name: ${{ env.CONTAINER_NAME }} | ||
| image: ${{ steps.build-image.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: ${{ env.ECS_SERVICE }} | ||
| cluster: ${{ env.ECS_CLUSTER }} | ||
| wait-for-service-stability: true | ||
Oops, something went wrong.
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.