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

ci: ensure unique revisions for deployments #1211

Merged
merged 5 commits into from
Oct 2, 2024

Conversation

arealmaas
Copy link
Collaborator

@arealmaas arealmaas commented Oct 1, 2024

Description

There was an issue where if we re-run the same workflow for deployment, it would fail because of using the same revision suffix. Changing to passing in a revision suffix and using workflow run id and workflow attempt to ensure uniqueness.

Related Issue(s)

  • #{issue number}

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)

Documentation

  • Documentation is updated (either in docs-directory, Altinnpedia or a separate linked PR in altinn-studio-docs., if applicable)

Summary by CodeRabbit

  • New Features

    • Introduced a new environment variable REVISION_SUFFIX for improved tracking of deployment revisions.
    • Added a revisionSuffix parameter across various Bicep configuration files to enhance deployment customization and versioning.
    • Standardized deployment names to include environment and version for consistency.
  • Chores

    • Enhanced deployment workflow structure without altering the overall functionality.

@arealmaas arealmaas requested review from a team as code owners October 1, 2024 14:20
Copy link
Contributor

coderabbitai bot commented Oct 1, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes introduced in this pull request focus on enhancing the deployment process by adding a new environment variable, REVISION_SUFFIX, which is derived from the GitHub run ID, version, and run attempt. This variable is incorporated into the environment settings for migration and application deployment jobs, ensuring consistent tracking of deployment revisions. Additionally, a new parameter revisionSuffix is introduced in multiple Bicep files to utilize this environment variable, replacing previous image tag references.

Changes

File Change Summary
.github/workflows/action-deploy-apps.yml Added the REVISION_SUFFIX environment variable to migration and deployment jobs; standardized deployment names.
.azure/applications/graphql/main.bicep Introduced revisionSuffix parameter for container app revision tracking, replacing imageTag.
.azure/applications/graphql/prod.bicepparam Added revisionSuffix parameter reading from REVISION_SUFFIX environment variable.
.azure/applications/graphql/staging.bicepparam Added revisionSuffix parameter reading from REVISION_SUFFIX environment variable.
.azure/applications/graphql/test.bicepparam Added revisionSuffix parameter reading from REVISION_SUFFIX environment variable.
.azure/applications/web-api-eu/main.bicep Introduced revisionSuffix parameter for container app revision tracking, replacing imageTag.
.azure/applications/web-api-eu/prod.bicepparam Added revisionSuffix parameter reading from REVISION_SUFFIX environment variable.
.azure/applications/web-api-eu/staging.bicepparam Added revisionSuffix parameter reading from REVISION_SUFFIX environment variable.
.azure/applications/web-api-eu/test.bicepparam Added revisionSuffix parameter reading from REVISION_SUFFIX environment variable.
.azure/applications/web-api-so/main.bicep Introduced revisionSuffix parameter for container app revision tracking, replacing imageTag.
.azure/applications/web-api-so/prod.bicepparam Added revisionSuffix parameter reading from REVISION_SUFFIX environment variable.
.azure/applications/web-api-so/staging.bicepparam Added revisionSuffix parameter reading from REVISION_SUFFIX environment variable.
.azure/applications/web-api-so/test.bicepparam Added revisionSuffix parameter reading from REVISION_SUFFIX environment variable.

Possibly related PRs

Suggested reviewers

  • oskogstad

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.

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: 3

🧹 Outside diff range comments (3)
.azure/applications/graphql/prod.bicepparam (1)

Line range hint 1-14: Consider adding a comment to explain the purpose of revisionSuffix.

The addition of the revisionSuffix parameter is well-implemented and consistent with the file's structure. To improve maintainability, consider adding a brief comment explaining its purpose and importance in ensuring unique deployments.

Example:

// Unique suffix for each deployment to prevent conflicts when re-running workflows
param revisionSuffix = readEnvironmentVariable('REVISION_SUFFIX')
.azure/applications/web-api-eu/main.bicep (1)

Incomplete Update of revisionSuffix Parameter

The revisionSuffix parameter has been introduced in main.bicep but is not reflected in any of the related workflow YAML files or documentation. To ensure consistent deployment behavior and proper documentation:

  • Workflow Files:

    • .github/workflows/action-deploy-infra.yml
    • .github/workflows/action-build-infrastructure.yml
    • .github/workflows/action-deploy-apps.yml

    Action: Update these workflows to include and pass the revisionSuffix parameter when invoking the Bicep template.

  • Documentation Files:

    • README.md
    • CHANGELOG.md
    • docs/Configuration.md
    • src/Digdir.Domain.Dialogporten.Janitor/README.md

    Action: Document the new revisionSuffix parameter, its purpose, and usage within these files to ensure clarity for all stakeholders.

🔗 Analysis chain

Line range hint 1-114: Verify related files and documentation.

The changes in this file successfully introduce the revisionSuffix parameter to ensure unique revisions for deployments. However, to complete this change:

  1. Ensure that any workflow files (e.g., GitHub Actions) that call this Bicep template are updated to provide the revisionSuffix parameter.
  2. Update any relevant documentation to reflect this new parameter and its purpose.

To help verify the impact of this change, you can run the following script:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for potential workflow files that might need updating
echo "Potential workflow files that might need updating:"
fd -e yml -e yaml . .github/workflows -x grep -l "main.bicep"

# Search for documentation files that might mention deployment revisions
echo "Documentation files that might need updating:"
rg -t md -l "revision|deployment|container app"

Length of output: 550


Script:

#!/bin/bash
# Verify 'revisionSuffix' parameter in workflow YAML files
echo "Checking for 'revisionSuffix' in workflow files:"
grep -Hn "revisionSuffix" .github/workflows/action-deploy-infra.yml .github/workflows/action-build-infrastructure.yml .github/workflows/action-deploy-apps.yml

# Verify documentation updates for 'revisionSuffix' in markdown files
echo "Checking for documentation updates related to 'revisionSuffix':"
grep -iHn "revisionSuffix" README.md CHANGELOG.md docs/Configuration.md src/Digdir.Domain.Dialogporten.Janitor/README.md

Length of output: 535

.github/workflows/action-deploy-apps.yml (1)

Line range hint 1-293: Suggestions for consistency and completeness

The changes effectively address the issue of duplicate revision suffixes in the deploy-apps job. However, consider the following suggestions to improve consistency and completeness:

  1. Apply the REVISION_SUFFIX to the deploy-migration-job and deploy-jobs jobs as well to ensure all deployments have unique revisions.

  2. Include the REVISION_SUFFIX in the deploymentName parameter for all jobs to prevent potential conflicts when multiple deployments are triggered for the same version. For example:

deploymentName: dp-be-${{ inputs.environment }}-${{ matrix.name }}-${{ inputs.version }}-${{ env.REVISION_SUFFIX }}
  1. If you implement the suggestion to define REVISION_SUFFIX at the job or workflow level, update all references accordingly.

These changes would ensure that the fix is applied consistently across all deployment jobs and further reduce the risk of conflicts.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 933d298 and 2c11f36.

📒 Files selected for processing (13)
  • .azure/applications/graphql/main.bicep (2 hunks)
  • .azure/applications/graphql/prod.bicepparam (1 hunks)
  • .azure/applications/graphql/staging.bicepparam (1 hunks)
  • .azure/applications/graphql/test.bicepparam (1 hunks)
  • .azure/applications/web-api-eu/main.bicep (2 hunks)
  • .azure/applications/web-api-eu/prod.bicepparam (1 hunks)
  • .azure/applications/web-api-eu/staging.bicepparam (1 hunks)
  • .azure/applications/web-api-eu/test.bicepparam (1 hunks)
  • .azure/applications/web-api-so/main.bicep (2 hunks)
  • .azure/applications/web-api-so/prod.bicepparam (1 hunks)
  • .azure/applications/web-api-so/staging.bicepparam (1 hunks)
  • .azure/applications/web-api-so/test.bicepparam (1 hunks)
  • .github/workflows/action-deploy-apps.yml (2 hunks)
🔇 Additional comments (16)
.azure/applications/graphql/prod.bicepparam (1)

7-7: LGTM! This change aligns well with the PR objectives.

The addition of the revisionSuffix parameter, which reads from the REVISION_SUFFIX environment variable, is a good implementation to ensure unique revisions for deployments. This directly addresses the issue mentioned in the PR objectives and should prevent failures due to duplicate revision suffixes when re-running workflows.

.azure/applications/graphql/test.bicepparam (1)

7-7: LGTM: New parameter added to ensure unique revisions

The addition of the revisionSuffix parameter, which reads its value from the REVISION_SUFFIX environment variable, aligns well with the PR objectives. This change will help ensure unique revisions for each deployment, preventing conflicts when re-running workflows.

A few points to consider:

  1. The implementation is consistent with other parameters in the file (e.g., imageTag).
  2. This change supports the goal of making each deployment have a distinct revision suffix.
  3. Ensure that the REVISION_SUFFIX environment variable is properly set in the CI/CD pipeline before this deployment step.

To verify the usage of this new parameter, please run the following script:

.azure/applications/web-api-eu/prod.bicepparam (1)

7-7: LGTM! This change addresses the PR objectives effectively.

The addition of the revisionSuffix parameter, which reads from the REVISION_SUFFIX environment variable, aligns perfectly with the PR's goal of ensuring unique revisions for deployments. This implementation will help prevent failures associated with duplicate identifiers when re-running workflows.

The parameter is correctly implemented and consistent with other environment variable readings in the file. This change enhances the reliability of the deployment process without disrupting the existing configuration.

.azure/applications/web-api-eu/test.bicepparam (1)

7-7: LGTM! The new parameter aligns with PR objectives.

The addition of the revisionSuffix parameter, which reads from the REVISION_SUFFIX environment variable, is well-implemented and aligns perfectly with the PR objectives. This change will ensure unique revisions for deployments, addressing the issue of workflow failures due to identical revision suffixes.

A few observations:

  1. The implementation is consistent with other parameters in the file.
  2. Using readEnvironmentVariable allows for dynamic assignment of the revision suffix, which is crucial for achieving uniqueness across deployments.
  3. The placement of the new parameter (after imageTag and before the secrets section) is logical and maintains good code organization.

To ensure this change is properly utilized, let's verify if the REVISION_SUFFIX environment variable is set in the relevant workflow files:

✅ Verification successful

REVISION_SUFFIX is correctly set in workflow files.

The REVISION_SUFFIX environment variable is properly defined in .github/workflows/action-deploy-apps.yml using a combination of github.run_id, inputs.version, and github.run_attempt. This ensures that each deployment has a unique revision suffix, aligning with the PR objectives.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if REVISION_SUFFIX is set in workflow files

# Test: Search for REVISION_SUFFIX in yaml files under .github/workflows
# Expect: At least one occurrence setting REVISION_SUFFIX
rg --type yaml 'REVISION_SUFFIX' .github/workflows

Length of output: 326

.azure/applications/web-api-so/prod.bicepparam (2)

Line range hint 1-13: The overall file structure and practices look good.

The file correctly uses environment variables for sensitive information and configuration, which is a good security practice. The parameters are appropriately defined for a production environment, and the existing parameters remain unchanged. This approach maintains consistency while introducing the new revisionSuffix parameter.


7-7: LGTM! The addition of revisionSuffix parameter aligns with the PR objectives.

The new parameter revisionSuffix is correctly implemented to read from the REVISION_SUFFIX environment variable. This change should address the issue of deployment failures due to identical revision suffixes when re-running workflows.

To ensure this change is effective, please verify that the REVISION_SUFFIX environment variable is correctly set in your CI/CD pipeline. You can use the following script to check if the variable is present in your GitHub Actions workflow:

If the variable is not found, you may need to update your workflow files to set this variable using the GitHub Actions run ID and attempt number, as mentioned in the PR description.

✅ Verification successful

LGTM! The addition of the revisionSuffix parameter aligns with the PR objectives.

The REVISION_SUFFIX environment variable is correctly set in your GitHub Actions workflows as confirmed by the verification script output. This change should effectively address the issue of deployment failures due to identical revision suffixes when re-running workflows.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if REVISION_SUFFIX is set in GitHub Actions workflow files

# Test: Search for REVISION_SUFFIX in workflow files
rg --type yaml 'REVISION_SUFFIX' .github/workflows

Length of output: 326

.azure/applications/web-api-so/test.bicepparam (2)

Line range hint 1-14: Summary: Successful implementation of unique revision suffix.

The addition of the revisionSuffix parameter is a focused and effective change that addresses the issue described in the PR objectives. By reading from an environment variable, it allows for dynamic setting of a unique identifier for each deployment.

This change:

  1. Solves the problem of duplicate revision suffixes when re-running workflows.
  2. Improves the reliability of the deployment process.
  3. Is minimally invasive, affecting only the necessary part of the configuration.

No further changes are required in this file. The implementation is clean and aligns well with the project's needs.


7-7: LGTM: New parameter added for unique revision suffix.

The addition of the revisionSuffix parameter aligns well with the PR objectives. It reads the value from the REVISION_SUFFIX environment variable, which will be set to a unique value for each deployment using the workflow run ID and attempt number.

This change effectively addresses the issue of duplicate revision suffixes when re-running workflows, ensuring that each deployment has a unique identifier.

To verify that this change is properly implemented in the workflow, we can check the relevant workflow file:

This script will search for the setting of REVISION_SUFFIX in the workflow files, ensuring it's set to a combination of github.run_id and github.run_attempt as described in the PR objectives.

✅ Verification successful

LGTM: REVISION_SUFFIX is correctly set with a unique identifier including version.

The revisionSuffix parameter is properly configured to include github.run_id, inputs.version, and github.run_attempt, ensuring each deployment has a unique identifier. This implementation aligns with the PR objectives and effectively prevents duplicate revision suffixes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the REVISION_SUFFIX is set in the workflow

# Test: Search for REVISION_SUFFIX in workflow files
rg --type yaml 'REVISION_SUFFIX.*\$\{\{ github.run_id \}\}-\$\{\{ github.run_attempt \}\}' .github/workflows/

Length of output: 111


Script:

#!/bin/bash
# Description: Check for any occurrences of REVISION_SUFFIX in workflow YAML files

rg --type yaml 'REVISION_SUFFIX' .github/workflows/

Length of output: 327


Script:

#!/bin/bash
# Description: Analyze the usage of REVISION_SUFFIX in deployment workflows

# Search for all instances where REVISION_SUFFIX is used
rg --type yaml 'REVISION_SUFFIX' .github/workflows/ | while read -r line; do
  echo "$line"
done

Length of output: 666

.azure/applications/graphql/staging.bicepparam (1)

7-7: LGTM! This change aligns well with the PR objectives.

The addition of the revisionSuffix parameter, which reads from the REVISION_SUFFIX environment variable, directly addresses the issue of ensuring unique revisions for deployments. This implementation will prevent failures when re-running workflows, as each deployment will now have a distinct revision suffix.

.azure/applications/web-api-eu/staging.bicepparam (1)

7-7: LGTM: New parameter aligns with PR objectives

The addition of the revisionSuffix parameter, which reads its value from the REVISION_SUFFIX environment variable, aligns well with the PR objectives. This change addresses the issue of deployment failures due to identical revision suffixes by allowing a unique suffix to be passed for each deployment.

A few points to consider:

  1. The implementation is correct and follows the pattern used for other parameters in this file.
  2. This change doesn't impact existing parameters, maintaining backward compatibility.
  3. The use of an environment variable allows for dynamic setting of the revision suffix, which is ideal for CI/CD workflows.

To ensure this change is properly utilized, let's verify if the REVISION_SUFFIX environment variable is set in the relevant workflow files:

This will help confirm that the new parameter is being used as intended in the CI/CD process.

✅ Verification successful

LGTM: revisionSuffix parameter is correctly integrated and utilized

The revisionSuffix parameter successfully reads the REVISION_SUFFIX environment variable, which is properly set in the CI/CD workflow files. This ensures each deployment has a unique suffix, effectively addressing the issue of deployment failures due to identical revision suffixes.

  • The environment variable REVISION_SUFFIX is defined in .github/workflows/action-deploy-apps.yml:
    • REVISION_SUFFIX: "${{ github.run_id }}-${{ inputs.version }}-${{ github.run_attempt}}"

No further actions are required as the implementation meets the PR objectives and maintains existing functionality.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if REVISION_SUFFIX is set in workflow files

# Test: Search for REVISION_SUFFIX in workflow files
rg --type yaml 'REVISION_SUFFIX' .github/workflows

Length of output: 326

.azure/applications/graphql/main.bicep (2)

19-21: LGTM: New parameter revisionSuffix is well-defined.

The new revisionSuffix parameter is correctly declared with an appropriate description and constraint. It follows the existing coding style and conventions used in the file.


94-94: Verify the usage of both revisionSuffix and imageTag parameters.

The addition of the revisionSuffix parameter to the containerApp module is correct and aligns with the PR objectives. However, the AI-generated summary mentioned that revisionSuffix replaces the previous usage of imageTag, but both parameters are still present in the module call.

Please run the following script to verify the usage of both parameters in the containerApp module:

If both parameters are indeed needed, please update the PR description to clarify this point.

.azure/applications/web-api-eu/main.bicep (1)

19-21: LGTM: New parameter revisionSuffix is well-defined.

The new revisionSuffix parameter is correctly declared with an appropriate description and constraint. It follows the existing coding style and conventions used in the file.

.azure/applications/web-api-so/main.bicep (2)

19-21: LGTM: New parameter revisionSuffix added correctly.

The new revisionSuffix parameter is well-defined with an appropriate description and constraint. This addition aligns with the PR objective of ensuring unique revisions for deployments.


101-101: Verify uniqueness of revisionSuffix in workflow.

The change correctly implements the use of revisionSuffix in the containerApp module, which aligns with the PR objective. This should prevent conflicts when re-running workflows.

Please ensure that the revisionSuffix parameter is set to a unique value for each workflow run. You can verify this by checking the workflow file where this Bicep template is used. The workflow should set revisionSuffix using unique identifiers like ${{ github.run_id }}-${{ github.run_attempt }}.

.github/workflows/action-deploy-apps.yml (1)

169-169: LGTM: Unique revision suffix for dry run deployments

The introduction of the REVISION_SUFFIX environment variable is a good solution to ensure unique revisions for each deployment. By combining github.run_id, inputs.version, and github.run_attempt, it guarantees a unique identifier for each workflow run, addressing the issue mentioned in the PR objectives.

.azure/applications/web-api-eu/main.bicep Show resolved Hide resolved
.github/workflows/action-deploy-apps.yml Outdated Show resolved Hide resolved
Copy link

sonarcloud bot commented Oct 1, 2024

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: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 2c11f36 and 683a9a0.

📒 Files selected for processing (1)
  • .github/workflows/action-deploy-apps.yml (3 hunks)
🔇 Additional comments (2)
.github/workflows/action-deploy-apps.yml (2)

152-153: Excellent addition of the REVISION_SUFFIX environment variable.

The introduction of the REVISION_SUFFIX environment variable, composed of github.run_id, inputs.version, and github.run_attempt, directly addresses the issue of deployment failures due to duplicate revision suffixes. This ensures that each deployment, even when re-running the same workflow, will have a unique identifier.


152-153: Summary: Effective implementation of unique revision suffixes

The changes introduced in this pull request successfully address the issue of deployment failures due to duplicate revision suffixes. By implementing a REVISION_SUFFIX environment variable that combines the GitHub run ID, version, and run attempt, the workflow now ensures that each deployment has a unique identifier.

Key points:

  1. The REVISION_SUFFIX is correctly defined at the job level.
  2. It's consistently applied in both dry run and actual deployment steps.
  3. The changes are minimal and focused, reducing the risk of introducing new issues.

These modifications align well with the PR objectives and should resolve the deployment conflicts when re-running workflows. The implementation is clean and effective.

Also applies to: 171-171, 195-195

.github/workflows/action-deploy-apps.yml Show resolved Hide resolved
@arealmaas arealmaas merged commit 69e7fe7 into main Oct 2, 2024
21 checks passed
@arealmaas arealmaas deleted the fix/avoid-duplicate-suffix branch October 2, 2024 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants