CI/CD - Integrate With GitHub Actions
Introduction
This article helps you to quickly configure your project for integration with GitHub Actions.
Every templates comes with the .github/workflows/build-application.yaml
file configured to build and create the application package on the Torizon Cloud.
Pre-requisites
- GitHub account
- GitHub Repository
- Torizon Cloud API v2 Client
- Torizon Cloud credentials.zip
- Project
fill-pipeline-settings
task executed at least once. See the respective Workspace Task for more information.
Configure the GitHub Repository
After creating the GitHub repository, you need to configure the secrets and variables to be used in the GitHub Actions workflow.
- In the repo page, click on the
Settings
tab:
- Click on the
Secrets and variables
tab:
- Click on the
Actions
:
This will load the Actions secrets and variables
section.
Adding Secrets
In the Actions secrets and variables
section, click on the New repository secret
:
This will load the New secret
section. In the Name
field, type the name of the secret. In the Value
field, type the value of the secret. Then, click on the Add secret
button:
Then, you will see the secret added to the list:
Do it for all the secrets listed below:
DOCKER_PSSWD
: DockerHub registry login password. This is the password from the login name that comes from thedocker_login
property, from.vscode/settings.json
, see Workspace Settings for more information.PLATFORM_CLIENT_ID
: Torizon Cloud API v2 Client ID. See Creating a New Torizon Cloud API v2 Client for more information.PLATFORM_CLIENT_SECRET
: Torizon Cloud API v2 Client Secret. See Creating a New Torizon Cloud API v2 Client for more information.
Adding credentials.zip as CI/CD Variable
To use the TorizonCore Builder to create the Torizon Cloud package, we need the credentials.zip
file available in the CI/CD pipeline. The .github/workflows/build-application.yaml
expectes to have the PLATFORM_CREDENTIALS
secret with the base64 encode of the credentials.zip
file. Execute the follow command to get the base64 encode of the credentials.zip
file:
$ base64 -w 0 ./credentials.zip
Then, copy the output and paste it in the Secret*
field from New secret
section.
Running the GitHub Actions Workflow
After configuring the secrets, your GitHub repository is ready to run the GitHub Actions workflow. Simply push your changes to the repository and the workflow will be triggered automatically.
The following steps will be executed:
Initial Setup
: This step will verify the environment variables and secrets configured in the repository. If any of the required variables or secrets are missing, the workflow will fail fast in this first step;Decode Credentials
: This step will decode thePLATFORM_CREDENTIALS
secret into thecredentials.zip
file. This file is used by TorizonCore Builder to authenticate with the Torizon Cloud;Create and Publish Image
: This step will run the tasktcb-platform-publish
that depends on thecreate-production-image
task. This task will create the production image and publish it to the Torizon Cloud. See the respective Workspace Task for more information.Deploy Application
: This step will run the taskplatform-update-fleet
. This task will deploy the application to the Torizon Cloud fleet defined in thetcb.fleetName
property from.vscode/settings.json
. See the respective Workspace Task for more information.
The Deploy Application
step will only be executed for a push on the main
branch. If you want to trigger an update when pushing in a different branch, you need to change the if
condition in the Deploy Application
step from the .github/workflows/build-application.yaml
file. Check the templates repository file: https://github.com/toradex/vscode-torizon-templates/blob/bookworm/assets/github/workflows/build-application.yaml#L55
At the end of the pipeline, if all occurs as expected, you will have the following in the repo Actions
tab:
And the Torizon Cloud update will be triggered, you should have the devices from the fleet with Update pending
state: