Skip to content
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

aws mutli-env deploy #730

Merged
merged 7 commits into from
Oct 16, 2024
Merged

aws mutli-env deploy #730

merged 7 commits into from
Oct 16, 2024

Conversation

snopoke
Copy link
Collaborator

@snopoke snopoke commented Oct 16, 2024

Description

Update the deploy action to support multiple environments (currently 'dev' and 'prod')

Copy link
Contributor

coderabbitai bot commented Oct 16, 2024

Walkthrough

The pull request introduces significant modifications to the deployment workflow for Amazon ECS as defined in the .github/workflows/deploy.yml file. A new input parameter, environment, has been added to allow users to specify the deployment environment when manually triggering the workflow. The workflow now requires expected variables to be set in JSON format at the repository level for different environments, including application names, AWS regions, and AWS account numbers.

The on section of the workflow has been updated to comment out the previous push trigger for the main branch. A new step titled "Set Deploy Env" has been incorporated to determine the deployment environment based on user input or the branch being deployed, which sets the DEPLOY_ENV variable.

Subsequent steps have been adjusted to utilize these new environment variables. The configuration for AWS credentials now dynamically references the DEPLOY_ENV variable to select the appropriate AWS account and region. Additionally, task definition families for various ECS services have been updated to incorporate the APP_NAME variable, ensuring that the correct service names are used based on the specified deployment environment.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
.github/workflows/deploy.yml (2)

4-11: Excellent addition of expected variables documentation!

This new section clearly explains the required repository-level variables and their expected format. It's a great improvement for maintainability and ease of setup.

Consider adding a brief example of how to set these variables in the repository settings to make it even more user-friendly.


42-66: Excellent implementation of dynamic environment-based configuration!

The new steps for setting the deployment environment and other variables greatly enhance the workflow's flexibility. The use of GitHub Environment variables ensures proper scoping, and the approach can easily accommodate new environments in the future.

To improve readability, consider using a heredoc for the multi-line environment variable setting in the "Set variables" step. For example:

- name: Set variables
  run: |
    cat << EOF >> $GITHUB_ENV
    APP_NAME=${{ fromJSON(vars.DEPLOY_APP_NAME)[env.DEPLOY_ENV] }}
    ECR_REPOSITORY=$APP_NAME-${{ env.DEPLOY_ENV }}-ecr-repo
    ECS_CLUSTER=$APP_NAME-${{ env.DEPLOY_ENV }}-Cluster
    ECS_SERVICE_DJANGO=$APP_NAME-${{ env.DEPLOY_ENV }}-Django
    ECS_SERVICE_CELERY=$APP_NAME-${{ env.DEPLOY_ENV }}-Celery
    ECS_SERVICE_CELERY_BEAT=$APP_NAME-${{ env.DEPLOY_ENV }}-CeleryBeat
    EOF

This approach can make the script more readable and easier to maintain.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c988a0b and 931aac5.

📒 Files selected for processing (1)
  • .github/workflows/deploy.yml (4 hunks)
🧰 Additional context used
🔇 Additional comments (5)
.github/workflows/deploy.yml (5)

18-27: Improved workflow trigger with manual environment selection.

The addition of the workflow_dispatch trigger with environment selection enhances flexibility for deployments. However, the commented-out push trigger raises a question about the intended deployment strategy.

Could you clarify the intended deployment strategy? If automatic deployments to production are still desired, consider using a conditional statement to trigger the workflow on push to the main branch with the production environment. For example:

on:
  workflow_dispatch:
    inputs:
      environment:
        description: "Deploy environment"
        required: true
        type: choice
        options:
          - dev
          - prod
  push:
    branches:
      - main

Then, in the "Set Deploy Env" step, you can add:

elif [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]]; then
  DEPLOY_ENV="prod"

This would maintain automatic production deployments while allowing manual triggers for both environments.


70-72: Good use of environment-specific AWS credentials!

The modification to use environment-specific variables for role-to-assume and aws-region is a great improvement. This allows for different AWS accounts and regions per environment, enhancing the workflow's flexibility.

To ensure that the AWS account and region are correctly set for each environment, consider adding a verification step after the AWS credentials configuration:

- name: Verify AWS configuration
  run: |
    echo "Configured AWS Account: $(aws sts get-caller-identity --query Account --output text)"
    echo "Configured AWS Region: ${{ env.AWS_REGION }}"

This step will print the configured AWS account and region, allowing for easy verification during workflow runs.


105-105: Correct implementation of environment-specific task definition family.

The modification to use env.APP_NAME and env.DEPLOY_ENV in the task-definition-family is correct and consistent with the previously set variables. This change allows for different task definition families per environment, which is essential for multi-environment deployments.


121-121: Consistent implementation of environment-specific task definition family for Celery worker.

The modification to use env.APP_NAME and env.DEPLOY_ENV in the task-definition-family for the Celery worker is correct and consistent with the previous changes. This ensures that the Celery worker task definition is properly segregated per environment.


129-129: Consistent implementation of environment-specific task definition family for Celery beat.

The modification to use env.APP_NAME and env.DEPLOY_ENV in the task-definition-family for the Celery beat is correct and consistent with the previous changes. This completes the set of changes required for environment-specific task definitions across all services.

These changes collectively ensure that all ECS task definitions (Django web, Celery worker, and Celery beat) are properly segregated per environment. This is crucial for maintaining separate configurations and deployments for different environments (e.g., dev and prod). The consistent use of env.APP_NAME and env.DEPLOY_ENV across all services reduces the chance of errors and improves maintainability.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Additional details and impacted files

📢 Thoughts on this report? Let us know!

@snopoke snopoke merged commit c41ca19 into main Oct 16, 2024
9 checks passed
@snopoke snopoke deleted the sk/aws-deploy-tweaks branch October 16, 2024 10:05
This was referenced Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants