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

feat(service): deploy application in container apps #1303

Merged
merged 3 commits into from
Oct 16, 2024

Conversation

arealmaas
Copy link
Collaborator

@arealmaas arealmaas commented Oct 16, 2024

Description

  • Added Service in all environments in container app. Using webapi for now until Service is ready
  • Added user assigned identity instead of using the created managed identity created by the container app to avoid potential race conditions. This should be required eventually for all container apps. Making it optional for now.

Related Issue(s)

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 infrastructure configuration for deploying a container application in Azure.
    • Added support for multiple environments (production, staging, test) with dynamic parameter management.
    • Enhanced identity management for the container app, allowing for user-assigned identities.
  • Bug Fixes

    • Improved health probe configurations for better application monitoring.
  • Documentation

    • Updated workflow to include deployment capabilities for the new service component.

@arealmaas arealmaas requested review from a team as code owners October 16, 2024 08:18
Copy link
Contributor

coderabbitai bot commented Oct 16, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

This pull request introduces several Bicep files for deploying a container application across different environments (production, staging, test) and updates an existing module to support user-assigned identities. The main Bicep file defines parameters for deployment, including environment variables and resource configurations. Parameter files for production, staging, and test environments are created, allowing for dynamic configuration based on environment variables. Additionally, the workflow file is updated to include a new deployment job for the service, enhancing deployment capabilities.

Changes

File Path Change Summary
.azure/applications/service/main.bicep Added parameters for deployment configuration and outputs for container app deployment.
.azure/applications/service/prod.bicepparam Created a new parameter file for production with parameters sourced from environment variables.
.azure/applications/service/staging.bicepparam Created a new parameter file for staging with parameters sourced from environment variables.
.azure/applications/service/test.bicepparam Created a new parameter file for test with parameters sourced from environment variables.
.azure/modules/containerApp/main.bicep Added userAssignedIdentityId parameter and modified identity handling for container app.
.github/workflows/workflow-deploy-apps.yml Updated workflow to include a new deployment job for the service in the deployment matrix.

Possibly related PRs

Suggested reviewers

  • oskogstad

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c1ce84b and f8b40f5.

📒 Files selected for processing (1)
  • .azure/applications/service/main.bicep (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .azure/applications/service/main.bicep

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.

MagnusSandgren
MagnusSandgren previously approved these changes Oct 16, 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: 8

🧹 Outside diff range and nitpick comments (4)
.azure/applications/service/prod.bicepparam (1)

8-12: LGTM: Secure handling of sensitive parameters.

The secret parameters are appropriately defined and read from environment variables, which is a good security practice. The parameters cover essential resources for the container app deployment, including key vault, container app environment, app insights, and app configuration.

This approach aligns with the PR objective of using a user-assigned identity instead of a managed identity, which should help mitigate potential race conditions during deployment.

Consider adding a brief comment explaining the purpose of each parameter for improved clarity and maintainability. For example:

// Name of the Azure Key Vault containing environment-specific secrets
param environmentKeyVaultName = readEnvironmentVariable('AZURE_ENVIRONMENT_KEY_VAULT_NAME')
.azure/applications/service/test.bicepparam (2)

5-6: LGTM: Good use of environment variables. Consider adding default values.

The use of environment variables for imageTag and revisionSuffix is a good practice for dynamic configuration. To improve robustness, consider adding default values:

param imageTag = readEnvironmentVariable('IMAGE_TAG', 'latest')
param revisionSuffix = readEnvironmentVariable('REVISION_SUFFIX', '')

This ensures the deployment won't fail if these environment variables are not set, while still allowing for dynamic configuration.


8-12: LGTM: Good use of environment variables for configuration. Some improvements suggested.

  1. The use of environment variables for configuration is a good practice for security and flexibility.

  2. Consider updating the comment to better reflect the nature of these parameters:

// Azure resource configuration
  1. To improve robustness, consider adding default values or error handling for missing environment variables. For example:
param environmentKeyVaultName = readEnvironmentVariable('AZURE_ENVIRONMENT_KEY_VAULT_NAME', '')
param containerAppEnvironmentName = readEnvironmentVariable('AZURE_CONTAINER_APP_ENVIRONMENT_NAME', '')
param appInsightConnectionString = readEnvironmentVariable('AZURE_APP_INSIGHTS_CONNECTION_STRING', '')
param appConfigurationName = readEnvironmentVariable('AZURE_APP_CONFIGURATION_NAME', '')

// Add validation
@assert(environmentKeyVaultName != '', 'AZURE_ENVIRONMENT_KEY_VAULT_NAME must be set')
@assert(containerAppEnvironmentName != '', 'AZURE_CONTAINER_APP_ENVIRONMENT_NAME must be set')
@assert(appInsightConnectionString != '', 'AZURE_APP_INSIGHTS_CONNECTION_STRING must be set')
@assert(appConfigurationName != '', 'AZURE_APP_CONFIGURATION_NAME must be set')

This approach provides clear error messages if required environment variables are not set.

.azure/applications/service/main.bicep (1)

154-154: Finalize the use of user-assigned identities

There's a TODO comment indicating that once all container apps use user-assigned identities, the comment should be removed. Since this app is already using a user-assigned identity, consider addressing this TODO.

Apply this diff to remove the TODO comment:

     userAssignedIdentityId: managedIdentity.id
-    // TODO: Once all container apps use user-assigned identities, remove this comment and ensure userAssignedIdentityId is always provided
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1ae4f41 and c1ce84b.

📒 Files selected for processing (6)
  • .azure/applications/service/main.bicep (1 hunks)
  • .azure/applications/service/prod.bicepparam (1 hunks)
  • .azure/applications/service/staging.bicepparam (1 hunks)
  • .azure/applications/service/test.bicepparam (1 hunks)
  • .azure/modules/containerApp/main.bicep (3 hunks)
  • .github/workflows/workflow-deploy-apps.yml (1 hunks)
🧰 Additional context used
🔇 Additional comments (15)
.azure/applications/service/prod.bicepparam (3)

1-1: LGTM: Correct module import.

The import statement correctly references the main Bicep module using a relative path, which is appropriate for maintaining file structure consistency.


3-6: LGTM: Well-structured environment-specific parameters.

The parameters are appropriately defined:

  1. Hardcoding 'environment' and 'location' is suitable for a production-specific file.
  2. Using environment variables for 'imageTag' and 'revisionSuffix' enables dynamic configuration during deployment.

The use of 'REVISION_SUFFIX' aligns with the PR objective of mitigating race conditions during deployment, which is a good practice.


1-12: Overall assessment: Well-structured and aligned with PR objectives.

This Bicep parameter file for the production environment is well-structured and follows best practices. It effectively uses a combination of hardcoded values and environment variables to configure the deployment, which aligns well with the PR objectives of enhancing deployment capabilities and addressing potential race conditions.

The file covers all necessary parameters for production deployment, including environment-specific settings and secure handling of sensitive information. The use of environment variables for dynamic configuration and secrets is a good practice that enhances flexibility and security.

To ensure consistency across environments, let's verify the existence of similar parameter files for other environments:

✅ Verification successful

Environment parameter files are consistent across all environments.

All necessary Bicep parameter files for staging and test environments exist alongside the prod configuration. This ensures consistency and reliability across different deployment environments.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for the existence of similar Bicep parameter files for other environments

# Test: Check for staging and test parameter files
for env in staging test; do
  if [ -f ".azure/applications/service/${env}.bicepparam" ]; then
    echo "${env}.bicepparam exists"
  else
    echo "${env}.bicepparam does not exist"
  fi
done

Length of output: 284

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

1-1: LGTM: Correct import of the main Bicep file.

The import statement is correctly using a relative path to reference the main Bicep file, following best practices for modular Bicep deployments.

.azure/applications/service/staging.bicepparam (4)

1-1: LGTM: Correct file import.

The main Bicep file is properly imported using the 'using' statement, which follows Bicep best practices.


3-4: LGTM: Appropriate environment and location parameters.

The 'environment' and 'location' parameters are correctly defined for the staging environment. The use of 'norwayeast' as the location is valid and aligns with the PR objectives.


9-12: LGTM: Secure parameter management for sensitive information.

The use of environment variables for sensitive parameters (key vault, container app environment, app insights, and app configuration) is a good security practice and aligns with the PR objectives.

Ensure that all required environment variables are correctly set in your CI/CD pipeline. You can verify this by running the following script in your pipeline:

#!/bin/bash
# Description: Verify that required environment variables are set

required_vars=(
  "AZURE_ENVIRONMENT_KEY_VAULT_NAME"
  "AZURE_CONTAINER_APP_ENVIRONMENT_NAME"
  "AZURE_APP_INSIGHTS_CONNECTION_STRING"
  "AZURE_APP_CONFIGURATION_NAME"
)

for var in "${required_vars[@]}"; do
  if [ -z "${!var}" ]; then
    echo "Error: $var is not set"
    exit 1
  else
    echo "$var is set (value hidden for security)"
  fi
done

echo "All required environment variables are set"

Would you like assistance in updating the documentation to reflect these new environment variables and their purpose in the deployment process?


5-6: LGTM: Dynamic parameters for flexible deployment.

The use of environment variables for 'imageTag' and 'revisionSuffix' allows for dynamic configuration, which enhances deployment capabilities as per the PR objectives.

Ensure that the 'IMAGE_TAG' and 'REVISION_SUFFIX' environment variables are correctly set in your CI/CD pipeline. You can verify this by running the following script in your pipeline:

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

Line range hint 1-324: Summary of changes and considerations

The addition of the new "service" to the deployment matrix is the only change in this workflow file. This modification aligns with the PR objectives and extends the existing deployment process to include the new service.

Consider the following points for the overall implementation:

  1. Ensure that all necessary Bicep files and configurations for the new service are in place and properly tested.
  2. Update any relevant documentation to reflect the addition of this new service to the deployment process.
  3. Consider adding a brief description or comment in the workflow file to explain the purpose of the new service for future reference.
  4. After deployment, verify that the new service is functioning correctly in all environments.
.azure/modules/containerApp/main.bicep (5)

34-36: Optional userAssignedIdentityId parameter added correctly

The introduction of the userAssignedIdentityId parameter with a default empty string is appropriate. This allows for optional usage of user-assigned identities until it becomes a requirement for all container apps.


57-65: Conditional identity configuration is well-implemented

The identityConfig variable correctly sets the identity type based on whether userAssignedIdentityId is provided. This ensures that the container app uses a system-assigned identity by default or a user-assigned identity when specified.


69-69: Identity configuration included in container app resource

Adding identity: identityConfig to the containerApp resource correctly applies the identity settings as per the configured identity type.


95-97: Existing user-assigned identity referenced appropriately

The managedIdentity resource correctly references the existing user-assigned managed identity when userAssignedIdentityId is provided. Extracting the name using last(split(userAssignedIdentityId, '/')) is an effective method.


99-99: Output identityPrincipalId conditionally returns the correct principal ID

The output for identityPrincipalId appropriately selects the principal ID from the system-assigned identity or the user-assigned identity based on the presence of userAssignedIdentityId.

.azure/applications/service/main.bicep (1)

57-74: Verify Application Insights connection string handling

Ensure that the appInsightConnectionString parameter is correctly being passed and used securely. Since it's sensitive information, confirm that it is stored and referenced properly without exposure.

Consider running the following script to check for any inadvertent exposures:

Comment on lines +3 to +4
param environment = 'test'
param location = 'norwayeast'
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 16, 2024

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider using environment variables for environment and location.

While the current setup is functional, using environment variables for environment and location parameters could provide more flexibility:

param environment = readEnvironmentVariable('ENVIRONMENT', 'test')
param location = readEnvironmentVariable('AZURE_LOCATION', 'norwayeast')

This approach allows for easier configuration changes without modifying the Bicep file, while still maintaining default values.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the bicepparam file is only used for that environment, so would be overkill to supply environment too right?

I'll make a note of AZURE_LOCATION for later, good point!

Copy link
Contributor

Choose a reason for hiding this comment

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

@arealmaas, you make a great point—it might be unnecessary to supply the environment parameter via an environment variable since the bicepparam file is only used for that specific environment. Thanks for considering the suggestion about AZURE_LOCATION!

(_/_)
(•︵•)


✏️ Learnings added
Learnt from: arealmaas
PR: digdir/dialogporten#1303
File: .azure/applications/service/test.bicepparam:3-4
Timestamp: 2024-10-16T08:43:00.537Z
Learning: When working with environment-specific bicepparam files, it's unnecessary to supply the `environment` parameter via environment variables because each bicepparam file is only used for that specific environment.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

.github/workflows/workflow-deploy-apps.yml Show resolved Hide resolved
Comment on lines +24 to +25
@secure()
param containerAppEnvironmentName string
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove @secure() from non-sensitive parameter

The containerAppEnvironmentName parameter is annotated with @secure(), which is typically used for sensitive data like passwords or connection strings. Since this parameter represents a resource name and is not sensitive, consider removing the @secure() attribute to avoid unnecessary restrictions.

Apply this diff to remove the @secure() attribute:

 @description('The name of the container app environment')
 @minLength(3)
-@secure()
 param containerAppEnvironmentName string
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@secure()
param containerAppEnvironmentName string
@description('The name of the container app environment')
@minLength(3)
param containerAppEnvironmentName string

.azure/applications/service/main.bicep Outdated Show resolved Hide resolved
.azure/applications/service/main.bicep Outdated Show resolved Hide resolved
.azure/applications/service/main.bicep Show resolved Hide resolved
Comment on lines +162 to +163
output name string = containerApp.outputs.name
output revisionName string = containerApp.outputs.revisionName
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider outputting the managed identity principal ID

If other resources need to reference the managed identity's principal ID, it might be helpful to output it.

You can add the following output:

 output name string = containerApp.outputs.name
 output revisionName string = containerApp.outputs.revisionName
+output managedIdentityPrincipalId string = managedIdentity.properties.principalId

Committable suggestion was skipped due to low confidence.

.azure/applications/service/main.bicep Show resolved Hide resolved
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarCloud

@arealmaas arealmaas merged commit a309044 into main Oct 16, 2024
23 of 24 checks passed
@arealmaas arealmaas deleted the feat/deploy-service branch October 16, 2024 10:24
arealmaas pushed a commit that referenced this pull request Oct 17, 2024
🤖 I have created a release *beep* *boop*
---


##
[1.25.0](v1.24.0...v1.25.0)
(2024-10-17)


### Features

* **applications:** add scalers for cpu and memory
([#1295](#1295))
([eb0f19b](eb0f19b))
* **infrastructure:** create new yt01 app environment
([#1291](#1291))
([1a1ccc0](1a1ccc0))
* **service:** add permissions for service-bus
([#1305](#1305))
([7bf4177](7bf4177))
* **service:** deploy application in container apps
([#1303](#1303))
([a309044](a309044))


### Bug Fixes

* **applications:** add missing property for scale configuration
([3ffb724](3ffb724))
* **applications:** use correct scale configuration
([#1311](#1311))
([b8fb3cc](b8fb3cc))
* Fix ID-porten acr claim parsing
([#1299](#1299))
([8b8862f](8b8862f))
* **service:** ensure default credentials work
([#1306](#1306))
([b1e6a14](b1e6a14))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants