DEV Community

Cover image for GitHub Actions & Napptive
Napptive
Napptive

Posted on • Originally published at napptive.com

GitHub Actions & Napptive

No one can deny the beauty of an automated workflow. It takes charge of tedious tasks, such as executing commands to build, test and deploy, so that you can spend more time developing. If you use GitHub Actions for your CI/CD workflow, or you’re thinking about doing so, and wonder how GitHub Actions and Napptive go together, this tutorial is for you.

Using GitHub Actions for your CI/CD

If you already know and love GitHub Actions, you can totally skip this section. Otherwise, let’s begin with a little intro about it.

Is it for me?
GitHub Actions is a platform for automating developer workflows. It’s not just limited to CI/CD, as it could automate other organizational tasks like reviewing pull requests and merging them to the master branch. However, it comes in really handy for CI/CD. First of all, because it’s part of the largest open-source project platform, so you probably already have your code there.

In addition, it’s been created so that setting up a pipeline that uses different tools is really easy:

You just need to call for a fresh environment with all the tools you need already installed in it.
You can select a template for your pipeline from a wide range that includes almost every technology under the sun.
And lastly, it’s meant for developers that don’t necessarily have a DevOps person to build a CI/CD pipeline for them.

How does it work?
To create a workflow in GitHub Actions, you need to create a YAML declaration file in your repository’s .github/workflows directory.

There, you first declare which events trigger your workflow. For example, a pull request on the master branch.

Then, you define one or more jobs that compose the workflow. By default, they run in parallel on different runners. Every runner is a fresh, newly-provisioned virtual machine, and you can choose between Ubuntu Linux, Microsoft Windows, and macOS.

A job is a set of steps that are executed in order in the same runner. Each step is either a command or an action. Actions are custom applications for the GitHub Actions platform that performs a complex but frequently repeated task, like setting up the authentication to your cloud provider. You can write your own actions, or you can find actions to use in your workflows in the GitHub Marketplace.

You can learn more on the GitHub Docs page or watch Nana explain it here.

GitHub Actions and Napptive

One of the main benefits of cloud-native applications is the ability to deliver features as soon as possible to your customers. Therefore, a CI/CD pipeline becomes a must for cloud-native development.

In this type of scenario, the developer will make changes in the codebase and submit them as part of a pull/merge request. That pull/merge request will be evaluated by other team members for correctness, and will also be analyzed by a CI/CD pipeline. This pipeline includes stages such as compiling the code, performing unit tests, running linters, executing integration and end-to-end tests, etc.

Once all the required tests have passed, and the request is approved, another pipeline is triggered. This new CD pipeline is usually involved in creating and publishing the container images, rendering the YAML files required to deploy a component, and either publishing the results to another repository for a GitOps approach, or pushing the changes to a target Kubernetes cluster.

The Napptive Playground provides a method to easily get on-demand Kubernetes namespaces that can be used for many of the CI/CD use cases, from integration testing to deployment of the newly released application. We have created a demo application with NodeJS to showcase how you can use GitHub Actions together with Napptive to deploy an application.

How to use GitHub Actions with Napptive

In this demo tutorial, we’ll be using the application at https://github.com/napptive/example-app-nodejs but, before you start, you need a Napptive account.

The example pipelines
The demo repository already contains two pipelines in the .github/workflows/ directory. The deploy-app.yaml workflow consists of the following jobs:

Building the code.
Running unit and integration tests.
Generating the Docker images and uploading them to /example-app-nodejs-api: and /example-app-nodejs-api-at-runner:.
Uploading the application definition to the Napptive catalog, storing the application as /example-app-nodejs: and /example-app-nodejs-at: respectively.
Creating a new fresh environment named /todo-at-.
Launching the demo application and the acceptance test runner.
Removing the acceptance test environment when the previous job is finished, as it will no longer be used.
And, if the tests are successful:

Creating the production environment /todo-app-prod
Deploying the application from the catalog if it doesn’t exist, or patching the component version to use the new version if it does.
Napptive Actions
If you look closely at the code in the deploy-app.yaml file, you’ll notice three different Actions that allow you to interact with the Napptive playground:

Action

Description

playground-github-action

The playground action allows you to execute any command from the playground CLI. Use this action to manage environments, orchestrate deployment, etc.

catalog-deploy-action

This action allows you to deploy an application from the catalog. Use this action to deploy the application under tests, a testing backend, or to deploy the application in production once the tests pass.

catalog-push-action

This action allows you to push a new application to the catalog. Use this action to publish application revisions for testing or new releases for production workloads.

Click the links to learn how to take full advantage of them.

Run the demo

Navigate to https://github.com/napptive/example-app-nodejs and fork the example to your own repository by clicking on the Fork icon on the top right of the GitHub page. You will also get a copy of the workflows in your fork.
Generate a Personal Access Token and save the results in a secret called PLAYGROUND_PAT. Make sure the repository can access the value of the secret in case you’re using an organization one.
Generate Docker Access Tokens and store the resulting values in two secrets: DOCKER_HUB_USER and DOCKER_HUB_TOKEN.
Select the Actions tab and click the green button to enable the copied workflows.
Edit .github/workflows/deploy-app.yml to modify the value of TARGET_DOCKER_REGISTRY with your Docker username and the value of PLAYGROUND_ACCOUNT_NAME with your Napptive username.
Commit your changes to your repository, accept the PR if you are using this approach, and check the triggered action in the Actions tab.
Once the pipeline has been executed, you can connect to the Napptive Playground and you’ll see your application running. First, select the todo-app-prod environment on the top left selector, and click on the example-app-nodejs application. After that, expand the application and click on the endpoint link to receive the welcome message.
Now, try editing server.js and changing the welcome message, and increasing the version file:
// Change this line to easily check that the running application has changed.

app.get(‘/’, (req, res) => {

res.send(‘Hello World!’)

})

Commit the changes, and you’ll see the updated app running after the GitHub Actions pipeline is executed once more.
Conclusion
GitHub Actions is a great tool that allows developers to easily create CI/CD pipelines. Now you know how to use it to automatically get your cloud-native app up and running in Napptive!

In case you have not yet tried Napptive, we encourage you to sign up for free and discover how we are helping propel the development of cloud-native apps.

Top comments (0)