Instance Update Action

Instance Update Action

The Instance Update (opens in a new tab) GitHub action provides a seamless solution for updating Cluster instances directly from your workflow environment. This action simplifies the process of managing your infrastructure by allowing you to create pipelines that automatically build and deploy new Docker images whenever a commit is made to your branch. With the Instance Update (opens in a new tab) GitHub Action, you can ensure that your instances are always up-to-date with the latest changes in your codebase.

Usage

In the examples below, we are going to see how we can create a Github workflow that will:

  1. Get the version of the project from package.json.
  2. Create a new docker image, which uses the version of the project for the image tag.
  3. Push the newly created image to the docker hub.
  4. Update the spheron instance to use the newly created image.
name: Update Spheron Cluster Instance
 
on:
  push:
    branches:
      - main
 
jobs:
  update-spheron-instance:
    runs-on: ubuntu-latest
 
    steps:
      - name: Checkout repository
        id: checkout-repository
        uses: actions/checkout@v3
 
      - name: Extract version
        id: extract-version
        run: echo "version=$(cat package.json | jq -r '.version')" >> "$GITHUB_OUTPUT"
 
      - name: Login to Docker Hub
        id: docker-hub-login
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
 
      - name: Set up Docker Buildx
        id: docker-buildx-setup
        uses: docker/setup-buildx-action@v2
 
      - name: Build and push
        id: docker-build-n-push
        uses: docker/build-push-action@v4
        with:
          context: .
          file: ./Dockerfile
          push: true
          tags: image:${{ steps.extract-version.outputs.version }}
 
      - name: Update Spheron Instance
        id: update-spheron-instance
        uses: spheronFdn/instance-update-action@v1.0.0
        with:
          spheron-token: ${{ secrets.SPHERON_TOKEN }}
          instance-id: ${{ secrets.SPHERON_INSTANCE_ID }}
          tag: ${{ steps.extract-version.outputs.version }}
          env: '[ "key1=value1", "key2=value2" ]'
          secret-env: '[ "skey1=svalue1", "skey2=svalue2" ]'

In the examples, we are also using 4 other actions:

Instance Update Action

Inputs

  • spheron-token: To create the token, follow the instructions in the DOCS (opens in a new tab). When you are creating the tokens, please choose Compute type in the dashboard.

  • instance-id: The ID of the instance that should be updated.

    NOTE: You will need to create the instance in the dashboard first and then pass the id from the instance dashboard.

  • tag( optional ): The tag that will be used to update the instance. If the tag is not provided, the latest will be used.

    NOTE: When making changes to the code, the new tag needs to be different than the one that is currently running on the Cluster Instance. entered.

  • env( optional ): The environment variables that should be used. The environment variables need to be provided each time the instance is updated. You will be able to see the value of the environment variables in the settings page of your instance. The value of env is a string that represents a json array where each element in the array is the string in format key=value, for example: env: '[ "key1=value1", "key2=value2" ]'

  • secret-env( optional ): The secret environment variables that should be used. The secret environment variables need to be provided each time the instance is updated. You will not be able to see the value of the environment variables in the settings page of your instance. The value of secret env is a string that represents a json array where each element in the array is a string in format key=value, for example secret-env: '[ "key1=secret-value1", "key2=secret-value2" ]'

Outputs

  • cluster-id: The Cluster ID of the updated instance.
  • instance-id: The ID of the updated instance.
  • deployment-id: The Deployment ID of the updated instance.
  • organization-id: The Organization ID of the updated instance.
Github ActionsSpheron Terraform