Bare Metal Cloud GitHub Actions

Introduction

GitHub Actions is a platform for software development workflow automation with a built-in CI/CD tool. The platform is easy to use and does not require a third-party app or prior expert knowledge and a dedicated person for maintenance.

PhoenixNAP Bare Metal Cloud GitHub actions serve as an automated task runner that reacts to GitHub events in your git repository. Without spinning up another server, you can achieve the desired CI/CD functionality directly from GitHub.

Bare Metal Cloud GitHub actions

Prerequisites

What is BMC GitHub Action?

A Bare Metal Cloud GitHub action is defined by the corresponding action.yaml file. Each BMC action repository has a dedicated action.yaml file with the code created for that specific action, such as create-server-bmc.

The yaml file describes how to run the action, defines the main JavaScript file, in this case index.js, and the function metadata. You can combine these JavaScript-based BMC actions and incorporate them into your workflows to achieve the desired level of automation.

Note: Are you transitioning to DevOps? Consider these 9 DevOps Principles you need to adopt.

BMC GitHub Credentials

GitHub repository supports fully encrypted secret environment variables. You then reference clientid and clientsecret in the workflow yaml file. BMC actions get access to your secret only once you add them to your repository.

Once you add credentials to your repository or organization, the values are not visible when you run an action.

The values are not visible when adding credentials to a repository or organization

To obtain BMC Client ID and Client Secret, log in to the Bare Metal Cloud portal and:

1. Navigate to the API Credentials page.

2. Click the Create Credentials button.

Creating credentials on the API Credentials page

3. Add the credential name and optional description in the respective fields.

4. Assign permissions scopes. Check the box next to the permission level you want to grant to the credentials. Choose if you want to allow the usage of all or read-only BMC API calls.

5. Click Create when ready.

Creating credential name and description and selecting permission scopes

6. You will get the Client ID and Client Secret in the confirmation window.

Confirmation window for API credentials creation

7. Copy the credentials and add them to your GitHub repository as Secret. Go to Settings - > Secrets and click Add a new secret.

Adding a new secret for storing credentials

Note: You should not hardcode your credentials due to security concerns.

PhoenixNAP BMC GitHub Actions Repository

Our BMC GitHub Actions repository currently contains three actions:

You can combine BMC actions with other actions to create your custom jobs and workflows.

Create New BMC Server GitHub Action

The create-server-bmc GitHub action allows you to automate the server creation process. You can create a workflow that installs software testing applications and when you need more resources to spin up a new BMC server automatically.

This action outputs the new server ID and public IP addresses in a list with comma-separated values. The action is synchronous. However, the server creation and boot process are asynchronous.

Note: The actions in your workflow that follow create-server-bmc should probe for machine readiness.

Required Inputs

Every GitHub action has mandatory elements. The create server action must include:

  • clientid: Client ID from application OAuth2 credentials.
  • clientsecret: Client Secret from application OAuth2 credentials.
  • hostname: Hostname of server. The name must follow this pattern: 1 ≤ length ≤ 100 matches ^(?=.*[a-zA-Z])([a-zA-Z0-9().-])+$

Optional Inputs

Optional inputs for the create-server-bmc GitHub action are:

  • image: The server’s OS ID. Defaults to ubuntu/bionic.
  • type: Server type ID. Defaults to s1.c1.small.
  • location: Server Location ID. You cannot change the location once a server is created. You can set this field to PHX or ASH. The default value is PHX.
  • bmcentrypoint: The BMC API entrypoint. Defaults to https://api.phoenixnap.com/bmc/v1/.
  • bmctokenhost: The BMC OIDC token host. Defaults to https://auth.phoenixnap.com.
  • bmctokenpath: The BMC OIDC token path. Defaults to /auth/realms/BMC/protocol/openid-connect/token.

Outputs

The create-server-bmc action has the following output:

  • id: The new BMC server ID.
  • ipaddresses: A comma-separated list of public IP address attached to the new server.

Example Usage for Create BMC Server Action

Below is the example for the create server action:

- name: CreateBMCServer step
  uses: phoenixnap-github-actions/create-server-bmc 
  id: createserver
  with:
    clientid: ${{secrets.BMC_CLIENT_ID}}
    clientsecret: ${{secrets.BMC_CLIENT_SECRET}}
    hostname: "bmc-gha-test"
    image: "ubuntu/bionic"
    location: "ASH"
    type: "s1.c1.small"
    description: "This server is created using GitHub Actions."

Get BMC Server Information GitHub Actio

The get-server-bmc action retrieves basic information about a Bare Metal Cloud server. This synchronous action obtains most of the details provided during the create BMC server action.

Required Inputs

Required inputs for the get-server-bmc action are:

  • clientid: Client ID from application OAuth2 credentials.
  • clientsecret: Client Secret from application OAuth2 credentials.
  • serverid: The ID of the server for which to get the information. The ID is created during the create server step.

Optional Inputs

These are the optional inputs for get-server-bmc GitHub action:

  • bmcentrypoint: The BMC API entrypoint. Defaults to https://api.phoenixnap.com/bmc/v1/.
  • bmctokenhost: The BMC OIDC token host. Defaults to https://auth.phoenixnap.com.
  • bmctokenpath: The BMC OIDC token path. Defaults to /auth/realms/BMC/protocol/openid-connect/token.

Outputs

The create-server-bmc action provides this output:

  • id: The BMC server ID.
  • status: The server operational status.
  • hostname: The server hostname.
  • ipaddresses: A comma-separated list of public IP address attached to the server.

Example Usage for Create BMC Server Action

Below is the example usage for the create server action:

- name: GetServer step
  uses: phoenixnap-github-actions/get-server-bmc  
  id: getserver
  with:
    clientid: ${{secrets.BMC_CLIENT_ID}}
    clientsecret: ${{secrets.BMC_CLIENT_SECRET}}
    serverid: ${{ steps.createserver.outputs.id }}

Delete BMC Server GitHub Action

The delete-server-bmc GitHub action deletes a Bare Metal Cloud server. The action is synchronous, while deletion and cleanup are asynchronous.

Warning: Use the delete action with extreme caution as it cannot be undone and may result in data loss.

Required Inputs

Required inputs for the delete-server-bmc action are:

  • clientid: Client ID from application OAuth2 credentials.
  • clientsecret: Client Secret from application OAuth2 credentials.
  • serverid: The ID of the server you want to delete. The ID is created during the create server step.

Optional Inputs

These are the optional inputs for delete-server-bmc GitHub action:

  • bmcentrypoint: The BMC API entrypoint. Defaults to https://api.phoenixnap.com/bmc/v1/.
  • bmctokenhost: The BMC OIDC token host. Defaults to https://auth.phoenixnap.com.
  • bmctokenpath: The BMC OIDC token path. Defaults to /auth/realms/BMC/protocol/openid-connect/token.

Outputs

The delete-server-bmc action provides this output:

  • id: The ID of a deleted BMC server.

Example Usage for Delete BMC Server Action

Below is the example usage for the create server action:

- name: DeleteServer step
  uses: phoenixnap-github-actions/delete-server-bmc 
  id: deleteserver
  with:
    clientid: ${{secrets.BMC_CLIENT_ID}}
    clientsecret: ${{secrets.BMC_CLIENT_SECRET}}
    serverid: ${{ steps.createserver.outputs.id }}

Note: You should also check out our guide on GitHub Repos for Automating Bare Metal Cloud Server Management.

Conclusion

This guide provided the information and examples for available Bare Metal Cloud GitHub actions. By incorporating BMC action into your workflows, you can automate server creation and deletion and obtain server information.

If you need assistance with your Bare Metal Cloud server, contact our Support Team.

Was this article helpful?
YesNo
Goran Jevtic
Goran combines his passions for research, writing and technology as a technical writer at phoenixNAP. Working with multiple departments and on a variety of projects, he has developed extraordinary understanding of cloud and virtualization technology trends and best practices.
Next you should read
What is Bare Metal Cloud
May 20, 2020

The most common cause of performance degradation in virtualized environments is the technology that runs the cloud...
Read more
phoenixNAP Bare Metal Cloud Billing Models
October 30, 2020

The article will provide details for the BMC billing models so you can choose which one is right for you.
Read more
How to Deploy a Bare Metal Cloud Server
March 23, 2021

Deploying a BMC server is an easy process. The guide will show you how to deploy a Bare Metal Cloud server via the phoenixNAP BMC portal.
Read more
Bare Metal Billing Client Portal Guide
January 14, 2020

This quick guide will show you how to use the new form to order a bare metal server and how to navigate through new bare...
Read more
  • © 2021 Copyright phoenixNAP | Global IT Services. All Rights Reserved.