From 8bf51bc4e61b2c4673a25322bb1007271624c9a4 Mon Sep 17 00:00:00 2001 From: Joshua Croft <32483134+devjsc@users.noreply.github.com> Date: Fri, 19 Jul 2024 10:46:38 +0100 Subject: [PATCH] chore(docs): new deploy (#802) Co-authored-by: Joshua Croft --- .github/workflows/deploy-production.yml | 3 +- .github/workflows/deploy-staging.yml | 56 ++----------- .github/workflows/ephemeral-delete.yaml | 50 ------------ .github/workflows/ephemeral-deploy.yaml | 103 ------------------------ .github/workflows/pr-title-linting.yml | 2 +- README.md | 30 +++++++ scripts/build-img.py | 99 +++++++++++++++++++++++ 7 files changed, 140 insertions(+), 203 deletions(-) delete mode 100644 .github/workflows/ephemeral-delete.yaml delete mode 100644 .github/workflows/ephemeral-deploy.yaml create mode 100755 scripts/build-img.py diff --git a/.github/workflows/deploy-production.yml b/.github/workflows/deploy-production.yml index 11afdab88..de292052a 100644 --- a/.github/workflows/deploy-production.yml +++ b/.github/workflows/deploy-production.yml @@ -35,8 +35,9 @@ jobs: - name: Build and Push Images run: | - ./k8s/build-img.py -p production + ./scripts/build-img.py env: + IMAGE_REPOSITORY: ${{ secrets.PRODUCTION_IMAGE_REPOSITORY }} BACKEND_URL: ${{ secrets.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 }} diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index f401d162c..a994a4c06 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -35,8 +35,9 @@ jobs: - name: Build and Push Images run: | - ./k8s/build-img.py -p staging + ./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 }} @@ -45,51 +46,10 @@ jobs: NEWSLETTER_BASE_URL: ${{ secrets.NEWSLETTER_BASE_URL }} SENDER_TOKEN: ${{ secrets.SENDER_TOKEN }} - deploy: - name: Deployment - runs-on: ubuntu-latest - - 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: Deploy to Staging - env: - IMAGE_TAG: ${{ steps.lookup.outputs.version }} - HELM_NAME: staging - NAMESPACE: docs-staging - GKE_PROJECT: fetch-ai-sandbox - GKE_CLUSTER: london-b - GKE_ZONE: europe-west2-b - + - name: Repository Dispatch 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 \ - ./k8s/docs/ \ - --set-string website.image.tag=$IMAGE_TAG \ - -n $NAMESPACE + curl -f -H "Accept: application/vnd.github.everest-preview+json" \ + -H "Authorization: token ${{ secrets.ORG_DISPATCH_RENDER_TOKEN }}" \ + --request POST \ + --data '{"event_type": "docs-staging-build", "client_payload": {"image": "'"${{ secrets.STAGING_IMAGE_REPOSITORY }}"'" , "image_path": "values", "key_path": ".website.image.tag", "commit_message_service": "Docs Staging", "tag": "'"${{ steps.lookup.outputs.version }}"'"}}' \ + https://api.github.com/repos/fetchai/infra-sandbox-london-b-deployment/dispatches diff --git a/.github/workflows/ephemeral-delete.yaml b/.github/workflows/ephemeral-delete.yaml deleted file mode 100644 index 43ace2c1d..000000000 --- a/.github/workflows/ephemeral-delete.yaml +++ /dev/null @@ -1,50 +0,0 @@ -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 diff --git a/.github/workflows/ephemeral-deploy.yaml b/.github/workflows/ephemeral-deploy.yaml deleted file mode 100644 index 032be3537..000000000 --- a/.github/workflows/ephemeral-deploy.yaml +++ /dev/null @@ -1,103 +0,0 @@ -name: Ephemeral (Testing) Deployment - -on: - pull_request: - types: - - opened - - reopened - - synchronize - -jobs: - build: - name: Build Images - 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 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: ./k8s/build-img.py -p staging - env: - 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 }} - NEWSLETTER_BASE_URL: ${{ secrets.NEWSLETTER_BASE_URL }} - SENDER_TOKEN: ${{ secrets.SENDER_TOKEN }} - - deploy: - name: Ephermeral Deployment - runs-on: ubuntu-latest - 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: 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 - 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 \ - ./k8s/docs/ \ - --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=null \ diff --git a/.github/workflows/pr-title-linting.yml b/.github/workflows/pr-title-linting.yml index a353a45ef..90acdd02f 100644 --- a/.github/workflows/pr-title-linting.yml +++ b/.github/workflows/pr-title-linting.yml @@ -4,7 +4,7 @@ on: pull_request_target: types: - opened - - editedgit + - edited - synchronize jobs: diff --git a/README.md b/README.md index f261926ab..9b68e4ba3 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,19 @@ # Fetch.ai Documentation Repo +<<<<<<< HEAD + +## Updating docs + +# Changes can be made on github or locally. To run docs locally you must have npm installed. + Welcome to the code repository for websites and contents of fetch.ai/docs. ## Updating docs We welcome PRs from all members of our community, and details and formats of this can be seen in our [Code of Conduct](CODE_OF_CONDUCT.md). +> > > > > > > origin/master + ## Developing ### Install dependencies @@ -24,6 +32,26 @@ The site is then visible at: http://127.0.0.1:3000/docs +<<<<<<< HEAD + +### Production Build Workflow + +Build the codebase + +```bash +pnpm build +``` + +Run the production server + +```bash +pnpm start +``` + +The site is then visible at: + +# http://127.0.0.1:3000/docs + ## Contributing We welcome contributions from the community! Please see our Contributing Guide for information on how to get involved. Whether you're fixing bugs, adding new features, or improving documentation, your help is appreciated. @@ -35,3 +63,5 @@ If you need help or have any questions, please post a discussion or join our com ## License The uAgents library is licensed under the APACHE License. For more details, see the [LICENSE](LICENSE) file. + +> > > > > > > origin/master diff --git a/scripts/build-img.py b/scripts/build-img.py new file mode 100755 index 000000000..8f2bf7de2 --- /dev/null +++ b/scripts/build-img.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python3 +import os +import sys +import subprocess +import argparse + + +PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + +REPOSITORY = os.environ.get('IMAGE_REPOSITORY') + +BUILD_ENV_VARS = ( + 'BACKEND_URL', + 'NEXT_PUBLIC_GOOGLE_ANALYTICS_TRACKING_ID', + 'NEXT_PUBLIC_ALGOLIA_APP_ID', + 'NEXT_PUBLIC_ALGOLIA_API_KEY', + 'NEXT_PUBLIC_ALGOLIA_INDEX', + 'NEWSLETTER_BASE_URL', + 'SENDER_TOKEN' +) + + +def parse_commandline() -> argparse.Namespace: + parser = argparse.ArgumentParser() + parser.add_argument('-n', '--no-push', dest='push', action='store_false', help='Disable pusing of the image') + parser.add_argument('-f', '--force-build', action='store_true', help=argparse.SUPPRESS) + return parser.parse_args() + + +def detect_local_modifications() -> bool: + exit_code = subprocess.call(['git', 'diff-index', '--quiet', 'HEAD']) + return exit_code != 0 + + +def get_version() -> str: + return subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode().strip() + + +def main(): + args = parse_commandline() + + # validate the repository environment variable + if REPOSITORY is None: + print('Missing IMAGE_REPOSITORY environment variable') + sys.exit(1) + + # argument validation / augmentation + push = args.push + if detect_local_modifications(): + if args.force_build: + push = False + print('Disabling push of images due to local modifications') + else: + print('Detected local modifications. Please commit and try again') + sys.exit(1) + + # lookup the required information + version = get_version() + + image_url = f'{REPOSITORY}:{version}' + + print() + print(f'Project root: {PROJECT_ROOT}') + print(f'Image Ref...: {image_url}') + print(f'Push........: {push}') + print() + + # Step 0. Collect up the build environment variables + build_args = [] + for env_name in BUILD_ENV_VARS: + if env_name not in os.environ: + print('Missing build variable', env_name) + sys.exit(1) + + build_args.append(f'--build-arg={env_name}={os.environ[env_name]}') + + # Step 1. Build the image + cmd = [ + 'docker', + 'build', + ] + build_args + [ + '--platform', 'linux/amd64', + '-t', image_url, + PROJECT_ROOT, + ] + subprocess.check_call(cmd) + + # Step 2. Push the image + if push: + subprocess.check_call([ + 'docker', + 'push', + image_url, + ]) + + + +if __name__ == '__main__': + main()