Skip to content

Commit c15d07b

Browse files
authored
Merge pull request #36 from Open-Captable-Protocol/dev
Main Merge
2 parents af68ad0 + dea978f commit c15d07b

File tree

157 files changed

+6770
-9693
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+6770
-9693
lines changed

.dockerignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules
2-
npm-debug.log
2+
npm-debug.log
3+
!chain/out
4+
!chain/out/**/*.json

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ CONVERTIBLES_FACET=
2929
EQUITY_COMPENSATION_FACET=
3030
STOCK_PLAN_FACET=
3131
WARRANT_FACET=
32-
STAKEHOLDER_NFT_FACET=
32+
STAKEHOLDER_NFT_FACET=

.github/workflows/deploy.dev.yaml

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
name: Deployment (Dev)
2+
3+
on:
4+
push:
5+
branches:
6+
- dev
7+
- adam/setup-cicd
8+
9+
jobs:
10+
build:
11+
name: Build, Test, and Deploy
12+
environment: dev
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v2
17+
with:
18+
submodules: true
19+
fetch-depth: 0
20+
21+
# Setup and cache dependencies
22+
- name: Setup Node.js
23+
uses: actions/setup-node@v3
24+
with:
25+
node-version: "18"
26+
cache: "yarn"
27+
28+
- name: Install Node Dependencies
29+
run: yarn install --frozen-lockfile
30+
31+
- name: Install Foundry
32+
uses: foundry-rs/foundry-toolchain@v1
33+
with:
34+
version: nightly
35+
36+
- name: Run Forge Install Script
37+
run: chmod +x setup.sh && ./setup.sh
38+
39+
# Run all tests and checks
40+
- name: Run Forge Tests
41+
run: cd chain && forge test --summary
42+
43+
- name: Run ESLint
44+
run: yarn lint:check
45+
46+
- name: Check Formatting
47+
run: yarn format:check
48+
49+
# Build and Deploy
50+
- name: Deploy
51+
shell: bash
52+
env:
53+
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
54+
HOST: ${{ secrets.LIGHTSAIL_INSTANCE_PUBLIC_IP_DEV }}
55+
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
56+
ETHERSCAN_L2_API_KEY: ${{ secrets.ETHERSCAN_L2_API_KEY }}
57+
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
58+
DATABASE_URL: ${{ secrets.DATABASE_URL }}
59+
RPC_URL: ${{ secrets.RPC_URL }}
60+
CHAIN_ID: ${{ secrets.CHAIN_ID }}
61+
62+
run: |
63+
# Generate timestamp for deployment
64+
DEPLOY_TIME=$(date +%s)
65+
echo "DEPLOY_TIME: $DEPLOY_TIME"
66+
67+
# Save SSH key and set permissions
68+
echo "$SSH_PRIVATE_KEY" > deploy_key
69+
chmod 600 deploy_key
70+
71+
# Create a temp directory for deployment
72+
DEPLOY_DIR="/tmp/deploy-${DEPLOY_TIME}"
73+
mkdir -p $DEPLOY_DIR
74+
75+
# Copy necessary files to temp directory
76+
echo "Preparing deployment files..."
77+
cp -r . $DEPLOY_DIR/
78+
79+
# Sync files to server
80+
echo "Syncing files to server..."
81+
rsync -az --delete \
82+
--exclude='node_modules' \
83+
--exclude='.git' \
84+
--exclude='deploy_key' \
85+
--include='chain/out' \
86+
--include='chain/out/**' \
87+
-e "ssh -i deploy_key -o StrictHostKeyChecking=no" \
88+
$DEPLOY_DIR/ \
89+
ubuntu@"$HOST":/home/ubuntu/app-${DEPLOY_TIME}
90+
91+
# Execute deployment on server
92+
ssh -i deploy_key -o StrictHostKeyChecking=no ubuntu@"$HOST" "
93+
sudo su && \
94+
cd /home/ubuntu/app-${DEPLOY_TIME} && \
95+
echo 'Building image on host...' && \
96+
# Source the functions
97+
source ./scripts/docker_container_utils.sh && \
98+
docker build -t ocp-dev:${DEPLOY_TIME} -f Dockerfile.dev . && \
99+
100+
# Initial cleanup
101+
echo 'Cleaning up old resources...' && \
102+
docker ps -q --filter 'publish=8081' | xargs -r docker rm -f && \
103+
docker ps -q --filter 'publish=8082' | xargs -r docker rm -f && \
104+
docker container prune -f && \
105+
docker image prune -f && \
106+
107+
# Start new container
108+
echo 'Starting new container...' && \
109+
CONTAINER_NAME=ocp-dev-${DEPLOY_TIME} && \
110+
111+
# Run container
112+
docker run --name \$CONTAINER_NAME -d \
113+
--health-cmd='curl -f http://localhost:8080/health || exit 1' \
114+
--health-interval='2s' \
115+
--health-retries='3' \
116+
--health-timeout='5s' \
117+
--restart always \
118+
-e DOCKER_ENV='true' \
119+
-e NODE_ENV='development' \
120+
-e SENTRY_DSN='${SENTRY_DSN}' \
121+
-e DATABASE_URL='${DATABASE_URL}' \
122+
-e RPC_URL='${RPC_URL}' \
123+
-e CHAIN_ID='${CHAIN_ID}' \
124+
-e PORT=8080 \
125+
-e PRIVATE_KEY='${PRIVATE_KEY}' \
126+
-e ETHERSCAN_L2_API_KEY='${ETHERSCAN_L2_API_KEY}' \
127+
-v '/home/ubuntu/global-bundle.pem:/global-bundle.pem' \
128+
ocp-dev:${DEPLOY_TIME} && \
129+
130+
# Wait for container to be healthy
131+
wait_for_health "\$CONTAINER_NAME" && \
132+
if [ \$? -eq 0 ]; then
133+
handle_container_switch "\$CONTAINER_NAME" "${DEPLOY_TIME}" "dev"
134+
else
135+
handle_failed_deployment "\$CONTAINER_NAME" "${DEPLOY_TIME}" "dev"
136+
fi
137+
"

.github/workflows/deploy.prod.yaml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
name: Deployment (Prod)
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build:
10+
name: Build, Test, and Deploy
11+
environment: prod
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v2
16+
with:
17+
submodules: true
18+
fetch-depth: 0
19+
20+
# Setup and cache dependencies
21+
- name: Setup Node.js
22+
uses: actions/setup-node@v3
23+
with:
24+
node-version: "18"
25+
cache: "yarn"
26+
27+
- name: Install Node Dependencies
28+
run: yarn install --frozen-lockfile
29+
30+
- name: Install Foundry
31+
uses: foundry-rs/foundry-toolchain@v1
32+
33+
- name: Run Forge Install Script
34+
run: chmod +x setup.sh && ./setup.sh
35+
36+
# Run all tests and checks
37+
- name: Run Forge Tests
38+
run: cd chain && forge test --summary
39+
40+
- name: Run ESLint
41+
run: yarn lint:check
42+
43+
- name: Check Formatting
44+
run: yarn format:check
45+
46+
- name: Deploy
47+
shell: bash
48+
env:
49+
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
50+
HOST: ${{ secrets.LIGHTSAIL_INSTANCE_PUBLIC_IP_PROD }}
51+
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
52+
ETHERSCAN_L2_API_KEY: ${{ secrets.ETHERSCAN_L2_API_KEY }}
53+
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
54+
DATABASE_URL: ${{ secrets.DATABASE_URL }}
55+
RPC_URL: ${{ secrets.RPC_URL }}
56+
CHAIN_ID: ${{ secrets.CHAIN_ID }}
57+
58+
run: |
59+
# Generate timestamp for deployment
60+
DEPLOY_TIME=$(date +%s)
61+
# Save SSH key and set permissions
62+
echo "$SSH_PRIVATE_KEY" > deploy_key
63+
chmod 600 deploy_key
64+
65+
# Create a temp directory for deployment
66+
DEPLOY_DIR="/tmp/deploy-${DEPLOY_TIME}"
67+
mkdir -p $DEPLOY_DIR
68+
69+
# Copy necessary files to temp directory
70+
echo "Preparing deployment files..."
71+
cp -r . $DEPLOY_DIR/
72+
73+
# Sync files to server
74+
echo "Syncing files to server..."
75+
rsync -az --delete \
76+
--exclude='node_modules' \
77+
--exclude='.git' \
78+
--exclude='deploy_key' \
79+
--include='chain/out' \
80+
--include='chain/out/**' \
81+
-e "ssh -i deploy_key -o StrictHostKeyChecking=no" \
82+
$DEPLOY_DIR/ \
83+
ubuntu@"$HOST":/home/ubuntu/app-${DEPLOY_TIME}
84+
85+
sudo su && \
86+
cd /home/ubuntu/app-${DEPLOY_TIME} && \
87+
echo "Building image on host..." && \
88+
# Source the functions
89+
source ./scripts/docker_container_utils.sh && \
90+
docker build -t ocp-prod:${DEPLOY_TIME} -f Dockerfile.prod . && \
91+
92+
# Initial cleanup of dangling images and stopped containers
93+
echo "Cleaning up old resources..." && \
94+
docker ps -q --filter "publish=8081" | xargs -r docker rm -f && \
95+
docker ps -q --filter "publish=8082" | xargs -r docker rm -f && \
96+
docker container prune -f && \
97+
docker image prune -f && \
98+
99+
# Start new container on different port
100+
echo "Starting new container..." && \
101+
CONTAINER_NAME=ocp-prod-${DEPLOY_TIME} && \
102+
NEW_PORT=$(get_port)
103+
echo "Using port: $NEW_PORT" && \
104+
105+
docker run --name $CONTAINER_NAME -d \
106+
-p ${NEW_PORT}:8080 \
107+
--health-cmd="curl -f http://localhost:8080/health || exit 1" \
108+
--health-interval=2s \
109+
--health-retries=3 \
110+
--health-timeout=5s \
111+
--restart always \
112+
-e DOCKER_ENV="true" \
113+
-e NODE_ENV="production" \
114+
-e SENTRY_DSN="${{ secrets.SENTRY_DSN }}" \
115+
-e DATABASE_URL="${{ secrets.DATABASE_URL }}" \
116+
-e RPC_URL="${{ secrets.RPC_URL }}" \
117+
-e CHAIN_ID="${{ secrets.CHAIN_ID }}" \
118+
-e PORT=8080 \
119+
-e PRIVATE_KEY="${{ secrets.PRIVATE_KEY }}" \
120+
-e ETHERSCAN_L2_API_KEY="${{ secrets.ETHERSCAN_L2_API_KEY }}" \
121+
-v "/home/ubuntu/global-bundle.pem:/global-bundle.pem" \
122+
ocp-prod:${DEPLOY_TIME} && \
123+
124+
# Wait for container to be healthy
125+
wait_for_health "$CONTAINER_NAME" && \
126+
127+
# If container is healthy, switch traffic
128+
if [ $? -eq 0 ]; then
129+
handle_container_switch "$CONTAINER_NAME" "${DEPLOY_TIME}" "prod"
130+
else
131+
handle_failed_deployment "$CONTAINER_NAME" "${DEPLOY_TIME}" "prod"
132+
fi

.github/workflows/integrate.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Integration Tests
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "*"
7+
- "!main"
8+
- "dev"
9+
types: [opened, synchronize, reopened]
10+
11+
jobs:
12+
test:
13+
name: Build and Test
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v2
18+
with:
19+
submodules: true
20+
fetch-depth: 0
21+
22+
# Install only ESLint dependencies
23+
- name: Install ESLint Dependencies
24+
run: |
25+
yarn add -D @eslint/js@latest \
26+
@typescript-eslint/eslint-plugin@latest \
27+
@typescript-eslint/parser@latest \
28+
eslint-plugin-import@latest \
29+
globals@latest
30+
31+
- name: Install Foundry
32+
uses: foundry-rs/foundry-toolchain@v1
33+
with:
34+
version: nightly
35+
36+
- name: Run Forge Install Script
37+
run: |
38+
chmod +x setup.sh && ./setup.sh
39+
40+
# Run all tests and checks
41+
- name: Run Forge Tests
42+
run: cd chain && forge test --summary
43+
44+
- name: Run ESLint
45+
run: npx eslint "src/**/*.{js,ts,mjs,mts}"
46+
47+
- name: Check Formatting
48+
run: npx prettier --check "src/**/*.{js,mjs,ts,mts,json,md}"

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ tsconfig.tsbuildinfo
3939
.env.*
4040
chain/out
4141
chain/lib/*
42+
solana/*
43+
*.ignore.js

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[submodule "ocf"]
2+
path = ocf
3+
url = https://github.com/Open-Cap-Table-Coalition/Open-Cap-Format-OCF
14
[submodule "chain/lib/forge-std"]
25
path = chain/lib/forge-std
36
url = https://github.com/foundry-rs/forge-std
@@ -10,6 +13,3 @@
1013
[submodule "chain/lib/diamond-3-hardhat"]
1114
path = chain/lib/diamond-3-hardhat
1215
url = https://github.com/mudgen/diamond-3-hardhat
13-
[submodule "ocf"]
14-
path = ocf
15-
url = https://github.com/Open-Cap-Table-Coalition/Open-Cap-Format-OCF

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
yarn flightcheck
2+
cd chain && forge fmt

.prettierrc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@
55
"bracketSpacing": true,
66
"arrowParens": "always",
77
"printWidth": 150,
8-
"endOfLine": "auto",
9-
"formatOnSave": true,
10-
"editor.formatOnSave": true
8+
"endOfLine": "auto"
119
}

0 commit comments

Comments
 (0)