Github Actions on Pull Requests
Github Actions can be created for the following workflows:
- Setup vCluster Platform: Installs the
vCluster
CLI - Create Space: Creates a Space
- Delete Space: Deletes a Space
- Setup DevSpace: Installs the
devspace
CLI
Deploying Virtual Clusters on Pull Requests​
These examples show how to create and delete Virtual Clusters for pull requests.
- Basic
- Automatic Cleanup
- Reuse
This example shows how to create and delete a virtual cluster for testing an application named my-app
on pull requests.
# .github/workflows/vclusters.yaml
name: Pull Request Checks
on:
pull_request:
branches:
- "main"
jobs:
e2e:
runs-on: ubuntu-latest
steps:
- name: Install vCluster CLI
uses: loft-sh/setup-vcluster@main
- name: Login to vCluster Platform instance
env:
LOFT_URL: ${{ secrets.LOFT_URL }}
ACCESS_KEY: ${{ secrets.ACCESS_KEY }}
run: vcluster login $LOFT_URL --access-key $ACCESS_KEY
- name: Create PR Virtual Cluster
env:
NAME: pr-${{ github.event.pull_request.number }}-${{ github.sha }}-${{ github.run_id }}
run: vcluster create $NAME --project default
- name: Deploy Application
run: kubectl apply -Rf ./kubernetes
- name: Wait for Deployment
run: kubectl rollout status deployments/my-app
- name: Run Tests
run: make e2e
- name: Delete PR Virtual Cluster
env:
NAME: pr-${{ github.event.pull_request.number }}-${{ github.sha }}-${{ github.run_id }}
run: vcluster delete $NAME --project default
Explanation:
- The Setup vCluster Platform action is used to install the vCluster CLI.
- The
vcluster login
command is used to log in to the organization's vCluster Platform instance. Environment variablesLOFT_URL
andACCESS_KEY
are populated using GitHub secrets. - The
vcluster create
command is used to create a unique virtual cluster using information about the pull request in thedefault
project. This will automatically configure the kube context for the next steps. - The next step deploys the application using the runner provided
kubectl
and manifests located under./kubernetes
. - Before running tests, we use
kubectl
to wait for themy-app
deployment to become ready. - Now we run the end-to-end tests. In this example we're using
make
to run tests, but the command should be customized for your testing framework. - Finally, the
vcluster delete
command is used to delete the virtual cluster.
This example shows how to create and reuse a virtual cluster for testing an application named my-app
on pull requests.
# .github/workflows/vclusters.yaml
name: Pull Request Checks
on:
pull_request:
branches:
- "main"
jobs:
e2e:
runs-on: ubuntu-latest
steps:
- name: Install vCluster CLI
uses: loft-sh/setup-vcluster@main
- name: Login to vCluster Platform instance
env:
LOFT_URL: ${{ secrets.LOFT_URL }}
ACCESS_KEY: ${{ secrets.ACCESS_KEY }}
run: vcluster login $LOFT_URL --access-key $ACCESS_KEY
- name: Create PR Virtual Cluster
env:
NAME: pr-${{ github.event.pull_request.number }}-${{ github.sha }}-${{ github.run_id }}
run: vcluster create $NAME --project default --upgrade
- name: Deploy Application
run: kubectl apply -Rf ./kubernetes
- name: Wait for Deployment
run: kubectl rollout status deployments/my-app
- name: Run Tests
run: make e2e
Explanation:
- The Setup vCluster Platform action is used to install the vCluster CLI.
- The
vcluster login
command is used to log in to the organization's vCluster Platform instance. Environment variablesLOFT_URL
andACCESS_KEY
are populated using GitHub secrets. - The
vcluster create
command is used to create a unique virtual cluster using information about the pull request in thedefault
project. This will automatically configure the kube context for the next steps. The--upgrade
flag has been added to reuse the existing virtual cluster and upgrade it to the latest version. Additional flags may be used to control the desired virtual cluster version. - The next step deploys the application using the runner provided
kubectl
and manifests located under./kubernetes
. - Before running tests, we use
kubectl
to wait for themy-app
deployment to become ready. - Now we run the end-to-end tests. In this example we're using
make
to run tests, but the command should be customized for your testing framework.
This example shows how to automatically delete a Virtual Cluster after testing an application named my-app for pull requests.
# .github/workflows/vclusters.yaml
name: Pull Request Checks
on:
pull_request:
branches:
- 'main'
jobs:
e2e:
runs-on: ubuntu-latest
steps:
- name: Install vCluster CLI
uses: loft-sh/setup-loft@main
with:
url: ${{ secrets.LOFT_URL }}
access-key: ${{ secrets.LOFT_ACCESS_KEY }}
- name: Create Virtual Cluster for PR
uses: loft-sh/create-vcluster@main
with:
name: pr-${{ github.event.pull_request.number }}-${{ github.sha }}-${{ github.run_id }}
auto-cleanup: true
- name: Deploy Application
run: kubectl apply -Rf ./kubernetes
- name: Wait for Deployment
run: kubectl rollout status deployments/my-app
- name: Run Tests
run: make e2e
Explanation:
- The Setup Loft action is used to install the vCluster CLI and login using the provided
url
andaccess-key
. - The Create Virtual Cluster action is used to create a unique virtual cluster using information about the pull request. This will automatically configure the kube context for the following steps. Additionally, we have enabled the
auto-cleanup
option, which will delete the virtual cluster after the job completes. - The next step deploys the application using the runner provided
kubectl
and manifests located under./kubernetes
. - Before running tests, we use
kubectl
to wait for themy-app
deployment to become ready. - Finally we run the end-to-end tests. In this example we're using
make
to run tests, but the command should be customized for your testing framework. There's no need to delete the virtual cluster since theauto-cleanup
option was used when creating the virtual cluster.
Deploying Spaces on Pull Requests​
These examples show how to create and delete Spaces for pull requests.
- Basic
- Automatic Cleanup
- Reuse
This example shows how to create and delete a space to test an application named my-app
for pull requests.
# .github/workflows/prs.yaml
name: Pull Request Checks
on:
pull_request:
branches:
- 'main'
jobs:
e2e:
runs-on: ubuntu-latest
steps:
- name: Install vCluster CLI
uses: loft-sh/setup-loft@main
with:
url: ${{ secrets.LOFT_URL }}
access-key: ${{ secrets.LOFT_ACCESS_KEY }}
- name: Create Space for PR
uses: loft-sh/create-space@main
with:
name: pr-${{ github.event.pull_request.number }}-${{ github.sha }}-${{ github.run_id }}
- name: Deploy Application
run: kubectl apply -Rf ./kubernetes
- name: Wait for Deployment
run: kubectl rollout status -n pr-${{ github.event.pull_request.number }}-${{ github.sha }}-${{ github.run_id }} deployments/my-app
- name: Run Tests
run: make e2e
- name: Delete PR Space
uses: loft-sh/delete-space@main
with:
name: pr-${{ github.event.pull_request.number }}-${{ github.sha }}-${{ github.run_id }}
Explanation:
- The Setup Loft action is used to install the vCluster CLI and login using the provided
url
andaccess-key
. - The Create Space action is used to create a unique space using information about the pull request. This will automatically configure the kube context for the following steps.
- The next step deploys the application using the runner provided
kubectl
and manifests located under./kubernetes
. - Before running tests, we use
kubectl
to wait for themy-app
deployment to become ready. - Now we run the end-to-end tests. In this example we're using
make
to run tests, but the command should be customized for your testing framework. - Finally, the Delete Space GitHub Action is used to delete the pull request's space.
This example shows how to automatically delete a Space after testing an application named my-app
for pull requests.
# .github/workflows/prs.yaml
name: Pull Request Checks
on:
pull_request:
branches:
- 'main'
jobs:
e2e:
runs-on: ubuntu-latest
steps:
- name: Install vCluster CLI
uses: loft-sh/setup-loft@main
with:
url: ${{ secrets.LOFT_URL }}
access-key: ${{ secrets.LOFT_ACCESS_KEY }}
- name: Create Space for PR
uses: loft-sh/create-space@main
with:
name: pr-${{ github.event.pull_request.number }}-${{ github.sha }}-${{ github.run_id }}
auto-cleanup: true
- name: Deploy Application
run: kubectl apply -Rf ./kubernetes
- name: Wait for Deployment
run: kubectl rollout status -n pr-${{ github.event.pull_request.number }}-${{ github.sha }}-${{ github.run_id }} deployments/my-app
- name: Run Tests
run: make e2e
Explanation:
- The Setup Loft action is used to install the vCluster CLI and login using the provided
url
andaccess-key
. - The Create Space action is used to create a unique space using information about the pull request. This will automatically configure the kube context for the following steps. Additionally, we have enabled the
auto-cleanup
option, which will delete the space after the job completes. - The next step deploys the application using the runner provided
kubectl
and manifests located under./kubernetes
. - Before running tests, we use
kubectl
to wait for themy-app
deployment to become ready. - Finally we run the end-to-end tests. In this example we're using
make
to run tests, but the command should be customized for your testing framework. There's no need to delete the space since theauto-cleanup
option was used when creating the space.
This example shows how to create and reuse a space to test an application named my-app
for pull requests.
# .github/workflows/prs.yaml
name: Pull Request Checks
on:
pull_request:
branches:
- 'main'
jobs:
e2e:
runs-on: ubuntu-latest
steps:
- name: Install vCluster CLI
uses: loft-sh/setup-loft@main
with:
url: ${{ secrets.LOFT_URL }}
access-key: ${{ secrets.LOFT_ACCESS_KEY }}
- name: Create Space for PR
uses: loft-sh/create-space@main
with:
name: pr-${{ github.event.pull_request.number }}-${{ github.sha }}-${{ github.run_id }}
use: true
- name: Deploy Application
run: kubectl apply -Rf ./kubernetes
- name: Wait for Deployment
run: kubectl rollout status -n pr-${{ github.event.pull_request.number }}-${{ github.sha }}-${{ github.run_id }} deployments/my-app
- name: Run Tests
run: make e2e
Explanation:
- The Setup Loft action is used to install the vCluster CLI and login using the provided
url
andaccess-key
. - The Create Space action is used to create a unique space using information about the pull request. This will automatically configure the kube context for the following steps. Notice that we're using the
use
attribute to specify that we wish to reuse the space if it still exists from a previous run. - The next step deploys the application using the runner provided
kubectl
and manifests located under./kubernetes
. - Before running tests, we use
kubectl
to wait for themy-app
deployment to become ready. - Now we run the end-to-end tests. In this example we're using
make
to run tests, but the command should be customized for your testing framework.
DevSpace for Running Tests on Pull Requests​
This example shows how use the Setup Devspace GitHub Action to install the DevSpace CLI and DevSpace commands to run tests.
# .github/workflows/vclusters.yaml
name: Pull Request Checks
on:
pull_request:
branches:
- "main"
jobs:
e2e:
runs-on: ubuntu-latest
steps:
- name: Install DevSpace CLI
uses: loft-sh/setup-devspace@main
- name: Install vCluster CLI
uses: loft-sh/setup-vcluster@main
- name: Login to vCluster Platform instance
env:
LOFT_URL: ${{ secrets.LOFT_URL }}
ACCESS_KEY: ${{ secrets.ACCESS_KEY }}
run: vcluster login $LOFT_URL --access-key $ACCESS_KEY
- name: Create PR Virtual Cluster
env:
NAME: pr-${{ github.event.pull_request.number }}-${{ github.sha }}-${{ github.run_id }}
run: vcluster create $NAME --project default
- name: Run Tests
run: devspace run e2e
Explanation:
- The Setup DevSpace action installs the DevSpace CLI.
- The Setup vCluster Platform action is used to install the vCluster CLI.
- The
vcluster login
command is used to log in to the organization's vCluster Platform instance. Environment variablesLOFT_URL
andACCESS_KEY
are populated using GitHub secrets. - The
vcluster create
command is used to create a unique virtual cluster using information about the pull request in thedefault
project. This will automatically configure the kube context for the next steps. - Finally we use
devspace run e2e
to perform the needed steps to deploy and testmy-app
.