Skip to content

Commit

Permalink
chore(misc): fix up deployments (#801)
Browse files Browse the repository at this point in the history
Co-authored-by: Joshua Croft <[email protected]>
Co-authored-by: Joshua Croft <[email protected]>
  • Loading branch information
3 people authored Jul 19, 2024
1 parent 4ea32f1 commit 97c724d
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 225 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/deploy-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
56 changes: 8 additions & 48 deletions .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
50 changes: 0 additions & 50 deletions .github/workflows/ephemeral-delete.yaml

This file was deleted.

103 changes: 0 additions & 103 deletions .github/workflows/ephemeral-deploy.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/pr-title-linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
pull_request_target:
types:
- opened
- editedgit
- edited
- synchronize

jobs:
Expand Down
31 changes: 9 additions & 22 deletions build-img.py → scripts/build-img.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,10 @@
import argparse


PROFILES = {
'staging': {
'repository': 'gcr.io/fetch-ai-sandbox/docs-website',
},
'production': {
'repository': 'gcr.io/fetch-ai-images/docs-website',
},
}

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',
Expand All @@ -26,18 +19,9 @@
'SENDER_TOKEN'
)

def _profile(text: str) -> str:
if text not in PROFILES:
available_profiles = ', '.join(PROFILES.keys())
print(f'Invalid profile {text}. Please select one of [{available_profiles}]')
sys.exit(1)

return text


def parse_commandline() -> argparse.Namespace:
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--profile', type=_profile, default='staging', help='The profile to use')
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()
Expand All @@ -55,6 +39,11 @@ def get_version() -> str:
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():
Expand All @@ -67,13 +56,11 @@ def main():

# lookup the required information
version = get_version()
repository = PROFILES[args.profile]['repository']

image_url = f'{repository}:{version}'
image_url = f'{REPOSITORY}:{version}'

print()
print(f'Project root: {PROJECT_ROOT}')
print(f'Profile.....: {args.profile}')
print(f'Image Ref...: {image_url}')
print(f'Push........: {push}')
print()
Expand Down Expand Up @@ -109,4 +96,4 @@ def main():


if __name__ == '__main__':
main()
main()

0 comments on commit 97c724d

Please sign in to comment.