Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GitHub Actions to use setup-vcluster #302

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ jobs:
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
with:
url: ${{ secrets.VCLUSTER_PLATFORM_URL }}
# Specify your vCluster Platform access key here
access-key: ${{ secrets.VCLUSTER_PLATFORM_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
run: vcluster platform create vcluster $NAME --project default
- name: Run Tests
run: devspace run e2e
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install vCluster CLI
uses: loft-sh/setup-loft@main
uses: loft-sh/setup-vcluster@main
with:
url: ${{ secrets.LOFT_URL }}
access-key: ${{ secrets.LOFT_ACCESS_KEY }}
url: ${{ secrets.VCLUSTER_PLATFORM_URL }}
# Specify your vCluster Platform access key here
access-key: ${{ secrets.VCLUSTER_PLATFORM_ACCESS_KEY }}
- name: Create Space for PR
uses: loft-sh/create-space@main
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install vCluster CLI
uses: loft-sh/setup-loft@main
uses: loft-sh/setup-vcluster@main
with:
url: ${{ secrets.LOFT_URL }}
access-key: ${{ secrets.LOFT_ACCESS_KEY }}
url: ${{ secrets.VCLUSTER_PLATFORM_URL }}
# Specify your vCluster Platform access key here
access-key: ${{ secrets.VCLUSTER_PLATFORM_ACCESS_KEY }}
- name: Create Space for PR
uses: loft-sh/create-space@main
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install vCluster CLI
uses: loft-sh/setup-loft@main
uses: loft-sh/setup-vcluster@main
with:
url: ${{ secrets.LOFT_URL }}
access-key: ${{ secrets.LOFT_ACCESS_KEY }}
url: ${{ secrets.VCLUSTER_PLATFORM_URL }}
# Specify your vCluster Platform access key here
access-key: ${{ secrets.VCLUSTER_PLATFORM_ACCESS_KEY }}
- name: Create Space for PR
uses: loft-sh/create-space@main
with:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,37 @@ on:
pull_request:
branches:
- "main"

env:
VCLUSTER_NAME: pr-${{ github.event.pull_request.number }}-${{ github.sha }}-${{ github.run_id }}

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
uses: loft-sh/setup-vcluster@main
with:
url: ${{ secrets.VCLUSTER_PLATFORM_URL }}
# Specify your vCluster Platform access key here
access-key: ${{ secrets.VCLUSTER_PLATFORM_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
run: vcluster platform create vcluster $VCLUSTER_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
run: vcluster platform delete vcluster $VCLUSTER_NAME --project default
```

**Explanation:**

1. The [Setup vCluster Platform](https://github.com/loft-sh/setup-vcluster) action is used to install the vCluster CLI.
2. The `vcluster login` command is used to log in to the organization's vCluster Platform instance. Environment variables `LOFT_URL` and `ACCESS_KEY` are populated using [GitHub secrets](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions).
3. The `vcluster create` command is used to create a unique virtual cluster using information about the pull request in the `default` project. This will automatically configure the kube context for the next steps.
4. The next step deploys the application using the runner provided `kubectl` and manifests located under `./kubernetes`.
5. Before running tests, we use `kubectl` to wait for the `my-app` deployment to become ready.
6. 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.
7. Finally, the `vcluster delete` command is used to delete the virtual cluster.
1. The [Setup vCluster Platform](https://github.com/loft-sh/setup-vcluster) action is used to install the vCluster CLI and log in to the organization's vCluster Platform instance. Environment variables `VCLUSTER_PLATFORM_URL` and `VCLUSTER_PLATFORM_ACCESS_KEY` are populated using [GitHub secrets](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions).
2. The `vcluster platform create vcluster` command is used to create a unique virtual cluster using information about the pull request in the `default` project. This will automatically configure the kube context for the next steps.
3. The next step deploys the application using the runner provided `kubectl` and manifests located under `./kubernetes`.
4. Before running tests, we use `kubectl` to wait for the `my-app` deployment to become ready.
5. 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.
6. Finally, the `vcluster platform delete vcluster` command is used to delete the virtual cluster.
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ 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: Setup vCluster Platform
uses: loft-sh/setup-vcluster@main
with:
url: ${{ secrets.VCLUSTER_PLATFORM_URL }}
# Specify your vCluster Platform access key here
access-key: ${{ secrets.VCLUSTER_PLATFORM_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
run: vcluster platform create vcluster $NAME --project default --upgrade
- name: Deploy Application
run: kubectl apply -Rf ./kubernetes
- name: Wait for Deployment
Expand All @@ -32,9 +32,8 @@ jobs:

**Explanation:**

1. The [Setup vCluster Platform](https://github.com/loft-sh/setup-vcluster) action is used to install the vCluster CLI.
2. The `vcluster login` command is used to log in to the organization's vCluster Platform instance. Environment variables `LOFT_URL` and `ACCESS_KEY` are populated using [GitHub secrets](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions).
3. The `vcluster create` command is used to create a unique virtual cluster using information about the pull request in the `default` 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.
4. The next step deploys the application using the runner provided `kubectl` and manifests located under `./kubernetes`.
5. Before running tests, we use `kubectl` to wait for the `my-app` deployment to become ready.
6. 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.
1. The [Setup vCluster Platform](https://github.com/loft-sh/setup-vcluster) action is used to install the vCluster CLI and to log in to the organization's vCluster Platform instance. Environment variables `VCLUSTER_PLATFORM_URL` and `VCLUSTER_PLATFORM_ACCESS_KEY` are populated using [GitHub secrets](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions).
2. The `vcluster platform create vcluster` command is used to create a unique virtual cluster using information about the pull request in the `default` 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.
3. The next step deploys the application using the runner provided `kubectl` and manifests located under `./kubernetes`.
4. Before running tests, we use `kubectl` to wait for the `my-app` deployment to become ready.
5. 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.
18 changes: 8 additions & 10 deletions platform/integrations/github-actions/preview-environments.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,11 @@ jobs:
uses: actions/checkout@v3

- name: Install vCluster CLI
uses: loft-sh/setup-loft@v2
uses: loft-sh/setup-vcluster@main
with:
version: v3.0.0
url: https://url-to-your-loft-instance.com
url: ${{ secrets.VCLUSTER_PLATFORM_URL }}
# Specify your vCluster Platform access key here
access-key: ${{ secrets.LOFT_PREVIEW_ACCESS_KEY }}
access-key: ${{ secrets.VCLUSTER_PLATFORM_ACCESS_KEY }}
# Optional if your vCluster Platform domain certificate is insecure
#insecure: true

Expand All @@ -89,7 +88,7 @@ jobs:
INGRESS_HOST=loft-preview-${{ github.event.pull_request.number }}.my-preview-environments.com

# Make sure to recreate if there is an already existing environment
vcluster pro create loft-preview-${{ github.event.pull_request.number }} --project preview --recreate
vcluster plaltform create vcluster loft-preview-${{ github.event.pull_request.number }} --project preview --recreate

# Deploy the application here with an ingress
helm repo add argo https://argoproj.github.io/argo-helm
Expand Down Expand Up @@ -129,17 +128,16 @@ jobs:
uses: actions/checkout@v3

- name: Install vCluster CLI
uses: loft-sh/setup-loft@v2
uses: loft-sh/setup-vcluster@main
with:
version: v3.0.0
url: https://url-to-your-loft-instance.com
url: ${{ secrets.VCLUSTER_PLATFORM_URL }}
# Specify your vCluster Platform access key here
access-key: ${{ secrets.LOFT_PREVIEW_ACCESS_KEY }}
access-key: ${{ secrets.VCLUSTER_PLATFORM_ACCESS_KEY }}
#insecure: true

- name: Destroy Preview Environment
run: |
loft delete vcluster loft-preview-${{ github.event.pull_request.number }} --project preview
vcluster platform delete vcluster loft-preview-${{ github.event.pull_request.number }} --project preview
```

## Conclusion
Expand Down
5 changes: 0 additions & 5 deletions platform/integrations/github-actions/pull-requests.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ sidebar_position: 1
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem'

import PartialIntegrationsVclusterPullRequestAutomatic from '../../_partials/integrations/github-actions-vclusters-pull-request-automatic.mdx'
import PartialIntegrationsVclusterPullRequestManual from '../../_partials/integrations/github-actions-vclusters-pull-request-manual.mdx'
import PartialIntegrationsVclusterPullRequestUse from '../../_partials/integrations/github-actions-vclusters-pull-request-use.mdx'

Expand All @@ -31,7 +30,6 @@ These examples show how to create and delete Virtual Clusters for pull requests.
defaultValue="manual"
values={[
{label: 'Basic', value: 'manual',},
{label: 'Automatic Cleanup', value: 'automatic',},
{label: 'Reuse', value: 'use',},
]}>
<TabItem value="manual">
Expand All @@ -40,9 +38,6 @@ These examples show how to create and delete Virtual Clusters for pull requests.
<TabItem value="use">
<PartialIntegrationsVclusterPullRequestUse/>
</TabItem>
<TabItem value="automatic">
<PartialIntegrationsVclusterPullRequestAutomatic/>
</TabItem>
</Tabs>

## Deploying Spaces on Pull Requests
Expand Down
Loading