Using GitLab CI/CD
GitLab CI/CD is a continuous integration and continuous deployment service integrated into GitLab repositories. It automates the processes of building, testing, and deploying software, streamlining software development workflows.
This guide shows how to integrate Continuous Delivery with Git in Appsmith, enabling automatic updates to the master branch with GitLab CI/CD. This eliminates the need for manual pulling after each update.
Prerequisites
- A self-hosted instance of Appsmith. Refer to the Appsmith installation guides for detailed instructions on setting up your Appsmith instance.
- An app that is already connected with Git. See How to Connect Git Repository.
- Basic knowledge of GitLab CI/CD.
Configure continuous delivery
Follow these steps to configure GitLab CI/CD workflow and automate continuous delivery for your Appsmith application:
-
In GitLab, go to Build tab and select Pipelines.
-
Select one of the available templates. If you're unsure, use the test template.
-
Configure the YAML file. Alternatively, you can directly create a file named
gitlab-ci.yml
within your project directory. GitLab requires the filename to be exactly asgitlab-ci.yml
.
This YAML code configures a GitLab Pipeline to execute a deployment task using the curl
command provided by Appsmith.
stages:
- deploy
deploy-job:
stage: deploy
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
when: always
- when: never
script:
# - echo $APPSMITH_CD
- "curl --location --fail-early --request POST https://app.appsmith.com/api/v1/git/deploy/app/66042fd670bf652918?branchName=master --header \"Authorization: Bearer $APPSMITH_CD\""
-
Open your Appsmith application and then select Git Settings located on the left side of the bottom bar.
-
Click on the Continuous Delivery tab.
-
Select the branch where you want to implement continuous delivery. For example, the
master
branch or anyfeature
branch. -
Copy the Appsmith-provided endpoint and paste it into your CI/CD pipeline configuration. Replace the
curl
command with the command provided by Appsmith(as mentioned in the YAML file in step 3). -
Generate and copy the bearer token for authenticating requests to the provided endpoint. Save this token for future reference. Once done, click the Finish Setup button in your Appsmith application.
-
In GitLab, add the bearer token. It is recommended that you create secrets or secure variables instead of directly adding them to the repository.
Example: You can use GitLab's variables and secrets to securely store your bearer token. Add your token as a variable within the CI/CD settings of your repository. Subsequently, in your YAML file, use the token using $GITLAB_CD_TOKEN
, like:
Replace:
- 'Authorization: Bearer <bearer token>'
With:
- "Authorization: Bearer $GITLAB_CD_TOKEN\"
For information see GitLab CI/CD variables.
-
Commit the YAML file changes to the repository.
-
To check the status, open the Pipelines tab:
Upon successful completion of the run, you can monitor the pipeline's status, access detailed log information from its execution, and gather various other data. For information see GitLab CI/CD pipelines.
Test the continuous delivery
Follow these steps to test continuous delivery after you have committed the YAML workflow file and added the bearer token:
-
Open the Appsmith App and create a new feature branch.
-
Commit & Push your modifications to the designated feature branch.
-
Open the repository and raise a pull request.
-
When you merge this into the
master
or specified branch, the pipeline workflow automatically triggers and updates the deployed version and branch accordingly.
The changes are deployed to that branch without the need to pull the changes manually. Additionally, the live version of the Appsmith app reflects those changes.