Achieving Continuous Deployment of Applications with GitOps
GitOps is a continuous delivery method that uses Git repositories as the single source of truth for application configuration and deployment.This article details how to implement the GitOps continuous deployment process on the Rainbond platform, including code repository integration, automatic build configuration, and the complete deployment process.
Rainbond supports two GitOps continuous deployment methods:
- Integrate Git repository via OAuth, create components based on source code by turning on the automatic build button, Rainbond will automatically configure WebHook in the corresponding repository.
- Manually configure WebHook, set the WebHook address in the code repository, and configure trigger conditions.
Preconditions
- Rainbond platform installed and configured
- Have administrator permissions for code repositories such as GitHub, GitLab, or Gitee
- Have team administrator or platform administrator permissions for the Rainbond platform
- Ensure network connectivity, code repositories and Rainbond platform can access each other
1. Integrate code repository and configure automatic build
Rainbond supports integration with various Git code repositories, achieving authorization and authentication through the OAuth protocol, currently supporting GitHub, GitLab, and Gitee code repositories.
Integrate GitHub
Create GitHub OAuth Apps
- Log in to GitHub account, go to Settings -> Developer settings -> OAuth Apps -> New OAuth App
- Fill in the following information:
- Application name: Custom application name, such as "Rainbond GitOps"
- Homepage URL: Rainbond access address, such as
https://rainbond.com
- Authorization callback URL: Callback address, format as
{Rainbond address}/console/oauth/redirect
, such ashttps://rainbond.com/console/oauth/redirect
- Click Register application to complete creation
- After creation, record the generated Client ID and Client Secret
Configure OAuth in Rainbond
- Log in to Rainbond platform,
- Global configuration: go to Platform Management -> Settings -> Basic Settings -> OAuth Third-party Service Integration -> Add
- Personal configuration: go to Personal Center -> Git Private Repository -> Add
- Fill in the following information:
- OAuth Type: Select github
- Name: Custom name, such as "GitHub"
- Client ID: Fill in the Client ID from GitHub OAuth Apps
- Client Secret: Fill in the Client Secret from GitHub OAuth Apps
- Callback Address: Default is the current Rainbond access address
- Click Confirm to complete configuration
Integrate GitLab
Create GitLab Applications
- Log in to GitLab account, go to User Settings -> Applications
- Fill in the following information:
- Name: Custom name, such as "Rainbond GitOps"
- Redirect URL: Callback address, format as
{Rainbond address}/console/oauth/redirect
, such ashttps://rainbond.com/console/oauth/redirect
- Scopes: Check
api
read_user
read_repository
- Click Save application to complete creation
- Record the generated Application ID and Secret
Note: If using GitLab 10.6 or above, you need to allow sending Webhook requests to the local network.Go to Admin area -> settings -> OutBound Request, check
Allow requests to the local network from hooks and services
.
Configure OAuth in Rainbond
- Log in to Rainbond platform,
- Global configuration: go to Platform Management -> Settings -> Basic Settings -> OAuth Third-party Service Integration -> Add
- Personal configuration: go to Personal Center -> Git Private Repository -> Add
- Fill in the following information:
- OAuth Type: Select gitlab
- Name: Custom name, such as "GitLab"
- Service Address: GitLab access address, such as
https://gitlab.example.com
- Client ID: Fill in the Application ID from GitLab Applications
- Client Secret: Fill in the Secret from GitLab Applications
- Callback Address: Default is the current Rainbond access address
- Click Confirm to complete configuration
Integrate Gitee
Create Gitee Third-party Application
- Log in to Gitee account, go to Settings -> Third-party Applications -> Create Application
- Fill in the following information:
- Application Name: Custom name, such as "Rainbond GitOps"
- Application Homepage: Rainbond access address, such as
https://rainbond.com
- Application Callback Address: Callback address, format as
{Rainbond address}/console/oauth/redirect
, such ashttps://rainbond.com/console/oauth/redirect
- Permissions: Check
user_info
projects
hook
- Click Create Application to complete the creation
- Record the generated Client ID and Client Secret
Configure OAuth in Rainbond
- Log in to the Rainbond platform,
- Global configuration: Go to Platform Management -> Settings -> Basic Settings -> OAuth Third-party Service Integration -> Add
- Personal configuration: Go to Personal Center -> Git Private Repository -> Add
- Fill in the following information:
- OAuth Type: Select gitee
- Name: Custom name, such as "Gitee"
- Service Address: Fill in
https://gitee.com
- Client ID: Fill in the Client ID from the Gitee third-party application
- Client Secret: Fill in the Client Secret from the Gitee third-party application
- Callback Address: Default is the current Rainbond access address
- Click Confirm to complete the configuration
OAuth account authentication
After completing the OAuth configuration, account authentication is required to connect with the third-party platform:
- Click the user avatar in the upper right corner of the Rainbond page
- Select Personal Center -> OAuth Account Binding
- On the corresponding code repository platform (GitHub/GitLab/Gitee), click Go to Authentication
- Follow the page instructions to complete the authorization authentication process
Create an application based on the source code repository and configure automatic deployment
- After completing the code repository connection, you can create an application based on the source code and configure automatic deployment.
- Enter the Rainbond team view, click Add -> Create Component Based on Source Code
- Select the connected code repository (GitHub/GitLab/Gitee)
- Browse and select the code project to be deployed
- Fill in basic information such as component name, application name
- Turn on the Auto Build switch.
- Click Create Component to start building
- After the component is created, you can configure automatic builds to achieve automatic deployment after code submission:
- Enter the component details page, click Build Source
- Set a trigger keyword, such as
@deploy
(can be customized)
Note: The trigger keyword is a specific string included in the Git commit information. Only when the submission information contains this keyword will the automatic build be triggered.
Manually configure Webhook to achieve automatic build
Enable Rainbond Git Webhook
Enable component Git Webhook In Component -> Build Source, turn on the Git-Webhook auto-build function, and copy the generated hook address.
Configure Git repository Webhooks
GitHub Configuration
Enter the GitHub project, Settings -> Webhooks -> Add webhooks
- Payload URL: Copy the Webhook address in Rainbond
- Content type:
application/json
- Just the push event: Select
push
trigger event - Active: Check
Active
GitLab Configuration
Enter the GitLab project, Settings -> Integrations -> Add webhooks
- URL: Copy the Webhook address in Rainbond
- Trigger: Check Push events
The configuration methods for other code repositories are similar. It should be noted that Rainbond hook triggering currently does not support secure request verification.
GitOps Continuous Deployment Practice
3.1 Complete GitOps Workflow
A complete GitOps workflow includes the following steps:
- Developers modify code in the local development environment
- Submit code to the Git repository, including the trigger keyword (such as
@deploy
) in the commit information - The Git repository notifies the Rainbond platform via Webhook
- Rainbond detects that the submission information contains the trigger keyword and automatically pulls the latest code
- Rainbond automatically builds and deploys the application
- Application update completed, developers can immediately see the latest changes
3.2 Best Practices
It is recommended to configure different branches and automatic build strategies for different environments:
- Development Environment: Configure automatic builds for the
develop
branch, which can use more relaxed trigger conditions - Test Environment: Configure automatic builds for the
test
orstaging
branch, using explicit trigger keywords - Production Environment: Configure automatic builds for the
master
ormain
branch, it is recommended to add manual review steps
common problem
Webhook did not trigger automatic build
Possible reasons:
- The commit information does not contain the trigger keyword
- Webhook configuration is incorrect or the URL is wrong
- Network connection issues caused the Webhook request not to reach Rainbond
- GitLab version is higher and does not allow local network Webhook requests
Solution:
- Check if the commit information contains the correct trigger keyword
- Check the delivery status of the Webhook on the Webhook configuration page of the code repository
- For privately deployed GitLab, check if the option "Allow sending Webhook requests to the local network" is enabled