Skip to content

Commit

Permalink
Merge pull request #6 from sayandcode/misc/iac-for-web-app
Browse files Browse the repository at this point in the history
Set up IaC for deployments
  • Loading branch information
sayandcode authored Mar 29, 2024
2 parents 40b0214 + f20b788 commit fa1dec8
Show file tree
Hide file tree
Showing 138 changed files with 9,279 additions and 1,848 deletions.
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

0 comments on commit fa1dec8

Please sign in to comment.