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

Set up IaC for deployments #6

Merged
merged 34 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b1c74ef
web-app/chore: Move web-app application code into src
sayandcode Mar 20, 2024
f9eab62
web-app/chore: Set up AWS CDK for IaC
sayandcode Mar 20, 2024
a9b4106
web-app/ci: Add build process for lambda
sayandcode Mar 21, 2024
5eaa241
web-app/ci: Setup build and deploy scripts for `infra`
sayandcode Mar 21, 2024
fe927fe
web-app/chore: Set up eslint for infra directory
sayandcode Mar 21, 2024
b8ab18b
chore: Allow infra folder to read from other folders
sayandcode Mar 23, 2024
7d825cc
contracts/ci: Add production deployment script
sayandcode Mar 24, 2024
88afb76
web-app/fix: Close modal when user rejects transaction
sayandcode Mar 24, 2024
0834337
web-app/refactor: Move dappInfo and chainInfo schemas into dedicated …
sayandcode Mar 24, 2024
d43e4d4
web-app/chore: Add browser env
sayandcode Mar 24, 2024
95ffbdb
web-app/refactor: Use chainInfo and dappInfo from env, not root loader
sayandcode Mar 24, 2024
3f3bfa0
web-app/chore: Add block explorer info to env & Rename `getParsedEnv`…
sayandcode Mar 24, 2024
a5e7fa5
web-app/feat: Add block explorer link for `requestSampleTokens`
sayandcode Mar 24, 2024
1c564bc
web-app/ci: Add script for production app building
sayandcode Mar 24, 2024
fb8f3f8
contracts/ci: Deploy to Polygon Mumbai Testnet
sayandcode Mar 24, 2024
fde13e7
web-app/chore: Setup local production server
sayandcode Mar 25, 2024
960e013
web-app/feat: Add splat route
sayandcode Mar 27, 2024
05e0b5b
web-app/feat: Add chain-switch dialog prompt
sayandcode Mar 27, 2024
0dd7e4c
web-app/fix: Prevent crash when metamask not installed
sayandcode Mar 27, 2024
405a09c
web-app/refactor: Move Active Chain ID fetch to RTK query
sayandcode Mar 27, 2024
5e119e8
web-app/feat: Try to use User's RPC first
sayandcode Mar 28, 2024
00dc1d9
web-app/feat: Update meta info
sayandcode Mar 28, 2024
4a1139a
web-app/feat: Setup cache control
sayandcode Mar 28, 2024
ca77828
web-app/fix: Fix __dirname issue on lambda
sayandcode Mar 28, 2024
3b8b857
web-app/ci: Add AWS CDK IaC for hosting web app
sayandcode Mar 28, 2024
d3f3ed2
web-app/fix: Add block count limit to Log Data Charts
sayandcode Mar 29, 2024
f6fd084
web-app/feat: Add block explorer url to `ChainInfo`
sayandcode Mar 29, 2024
07ecbc2
web-app/chore: Add jsdoc for env variables
sayandcode Mar 29, 2024
d27d7b8
contracts/ci: Update testing CI script and README
sayandcode Mar 29, 2024
221fe60
web-app/ci: Add pipeline for quality checks
sayandcode Mar 29, 2024
bdfe3a1
ci: Unify Quality control pipelines
sayandcode Mar 29, 2024
9bfc0ee
ci: Add web app deployment pipeline
sayandcode Mar 29, 2024
4bbe446
ci: Fix config bugs in deployment and QC pipelines
sayandcode Mar 29, 2024
f20b788
web-app/chore: Add project tag to IaC resources
sayandcode Mar 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/deploy-web-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Deploy Web app and Infrastructure
on: workflow_dispatch

permissions:
id-token: write
contents: read

jobs:
main:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Setup Node v20.10
uses: actions/setup-node@v4
with:
node-version: 20.10

# We need foundry for contract types
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Setup AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ap-south-1
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-session-name: FinthetixDeploymentSession

- name: Install node dependencies
run: |
cd web-app/infra
npm ci

- name: Deploy
env:
WEB_APP_INFRA_ENV: ${{ secrets.WEB_APP_INFRA_ENV }}
run: |
cd web-app/infra
echo "$WEB_APP_INFRA_ENV" > .env
npm run deploy
88 changes: 88 additions & 0 deletions .github/workflows/quality-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Quality Check

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

jobs:
test-contracts:
name: Test contracts
env:
FOUNDRY_PROFILE: ci
defaults:
run:
working-directory: contracts
strategy:
fail-fast: true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
sparse-checkout: contracts

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Run Forge build
run: |
forge --version
forge build --sizes
id: build

- name: Run Forge tests
run: |
forge test -vvv
id: test

build-typecheck-lint:
name: Build, typecheck and lint web app
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

# We need foundry for contract types
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Setup Node v20.10
uses: actions/setup-node@v4
with:
node-version: 20.10

- name: Install node dependencies
run: |
cd web-app/infra
npm ci

- name: Build infra and src
env:
WEB_APP_INFRA_ENV: ${{ secrets.WEB_APP_INFRA_ENV }}
run: |
cd web-app/infra
echo "$WEB_APP_INFRA_ENV" > .env
npm run build

- name: Lint
run: |
cd web-app/infra
npm run lint
cd ../src
npm run lint

- name: Typecheck
run: |
cd web-app/infra
npm run typecheck
cd ../src
npm run typecheck
47 changes: 0 additions & 47 deletions .github/workflows/test-contracts.yml

This file was deleted.

12 changes: 11 additions & 1 deletion contracts/.env.sample
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
PRIVATE_KEY="" # deployer private key
# The name of the account from `cast wallet` used for deployment
DEPLOYER_ACC_NAME=''

# The chain to which you are deploying. Make sure that the etherscan and RPC_URL are looking at the same chain
CHAIN_NAME="sepolia"

# The API key for verifying contract code on etherscan
ETHER_SCAN_API_KEY="4R9KW77TXKSQ1PV4STEWF1ZHHNZDZ2YAIG"

# The RPC URL for broadcasting the contract deployment
RPC_URL="https://eth-sepolia.g.alchemy.com/v2/mf16xqfXJrEylHiHuhg4nPfg6H5T9n2l"
15 changes: 14 additions & 1 deletion contracts/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
include .env

DEPLOY_SCRIPT=script/01_Deploy.s.sol

# These hardcoded private keys are from the anvil local chain
deploy-dev: $(DEPLOY_SCRIPT)
forge script $(DEPLOY_SCRIPT) --rpc-url http://127.0.0.1:8545 --broadcast
forge script $(DEPLOY_SCRIPT) --rpc-url http://127.0.0.1:8545 --broadcast \
--sender 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
--private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

deploy-prod: $(DEPLOY_SCRIPT)
@forge script $(DEPLOY_SCRIPT) --rpc-url ${RPC_URL} --broadcast \
--account ${DEPLOYER_ACC_NAME} \
--sender $$(cast wallet address --account ${DEPLOYER_ACC_NAME}) \
--verify --chain ${CHAIN_NAME} --etherscan-api-key ${ETHER_SCAN_API_KEY}

17 changes: 17 additions & 0 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,21 @@ $ forge test

```shell
$ forge snapshot
```

### Deploy to Local Anvil (development) chain
First start the anvil chain on a separate shell session
```shell
/contracts$ anvil
```
Then deploy to it with the following command. It will use the default RPC used by anvil
```shell
# (Optional) sudo apt install make
/contracts$ make deploy-dev
```

### Deploy to Production Chain
```shell
# (Optional) sudo apt install make
/contracts$ make deploy-prod
```
74 changes: 74 additions & 0 deletions contracts/broadcast/01_Deploy.s.sol/11155111/run-1711247789.json

Large diffs are not rendered by default.

120 changes: 120 additions & 0 deletions contracts/broadcast/01_Deploy.s.sol/11155111/run-1711247803.json

Large diffs are not rendered by default.

120 changes: 120 additions & 0 deletions contracts/broadcast/01_Deploy.s.sol/11155111/run-1711247866.json

Large diffs are not rendered by default.

120 changes: 120 additions & 0 deletions contracts/broadcast/01_Deploy.s.sol/11155111/run-latest.json

Large diffs are not rendered by default.

74 changes: 74 additions & 0 deletions contracts/broadcast/01_Deploy.s.sol/80001/run-1711284092.json

Large diffs are not rendered by default.

153 changes: 153 additions & 0 deletions contracts/broadcast/01_Deploy.s.sol/80001/run-1711284099.json

Large diffs are not rendered by default.

153 changes: 153 additions & 0 deletions contracts/broadcast/01_Deploy.s.sol/80001/run-1711284147.json

Large diffs are not rendered by default.

153 changes: 153 additions & 0 deletions contracts/broadcast/01_Deploy.s.sol/80001/run-latest.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions contracts/script/01_Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import {FinthetixStakingContract} from "src/FinthetixStakingContract.sol";

contract DappDeployer is Script {
function run() public returns (address stakingTokenAddr, address stakingContractAddr, address rewardTokenAddr) {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);
vm.startBroadcast();
FinthetixStakingToken stakingToken = new FinthetixStakingToken();
FinthetixStakingContract stakingContract = new FinthetixStakingContract(address(stakingToken));
vm.stopBroadcast();
Expand Down
4 changes: 0 additions & 4 deletions web-app/.env.sample

This file was deleted.

38 changes: 0 additions & 38 deletions web-app/README.md

This file was deleted.

28 changes: 0 additions & 28 deletions web-app/app/lib/env.ts

This file was deleted.

15 changes: 0 additions & 15 deletions web-app/app/lib/loaders/dappInfo.ts

This file was deleted.

45 changes: 0 additions & 45 deletions web-app/app/redux/services/lib/Metamask.ts

This file was deleted.

Loading