Skip to content

Commit

Permalink
Merge branch 'main' of github.com:centrifuge/apps into pod-indexer-ch…
Browse files Browse the repository at this point in the history
…arts
  • Loading branch information
sophialittlejohn committed Feb 22, 2024
2 parents b060919 + da6762d commit 7624fb8
Show file tree
Hide file tree
Showing 443 changed files with 26,352 additions and 21,530 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
node: true,
jest: true,
},
extends: ['prettier', 'eslint:recommended'],
extends: ['eslint:recommended'],
parser: '@typescript-eslint/parser',

plugins: ['@typescript-eslint/eslint-plugin'],
Expand Down
20 changes: 5 additions & 15 deletions .github/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
# Monorepo for the Centrifuge applications.

## Setup

Make sure you have installed Yarn and NVM.

1. Use Node v14.15.1: `nvm use`
2. Install dependencies: `yarn install`
3. Install `husky`: `yarn postinstall`
4. Add `.env` files with the right environment variables to each project.

It's also recommended to run Prettier automatically in your editor, e.g. using [this VS Code plugin](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode).
# Monorepo for the Centrifuge applications

## Preparing Envs (e.g when the dev chain data is reset)

Expand All @@ -24,9 +13,10 @@ It's also recommended to run Prettier automatically in your editor, e.g. using [
Setup pure proxy to sign transactions (whitelisting & transfer tokens).

1. Run `/initProxies` to create the pure proxy, fund it, and give it sufficient permissions
2. Copy the resulting pure proxy address and add it to the env varibles: `MEMBERLIST_ADMIN_PURE_PROXY` (onboarding-api) and `REACT_APP_MEMBERLIST_ADMIN_PURE_PROXY` (centrifuge-app)
3. Enable onboarding for each new pool under /issuer/<poolId>/investors
1. Use sudo in polkadot UI to give Alice enough currency to distribute (tokens.setBalance()). For currencyId select ForeignAsset and submit the transacton once with ForeignAsset 1 and once with ForeignAsset 2
2. Run `/initProxies` to create the pure proxy, fund it, and give it sufficient permissions
3. Copy the resulting pure proxy address and add it to the env varibles: `MEMBERLIST_ADMIN_PURE_PROXY` (onboarding-api) and `REACT_APP_MEMBERLIST_ADMIN_PURE_PROXY` (centrifuge-app)
4. Enable onboarding for each new pool under /issuer/<poolId>/investors

### Asset Originator POD Access

Expand Down
43 changes: 23 additions & 20 deletions .github/actions/deploy-gfunction/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ inputs:
deploy_env:
description: env to deploy function to
required: false

checkout_path:
description: Folder with repository code
required: true

GWIP:
description: Google Workflow Identity provider
Expand All @@ -30,19 +26,25 @@ inputs:
required: false

target:
description: "Gfunction target handler"
description: 'Gfunction target handler'
required: true
default: handler

gcloud_region:
description: "Google Cloud region to use"
description: 'Google Cloud region to use'
required: false
default: europe-central2
memory:
description: 'RAM settings for function (without unit suffix)'
# https://cloud.google.com/sdk/gcloud/reference/functions/deploy#--memory
# https://github.com/google-github-actions/deploy-cloud-functions?tab=readme-ov-file#inputs
default: 256
required: false
default: europe-central2

runs:
using: composite
steps:
# This is probably redundant but in case this action
# This is probably redundant but in case this action
# needs to be used in isolation, it won't work
# unless the repo is checked out somewhere first
- name: Checkout
Expand All @@ -52,7 +54,7 @@ runs:

- name: prepare env logic
id: prepare
uses: "./apps/.github/actions/prepare-deploy"
uses: './apps/.github/actions/prepare-deploy'
with:
app_base_name: ${{ inputs.app_name }}
deploy_to: ${{ inputs.deploy_env }}
Expand All @@ -61,7 +63,7 @@ runs:
shell: bash
id: set_env
env:
vars_file: ./apps/${{ inputs.app_name }}/env-vars/${{ steps.prepare.outputs.env_name }}.env
vars_file: ./apps/${{ inputs.app_name }}/env-vars/${{ steps.prepare.outputs.env_name }}.env
run: |
if [ -f ${{ env.vars_file }} ]; then
VARS_COMMA=$(cat ${{ env.vars_file }} | paste -s -d, -)
Expand All @@ -74,7 +76,7 @@ runs:
shell: bash
id: set_secrets
env:
secrets_file: ./apps/${{ inputs.app_name }}/env-vars/${{ steps.prepare.outputs.env_name }}.secrets
secrets_file: ./apps/${{ inputs.app_name }}/env-vars/${{ steps.prepare.outputs.env_name }}.secrets
run: |
if [ -f ${{ env.secrets_file }} ]; then
FILE=${{ env.secrets_file }}
Expand All @@ -87,12 +89,12 @@ runs:
else
echo "No secrets file in ${{ env.secrets_file }}, continuing..."
fi
- name: retrieve artifacts
id: download
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # @v3.0.2
with:
name: ${{ inputs.artifact_name || inputs.app_name }}
name: ${{ inputs.artifact_name || inputs.app_name }}
# This will work only if we're matching the same string as
# the upload step, which happens outside of this action file
# by convention I use the app_name everywhere
Expand All @@ -107,32 +109,33 @@ runs:
uses: google-github-actions/auth@ef5d53e30bbcd8d0836f4288f5e50ff3e086997d # @v1
with:
workload_identity_provider: ${{ inputs.GWIP }}
service_account: ${{ inputs.GSA }}
service_account: ${{ inputs.GSA }}

- name: Deploy to google functions
id: gclouddeploy
uses: google-github-actions/deploy-cloud-functions@14509ca55199d9348161571e36c48e44f855030d #@v1
with:
name: '${{ steps.prepare.outputs.function_name }}'
runtime: 'nodejs16'
runtime: 'nodejs18'
region: '${{ inputs.gcloud_region }}'
source_dir: '${{ steps.download.outputs.download-path }}'
entry_point: '${{ inputs.target }}'
secret_environment_variables: ${{ steps.set_secrets.outputs.function_secrets }}
env_vars: ${{ steps.set_env.outputs.function_vars }}
service_account_email: ${{ inputs.service_account }}
max_instances: ${{ contains(steps.prepare.outputs.function_name, 'production') && '200' || '10' }}
https_trigger_security_level: "secure_always"
https_trigger_security_level: 'secure_always'
memory_mb: ${{ inputs.memory }}

- name: Print Gcloud functions URL
shell: sh
if: ${{ github.event_name == 'pull_request'}}
run: echo "::notice title=Function_URL::${{ steps.gclouddeploy.outputs.url }}"

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@d51b5346f85640ec2aa2fa057354d2b82c2fcbce # v1.0.1
uses: google-github-actions/setup-gcloud@d51b5346f85640ec2aa2fa057354d2b82c2fcbce # v1.0.1

- name: Change function to allow_unathorized calls
- name: Change function to allow_unathorized calls
shell: sh
run: |
gcloud functions add-iam-policy-binding ${{ steps.prepare.outputs.function_name }} \
Expand Down
49 changes: 27 additions & 22 deletions .github/actions/prepare-deploy/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ inputs:
description: "app name you're deploying"
required: true
deploy_to:
description: "(Optional) Manual trigger to deploy"
description: '(Optional) Manual trigger to deploy'
required: false
outputs:
function_name:
description: "App name with environment appended"
function_name:
description: 'App name with environment appended'
value: ${{ steps.naming.outputs.function_name}}
front_url:
description: "Full URL for your front-end piece"
front_url:
description: 'Full URL for your front-end piece'
value: ${{ steps.naming.outputs.front_url }}
gh_env:
description: "Github actions environment to use for deployment"
value: ${{ steps.setenv.outputs.gh_env }}
env_name:
description: "Name of environment to deploy to"
value: ${{ steps.naming.outputs.env_name }}
gh_env:
description: 'Github actions environment to use for deployment'
value: ${{ steps.setenv.outputs.gh_env }}
env_name:
description: 'Name of environment to deploy to'
value: ${{ steps.naming.outputs.env_name }}

runs:
using: composite
Expand All @@ -35,13 +35,13 @@ runs:
contains(inputs.deploy_to, 'staging') ||
contains(inputs.deploy_to, 'production') }}; then
echo "gh_env=production" >> $GITHUB_OUTPUT
fi
fi
- name: Set artifact names based on environment
id: naming
shell: bash
# Follow deployment strategy from
# https://centrifuge.hackmd.io/MFsnRldyQSa4cadx11OtVg?both#Environments
# Follow deployment strategy from
# https://centrifuge.hackmd.io/MFsnRldyQSa4cadx11OtVg?both#Environments
run: |
echo "Set app name based on env strategy"
if ${{ inputs.deploy_to == 'production' }}; then
Expand All @@ -63,32 +63,37 @@ runs:
elif ${{ inputs.deploy_to == 'catalyst' }}; then
# CATALYST
echo "function_name=${{ inputs.app_base_name }}-catalyst" >> $GITHUB_OUTPUT
echo "front_url=${{ inputs.app_base_name }}-catalyst.k-f.dev" >> $GITHUB_OUTPUT
echo "front_url=app-catalyst.k-f.dev" >> $GITHUB_OUTPUT
echo "env_name=catalyst" >> $GITHUB_OUTPUT
elif ${{ contains(inputs.deploy_to, 'demo') }}; then
elif ${{ inputs.deploy_to == 'demo' }}; then
# DEMO
echo "function_name=${{ inputs.app_base_name }}-demo" >> $GITHUB_OUTPUT
echo "front_url=${{ inputs.app_base_name }}-demo.k-f.dev" >> $GITHUB_OUTPUT
echo "front_url=app-demo.k-f.dev" >> $GITHUB_OUTPUT
echo "env_name=demo" >> $GITHUB_OUTPUT
elif ${{ inputs.deploy_to == 'ff-prod' }}; then
# FF-PRODUCTION
# A build from the DEV env that points to prod
echo "function_name=${{ inputs.app_base_name }}-ff-production" >> $GITHUB_OUTPUT
echo "front_url=app-ff-production.k-f.dev" >> $GITHUB_OUTPUT
echo "env_name=production" >> $GITHUB_OUTPUT
elif ${{ github.ref == 'refs/heads/main' }}; then
# DEV
echo "function_name=${{ inputs.app_base_name }}-dev" >> $GITHUB_OUTPUT
echo "front_url=${{ inputs.app_base_name }}-dev.k-f.dev" >> $GITHUB_OUTPUT
echo "env_name=development" >> $GITHUB_OUTPUT
echo "front_url=app-dev.k-f.dev" >> $GITHUB_OUTPUT
echo "env_name=development" >> $GITHUB_OUTPUT
elif ${{ github.event_name == 'pull_request' }}; then
# PR
echo "function_name=${{ inputs.app_base_name }}-pr${{ github.event.number }}" >> $GITHUB_OUTPUT
echo "front_url=${{ inputs.app_base_name }}-pr${{ github.event.number }}.k-f.dev" >> $GITHUB_OUTPUT
echo "front_url=app-pr${{ github.event.number }}.k-f.dev" >> $GITHUB_OUTPUT
echo "env_name=development" >> $GITHUB_OUTPUT
else
echo "::error title=No env to deploy::Workflow called from non-deployable branch/tag"
fi
- name: debug outputs
shell: bash
run: |
echo "URL ${{ steps.naming.outputs.front_url }}"
echo "App name: ${{ steps.naming.outputs.function_name }}"
echo "Env name: ${{ steps.naming.outputs.env_name }}"
echo "GH env: ${{ steps.setenv.outputs.gh_env }}"
21 changes: 9 additions & 12 deletions .github/workflows/centrifuge-app.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
name: Centrifuge App
on:
push:
branches:
- main
paths:
- 'centrifuge-app/**'
- 'centrifuge-js/**'
- 'centrifuge-react/**'
- '.github/workflows/centrifuge-app.yml'
- '.github/actions/deploy-gcs'
pull_request:
paths:
- 'centrifuge-app/**'
Expand All @@ -23,7 +14,7 @@ on:
required: false
# Fancy concurrency group string to allow for multi-staging deployments
concurrency:
group: 'centrifuge-app-${{ inputs.deploy_env || github.event.inputs.deploy_env }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
group: 'centrifuge-app-${{ inputs.deploy_env || github.event.inputs.deploy_env }}@${{ github.event.name }}${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true
env:
artifact_name: "webpack${{ inputs.deploy_env && format('-{0}', inputs.deploy_env) }}"
Expand Down Expand Up @@ -103,7 +94,7 @@ jobs:
deploy-app:
concurrency:
# Do not sync the same bucket in parallel
group: deploy-${{ needs.build-app.outputs.front_url }}
group: deploy-${{ needs.build-app.outputs.front_url }}-${{ github.event.name }}
cancel-in-progress: true
permissions:
contents: 'read'
Expand Down Expand Up @@ -138,17 +129,23 @@ jobs:
if: github.event_name == 'pull_request'
steps:
- name: PR comment with preview URL
id: prcomment
uses: thollander/actions-comment-pull-request@v2
env:
pull_sha: ${{ github.event.pull_request.head.sha }}
with:
comment_tag: pr_preview_url
mode: recreate
message: |
PR deployed in Google Cloud
URL: https://${{ needs.deploy-app.outputs.bucket_url }}
Commit #: ${{ env.pull_sha }}
To access the functions directly check the corresponding deploy Action
- name: Check notify outputs
run: |
echo "id : ${{ steps.prcomment.outputs.id }}"
echo "body : ${{ steps.prcomment.outputs.body }}"
echo "html_url : ${{ steps.prcomment.outputs.html_url }}"
# owasp_scan:
# needs: deploy-app
# runs-on: ubuntu-latest
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/deploy_all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: "Deploy all apps"
on:
# Allow this wofkflow as a universal "deployer" to
# call from other workflows.
workflow_call:
inputs:
environment:
required: true
type: string

jobs:
app:
name: webapp
uses: ./.github/workflows/centrifuge-app.yml
secrets: inherit
with:
deploy_env: ${{ inputs.environment}}


pinning:
if: ${{ inputs.environment != 'ff-prod' }}
name: pinning
uses: ./.github/workflows/pinning-api.yml
secrets: inherit
with:
deploy_env: ${{ inputs.environment }}


onboarding:
if: ${{ inputs.environment != 'ff-prod' }}
name: onboarding
uses: ./.github/workflows/onboarding-api.yml
secrets: inherit
with:
deploy_env: ${{ inputs.environment}}

faucet:
if: ${{ inputs.environment == 'demo' || inputs.environment == 'development' }}
name: faucet
uses: ./.github/workflows/faucet-api.yml
secrets: inherit
with:
deploy_env: ${{ inputs.environment}}
1 change: 0 additions & 1 deletion .github/workflows/fabric.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ jobs:

- run: yarn install --immutable
- run: yarn build
# - run: yarn ci:loki -> broken

- name: Build fabric storybook
run: yarn build-storybook
Expand Down
Loading

0 comments on commit 7624fb8

Please sign in to comment.