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

fix: added ephemeral deployment #813

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
50 changes: 50 additions & 0 deletions .github/workflows/ephemeral-delete.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# name: Clean Ephemeral Deployment

# on:
# pull_request:
# types:
# - closed

# jobs:
# clean-deployment:
# runs-on: ubuntu-latest

# steps:
# - name: Checkout
# uses: actions/checkout@v3
# with:
# fetch-depth: 0

# - name: Setup Gcloud Auth
# uses: google-github-actions/auth@v1
# with:
# credentials_json: "${{ secrets.ORG_SANDBOX_DEPLOYMENT_KEY }}"

# - name: Setup Cloud SDK
# uses: google-github-actions/setup-gcloud@v1

# - name: Set Image Tag
# id: lookup
# run: echo "version=$(git describe --always --dirty=-wip)" >> $GITHUB_OUTPUT

# - name: Turnstyle
# uses: softprops/turnstyle@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# - name: Uninstall Deployment
# env:
# HELM_NAME: ephemeral-${{ github.event.pull_request.number }}
# NAMESPACE: docs-staging
# GKE_PROJECT: fetch-ai-sandbox
# GKE_CLUSTER: london-b
# GKE_ZONE: europe-west2-b
# PR_NUMBER: ${{ github.event.pull_request.number }}
# HELM_NAME_INGRESS: ephemeral-ingress-${{ github.event.pull_request.number }}

# run: |
# gcloud components install gke-gcloud-auth-plugin
# gcloud container clusters get-credentials $GKE_CLUSTER \
# --zone $GKE_ZONE \
# --project $GKE_PROJECT
# helm uninstall $HELM_NAME -n $NAMESPACE
111 changes: 111 additions & 0 deletions .github/workflows/ephemeral-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Ephemeral (Testing) Deployment

on:
pull_request:
types:
- opened
- reopened
- synchronize

jobs:
build:
name: Build Images
runs-on: self-hosted

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Gcloud Auth
uses: google-github-actions/auth@v1
with:
credentials_json: "${{ secrets.ORG_SANDBOX_DEPLOYMENT_KEY }}"

- name: Setup Cloud SDK
uses: google-github-actions/setup-gcloud@v1

- name: Set Image Tag
id: lookup
run: echo "version=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- run: |
gcloud auth list
gcloud auth configure-docker -q
echo "VERSION: ${{ steps.lookup.outputs.version }}"

- name: Build and Push Images
run: |
./scripts/build-img.py
env:
IMAGE_REPOSITORY: ${{ secrets.STAGING_IMAGE_REPOSITORY }}
BACKEND_URL: ${{ secrets.STAGING_NEXT_PUBLIC_BACKEND_URL }}
NEXT_PUBLIC_GOOGLE_ANALYTICS_TRACKING_ID: ${{ secrets.NEXT_PUBLIC_GOOGLE_ANALYTICS_TRACKING_ID }}
NEXT_PUBLIC_ALGOLIA_APP_ID: ${{ secrets.NEXT_PUBLIC_ALGOLIA_APP_ID }}
NEXT_PUBLIC_ALGOLIA_API_KEY: ${{ secrets.NEXT_PUBLIC_ALGOLIA_API_KEY }}
NEXT_PUBLIC_ALGOLIA_INDEX: ${{ secrets.NEXT_PUBLIC_ALGOLIA_INDEX }}

deploy:
name: Ephemeral Deployment
runs-on: self-hosted
needs: build

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Gcloud Auth
uses: google-github-actions/auth@v1
with:
credentials_json: "${{ secrets.ORG_SANDBOX_DEPLOYMENT_KEY }}"

- name: Setup Cloud SDK
uses: google-github-actions/setup-gcloud@v1

- name: Set Image Tag
id: lookup
run: echo "version=$(git describe --always --dirty=-wip)" >> $GITHUB_OUTPUT

- name: Turnstyle
uses: softprops/turnstyle@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Pull Helm Chart from ChartMuseum
run: |
mkdir -p ./charts
helm repo add chartmuseum http://charts.management.fetch-ai.com/
helm repo update
helm pull chartmuseum/docs --version=0.2.4 --untar --untardir ./charts

- name: Deploy to Staging
env:
IMAGE_TAG: ${{ steps.lookup.outputs.version }}
HELM_NAME: ephemeral-${{ github.event.pull_request.number }}
NAMESPACE: docs-staging
GKE_PROJECT: fetch-ai-sandbox
GKE_CLUSTER: london-b
GKE_ZONE: europe-west2-b
PR_NUMBER: ${{ github.event.pull_request.number }}
DNS: docs-ephemeral-${{ github.event.pull_request.number }}.sandbox-london-b.fetch-ai.com
ADDITIONAL_DNS: ${{ github.event.pull_request.number }}.staging.fetch-ai.com
CERT: docs-ephemeral-${{ github.event.pull_request.number }}
CERT_NAME: docs-ephemeral-cert-${{ github.event.pull_request.number }}
EPHEMERAL: true
run: |
gcloud components install gke-gcloud-auth-plugin
gcloud container clusters get-credentials $GKE_CLUSTER \
--zone $GKE_ZONE \
--project $GKE_PROJECT
helm upgrade --install --wait --timeout 300s $HELM_NAME \
./charts/gh-runner/ \
--set-string website.image.tag=$IMAGE_TAG \
--set-string prVersion=${{ github.event.pull_request.number }} \
-n $NAMESPACE \
--set-string dns.name=$DNS \
--set-string tls.cert=$CERT \
--set-string tls.certName=$CERT_NAME \
--set dns.additionalHosts[0]=$ADDITIONAL_DNS