Jovo CLI With GitHub Actions CI/CD
In this article, I’ll show you how to set up GitHub Actions to do continuous integration/continuous deployment (CI/CD) with Jovo.
You can also take a look at a previous article I published about doing continuous integration in Bitbucket Pipelines.
So, let’s get started on how to set up GitHub Actions to run CI/CD pipeline.
1. Configure the nodejs.yml File
When you work with GitHub Actions, you can add a file named nodejs.yml
into this path of your project: /.github/workflows/nodejs.yml to define the CI/CD instructions. Here’s the file I have in my repository:
In the pull_request section, I have defined the branches I want this yml file to run for when a new Pull Request is opened. I have also defined the steps that I want to run for Continuos Integration:
- NODE_ENV=development
- npm install
- npm run lint
- npm run test
2. Configure the deploy-production.yml File
You can name the .yml files with whatever name you want, there’s no any special nomenclature to follow for these names. I created this file in the following path /.github/workflows/deploy-production.yml to push the code to my production environment, as well as the Alexa and Dialogflow resources.
In the push section, I have defined the branches I want this yml file to run for when a commit is merged. I have also defined the steps that I want to run for Continuos Deployment:
- npm install
- echo “jovo -v”
- jovo -v
- sh ./scripts/deployLambda.sh prod
- sh ./scripts/deployAlexa.sh prod
- sh ./scripts/deployGoogle.sh prod
In the container section of the file, you’ll see the Docker image used: omenocal/jovo-deploy
. You can find it on this link. This Docker image was built using this repository:
Shout out to Ben Force for creating this Jovo Docker image!
I cloned the repository and created my own Docker image without changing anything. You can do that if you want to have your image in your own Docker account. At this link, you can find instructions to create a Docker image.
Thanks to this image mounted in the CD process, we can use the ASK CLI and the Jovo CLI because they are preinstalled.
My deployLambda.sh
file is here:
My deployAlexa.sh
file is here:
You’ll notice the environment variable $ASK_CLI_CONFIG
. You can set up your environment variables in Secrets section of your GitHub Repository settings, and this is what the next section is about.
3. GitHub Secrets
To set up your GitHub Workflow, you need to have admin privileges on your repository. Go to the Settings tab, and on the left section, click on the Secrets label.
In this screen you’ll be able to set up the environments variables used to push the code to AWS Lambda, and push the interaction model to the Alexa Developer Console, and the agent to Dialogflow.
I know you are wondering why you need so many environment variables. Well, you probably don’t need all of them. Let’s take a look at the project.js file of my Jovo project:
Look how I have added some of these environment variables to define values per environment. If you don’t have this kind of setup you probably DON’T need the following variables:
- API_GATEWAY_ENDPOINT
- API_GATEWAY_KEY
- ASK_PROFILE
- DIALOGFLOW_PROJECT_ID
- LAMBDA_FUNCTION_ARN
- SKILL_ID
So, let’s take a look at the ones you do need to deploy your voice app. To automate deployments with Jovo CLI to push your code to your AWS Lambda function, your agent to Dialogflow, and to your interaction model to the Alexa Developer Portal, you need five environment variables:
AWS_ACCESS_KEY_ID && AWS_SECRET_ACCESS_KEY
: You can create access keys in the AWS IAM dashboard of your AWS account. You only need to attach a policy with thelambda:UpdateFunctionCode
permission to an IAM user on the Lambda function to upload the code of your project.AWS_DEFAULT_REGION
: the region for which your Lambda function is created — for example, us-east-1ASK_CLI_CONFIG
: This is a JSON string the ASK CLI uses to deploy the skill metadata and interaction model to the Alexa developer console. This string looks like this:
To build the file with this string in your computer, you need to set up a profile using the ASK CLI in your computer. When you set up the profile, this file will be created in the home
path of your computer. In Linux and Mac computers, you can find it in here: ~/.ask/cli_config
.
Grab the access_token
and refresh_token
values, and place them into this JSON string. Then, paste it into the environment variable in your deployment configuration.
GOOGLE_SERVICE_ACCOUNT_KEY
: this is the JSON key you create in your Google Cloud Project with the Actions API Enabled and with Dialogflow Admin permissions granted. For more information on how to get this key, follow this link: Deploying your Dialogflow Agent using the Jovo CLI.
Take a look at my deployGoogle.sh file:
You can see in this is file that I use the service account key to deploy my app to Dialogflow.
4. Send a Pull Request for CI
When you open a pull request, the workflow will execute the pull_request portion of the configuration file in your GitHub repository to run ESLint and tests. This is how it looks like:
5. Merge Pull Request for CD
When you merge this pull request into the master branch, a merge commit will be pushed to the branch, and the deployment process will be triggered.
Final Words
At this point, you should be able to see your AWS Lambda function — as well as your Alexa Skills metadata and interaction model updated.
Jovo CLI has a set of useful commands to create new voice apps, to build the interaction models for Alexa Skills and the Dialogflow agents for your Google actions, and also to deploy the source code to your Lambda functions. You can automate this process by leveraging the CI/CD automation tools from your repository.
For more information about Jovo CLI, check out the official documentation.
Thanks for reading!
A note from the Plain English team
Did you know that we have four publications? Show some love by giving them a follow: JavaScript in Plain English, AI in Plain English, UX in Plain English, Python in Plain English — thank you and keep learning! We’ve also launched a YouTube and would love for you to support us by subscribing to our Plain English channel
And as always, Plain English wants to help promote good content. If you have an article that you would like to submit to any of our publications, send an email to submissions@plainenglish.io with your Medium username and what you are interested in writing about and we will get back to you!