Deploy your application to a Capsule using Github Actions
In this document, you'll learn how to build and deploy your application automatically using Github Actions.
Prerequisites
It is assumed that you have a Rig Capsule up and running, see Deploy Your Application if not. You should also have a GitHub repository from which you would like to build and deploy to your capsule.
Example workflow using the actions
Rig exposes two different actions, build and deploy. The build action assumes you have a Docker image you want to deploy and makes a Rig build off of it. The deploy action can then deploy the previously (or any other) generated build to a capsule.
As you need a Docker image to build and deploy, it is common to prefix these two actions with Docker Github actions to build and publish an image.
The following GitHub workflow example showcases how you can
- Build a Docker image from a new commit
 - Push that Docker image to Docker Hub
 - Make a Rig build from that Docker image
 - Deploy that Rig build to your Rig capsule
 
In this example a username and password to Dockerhub is stored as a Github secret in the repository of the workflow. The same is done with the client secret to the Rig project
on: [push]
jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Login to Docker Hub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKER_HUB_USERNAME }}
          password: ${{ secrets.DOCKER_HUB_PASSWORD }}
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2
      - name: Build and push
        uses: docker/build-push-action@v4
        with:
          context: .
          file: ./Dockerfile
          push: true
          tags: ${{ secrets.DOCKER_HUB_USERNAME }}/DOCKER_IMAGE_NAME:latest
      - name: Build Rig
        uses: rigdev/actions/build@v2
        id: build_rig
        with:
          url: url-to-rig-cluster
          project: YOUR_PROJECT_NAME
          clientID: YOUR_ID
          clientSecret: ${{ secrets.RIG_PROJECT_CLIENT_SECRET }}
          image: ${{ secrets.DOCKER_HUB_USERNAME }}/DOCKER_IMAGE_NAME:latest
          capsule: YOUR_CAPSULE
      - name: Deploy to capsule
        uses: rigdev/actions/deploy@update
        with:
          url: url-to-rig-cluster
          project: YOUR_PROJECT_NAME
          clientID: YOUR_ID
          clientSecret: ${{ secrets.RIG_PROJECT_CLIENT_SECRET }}
          capsule: YOUR_CAPSULE
          build: ${{ steps.build_rig.outputs.build }}