Skip to content

on push to new-staging #17

on push to new-staging

on push to new-staging #17

name: Deploy Rays Dashboard Staging
on:
workflow_dispatch:
push:
branches:
- new-staging
jobs:
changes:
name: Check for rays dashboard changes
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
build-rays-dashboard: ${{ steps.filter.outputs.build-rays-dashboard }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
build-rays-dashboard:
- 'apps/rays-dashboard/**'
- 'packages/app-db/**'
- 'packages/app-types/**'
- 'packages/app-ui/**'
- 'packages/app-icons/**'
- '.github/workflows/build-push-deploy-rays-dashboard-staging.yaml'
build:
name: Build and deploy Rays Dashboard
runs-on: ubuntu-latest
permissions:
id-token: write
environment: staging
needs: changes
if: ${{ needs.changes.outputs.build-rays-dashboard == 'true' }}
env:
AWS_REGION: eu-central-1
ENVIRONMENT_TAG: staging
SERVICE_NAME: summer-fi-rays-service-staging
CLUSTER_NAME: summer-fi-rays-staging
CONFIG_URL: ${{ secrets.CONFIG_URL }}
CONFIG_URL_RAYS: ${{ secrets.CONFIG_URL_RAYS }}
FUNCTIONS_API_URL: ${{ secrets.FUNCTIONS_API_URL }}
BORROW_DB_READ_CONNECTION_STRING: ${{ secrets.NEW_BORROW_DB_READ_CONNECTION_STRING_STAGING }}
CONTENTFUL_ACCESS_TOKEN: ${{ secrets.CONTENTFUL_ACCESS_TOKEN }}
CONTENTFUL_PREVIEW_ACCESS_TOKEN: ${{ secrets.CONTENTFUL_PREVIEW_ACCESS_TOKEN }}
CONTENTFUL_SPACE_ID: ${{ secrets.CONTENTFUL_SPACE_ID }}
MIXPANEL_KEY: ${{ secrets.MIXPANEL_KEY }}
NEXT_PUBLIC_MIXPANEL_KEY: ${{ secrets.NEXT_PUBLIC_MIXPANEL_KEY }}
SUBGRAPH_BASE: ${{ secrets.SUBGRAPH_BASE }}
SDK_API_URL: ${{ secrets.SDK_API_URL }}
NEXT_TELEMETRY_DISABLED: ${{ secrets.NEXT_TELEMETRY_DISABLED }}
steps:
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Set up turbo cache
uses: rharkor/[email protected]
- uses: pnpm/[email protected]
with:
version: 8.14.1
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 20
cache: 'pnpm'
- name: Setup Rays Dashboard App Next.js Cache
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/apps/rays-dashboard/.next/cache
key:
${{ runner.os }}-rays-dashboard-app-${{ hashFiles('pnpm-lock.yaml') }}-${{
hashFiles('apps/rays-dashboard/**/*.ts', 'apps/rays-dashboard/**/*.tsx') }}
restore-keys: ${{ runner.os }}-rays-dashboard-app-${{ hashFiles('pnpm-lock.yaml') }}-
- name: Extract commit hash
id: vars
shell: bash
run: |
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
- name: Install dependencies
run: pnpm install
- name: Prebuild
run: pnpm prebuild
- name: Build
run: pnpm build-rays-frontend
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.BUILD_DEPLOY_OIDC_ROLE_STAGING }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build docker image, copy build output and push to ECR
id: build-image
env:
LATEST_TAG: latest
ECR_REPO_NAME: summer-fi-rays-staging
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
SHA_TAG: ${{ steps.vars.outputs.sha_short }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -f apps/rays-dashboard/docker/Dockerfile \
--cache-from=$ECR_REGISTRY/$ECR_REPO_NAME:$LATEST_TAG \
-t $ECR_REGISTRY/$ECR_REPO_NAME:$SHA_TAG \
-t $ECR_REGISTRY/$ECR_REPO_NAME:$LATEST_TAG \
-t $ECR_REGISTRY/$ECR_REPO_NAME:$ENVIRONMENT_TAG \
./apps/rays-dashboard
docker push $ECR_REGISTRY/$ECR_REPO_NAME --all-tags
- name: Update ECS service with latest Docker image
id: service-update
run: |
aws ecs update-service --cluster $CLUSTER_NAME --service ${{ env.SERVICE_NAME }} --force-new-deployment --region $AWS_REGION
#- name: Wait for all services to become stable
# uses: oryanmoshe/[email protected]
# with:
# ecs-cluster: ${{ env.CLUSTER_NAME }}
# ecs-services: '["${{ env.SERVICE_NAME }}"]'
- name: Invalidate CloudFront
env:
CF_DIST_ID: ${{ secrets.CF_DIST_ID }}
run: |
AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ secrets.NEW_CF_DIST_ID_STAGING }} --paths "/*"
- name: Trigger e2e tests in e2e-tests repository
env:
E2E_TESTS_PAT: ${{ secrets.E2E_TESTS_PAT }}
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ env.E2E_TESTS_PAT }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OasisDEX/e2e-tests/actions/workflows/ci_e2e_tests.yml/dispatches \
-d "{\"ref\":\"main\", \"inputs\":{\"run_id\":\"${{ github.run_id }}\", \"repository\":\"${{ github.repository }}\"}}"
echo 'See test results in https://github.com/OasisDEX/e2e-tests/actions/workflows/ci_e2e_tests.yml --> Job with RUN_ID ${{ github.run_id }} in the logs.'