Skip to content

Commit

Permalink
build: staging conf
Browse files Browse the repository at this point in the history
  • Loading branch information
hai-ko committed Sep 5, 2023
1 parent 8c819cb commit ff99a38
Show file tree
Hide file tree
Showing 14 changed files with 136 additions and 48 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ jobs:
TARGET_HOST: ${{ secrets.STAGING_HOST }}
run: |
echo "REACT_APP_ADDR_ENS_SUBDOMAIN=.beta-addr.dm3.eth" >> ./.env.react
echo "REACT_APP_BACKEND=http://${{ secrets.STAGING_HOST }}" >> ./.env.react
echo "REACT_APP_BACKEND=http://${{ secrets.STAGING_HOST }}/api" >> ./.env.react
echo "REACT_APP_DEFAULT_DELIVERY_SERVICE=beta-ds.dm3.eth" >> ./.env.react
echo "REACT_APP_DEFAULT_SERVICE=http://${{ secrets.STAGING_HOST }}" >> ./.env.react
echo "REACT_APP_DEFAULT_SERVICE=http://${{ secrets.STAGING_HOST }}/api" >> ./.env.react
echo "REACT_APP_ETHEREUM_PROVIDER=${{ secrets.REACT_APP_ETHEREUM_PROVIDER }}" >> ./.env.react
echo "REACT_APP_PROFILE_BASE_URL=http://dm3-beta2-resolver.herokuapp.com" >> ./.env.react
echo "REACT_APP_RESOLVER_BACKEND=http://dm3-beta2-resolver.herokuapp.com" >> ./.env.react
echo "REACT_APP_PROFILE_BASE_URL=http://${{ secrets.STAGING_HOST }}/api" >> ./.env.react
echo "REACT_APP_RESOLVER_BACKEND=http://${{ secrets.STAGING_HOST }}/resolver-handler" >> ./.env.react
echo "REACT_APP_USER_ENS_SUBDOMAIN=.beta-user.dm3.eth" >> ./.env.react
echo "REACT_APP_WALLET_CONNECT_PROJECT_ID=${{ secrets.REACT_APP_WALLET_CONNECT_PROJECT_ID }}" >> ./.env.react
cat ./.env.react >> ./.env
echo "RESOLVER_ADDR=0x45F7Ed7d05c563D408898A80d9C705CC3328D2EF" >> ./.env
echo "WEB_PORT=80" >> ./.env
echo "SIGNING_PUBLIC_KEY=${{ secrets.SIGNING_PUBLIC_KEY }}" >> ./.env
echo "SIGNING_PRIVATE_KEY=${{ secrets.SIGNING_PRIVATE_KEY }}" >> ./.env
echo "SIGNER_PRIVATE_KEY=${{ secrets.SIGNER_PRIVATE_KEY }}" >> ./.env
echo "SPAM_PROTECTION=${{ secrets.SPAM_PROTECTION }}" >> ./.env
echo "ENCRYPTION_PUBLIC_KEY=${{ secrets.ENCRYPTION_PUBLIC_KEY }}" >> ./.env
echo "ENCRYPTION_PRIVATE_KEY=${{ secrets.ENCRYPTION_PRIVATE_KEY }}" >> ./.env
echo "RPC=${{ secrets.RPC }}" >> ./.env
echo "RPC=${{ secrets.STAGING_RPC }}" >> ./.env
envsubst '${SSL_CERTIFICATE_BASE_LOC} ${TLS_CERTIFICATE_LOCATION} ${TARGET_HOST}' < ./docker/nginx.conf > ./nginx.conf
- name: Build docker image
run: |
Expand All @@ -53,10 +53,11 @@ jobs:
rsync -avz -e 'ssh -i ./ssh-key' ./dm3-backend.tar app@${{ secrets.STAGING_HOST }}:/home/app/dm3
rsync -avz -e 'ssh -i ./ssh-key' ./nginx.conf app@${{ secrets.STAGING_HOST }}:/home/app/dm3
rsync -avz -e 'ssh -i ./ssh-key' ./docker/docker-compose.yml app@${{ secrets.STAGING_HOST }}:/home/app/dm3
- name: Load image
- name: Load docker image
run: |
ssh -i ./ssh-key app@${{ secrets.STAGING_HOST }} "\
cd dm3 && docker load -i dm3-backend.tar"
cd dm3 && docker load -i dm3-backend.tar; \
rm dm3-backend.tar"
- name: Start
run: |
ssh -i ./ssh-key app@${{ secrets.STAGING_HOST }} "\
Expand Down
31 changes: 18 additions & 13 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
version: "3.1"
services:

# nginx:
# container_name: nginx
# image: nginx:latest
# restart: always
# volumes:
# - ./nginx.conf:/etc/nginx/nginx.conf
# ports:
# - "80:80"
# - "443:443"
nginx:
container_name: nginx
image: nginx:latest
restart: always
depends_on:
- offchain-resolver
- web
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
ports:
- "80:80"
- "443:443"

backend:
image: dm3-backend
Expand All @@ -23,6 +26,8 @@ services:
ENCRYPTION_PUBLIC_KEY: ${ENCRYPTION_PUBLIC_KEY}
ENCRYPTION_PRIVATE_KEY: ${ENCRYPTION_PUBLIC_KEY}
RPC: ${RPC}
ports:
- '8081:8081'

db:
image: redis
Expand All @@ -44,7 +49,7 @@ services:
- offchain-resolver-db
environment:
DATABASE_URL: postgresql://postgres:example@offchain-resolver-db:5432

PORT: 8082
ports:
- '8082:8082'

Expand All @@ -63,7 +68,7 @@ services:
REACT_APP_WALLET_CONNECT_PROJECT_ID: ${REACT_APP_WALLET_CONNECT_PROJECT_ID}
RESOLVER_ADDR: ${RESOLVER_ADDR}
ports:
- '${WEB_PORT}:8080'
- '8080:8080'

ccip-resolver:
image: dm3org/ccip-resolver:v0.2.2
Expand All @@ -75,9 +80,9 @@ services:
LOG_LEVEL: debug
CONFIG: |
{
"0x5e0F81D5ca51D309B3A046FAeea70C4C70Df8079": {
"0x4283441191a27513c2160c1e7BC1aa02Ab84D900": {
"type": "signing",
"handlerUrl": "http://offchain-resolver:8081"
"handlerUrl": "http://offchain-resolver:8082"
}
}
PORT: 8181
Expand Down
40 changes: 39 additions & 1 deletion docker/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ events {

http {
keepalive_timeout 65;

limit_req_zone $binary_remote_addr zone=standardlimit:10m rate=3r/s;
limit_req_zone $binary_remote_addr zone=legacylimit:10m rate=2r/s;

server {
listen 80;
Expand All @@ -22,6 +23,43 @@ http {
}


location /resolver {
rewrite ^/resolver(.*)$ $1 break;
limit_req zone=standardlimit burst=50;
proxy_pass http://ccip-resolver:8181;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

proxy_redirect off;
}

location /resolver-handler {
rewrite ^/resolver-handler(.*)$ $1 break;
limit_req zone=standardlimit burst=50;
proxy_pass http://offchain-resolver:8082;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

proxy_redirect off;
}

location /api {
rewrite ^/api(.*)$ $1 break;
limit_req zone=standardlimit burst=50;
proxy_pass http://backend:8081;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

proxy_redirect off;
}


}


Expand Down
4 changes: 2 additions & 2 deletions packages/lib/offchainResolver-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
},
"dependencies": {
"axios": "^1.3.4",
"axios": "^1.5.0",
"dm3-lib-profile": "^0.2.0",
"ethers": "5.7.2"
},
Expand All @@ -25,7 +25,7 @@
"jest": "^28.1.1",
"ts-jest": "^28.0.4",
"ts-json-schema-generator": "^0.98.0",
"typescript": "^4.4.2"
"typescript": "^4.7.0"
},
"scripts": {
"build": "yarn tsc --declaration ",
Expand Down
4 changes: 2 additions & 2 deletions packages/lib/offchainResolver-api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "CommonJS",
"moduleResolution": "node",
"module": "node16",
"moduleResolution": "node16",
"resolveJsonModule": true,
"isolatedModules": true,
"outDir": "dist",
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/profile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@
"test": "jest --coverage --transformIgnorePatterns 'node_modules/(?!(dm3-lib-\\w*)/)'"
},
"files": [
"dist"
"dist"
]
}
12 changes: 12 additions & 0 deletions packages/messenger-demo/config-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,17 @@ module.exports = function override(config) {
Buffer: ['buffer', 'Buffer'],
}),
]);

config.module.rules = config.module.rules.map((rule) => {
if (rule.oneOf instanceof Array) {
rule.oneOf[rule.oneOf.length - 1].exclude = [
/\.(js|mjs|jsx|cjs|ts|tsx)$/,
/\.html$/,
/\.json$/,
];
}
return rule;
});

return config;
};
2 changes: 1 addition & 1 deletion packages/messenger-demo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"moduleResolution": "node16",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
Expand Down
4 changes: 2 additions & 2 deletions packages/messenger-widget/src/views/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
RainbowKitProvider,
} from '@rainbow-me/rainbowkit';
import { configureChains, createConfig, WagmiConfig } from 'wagmi';
import { mainnet } from 'wagmi/chains';
import { mainnet, goerli } from 'wagmi/chains';
import {
metaMaskWallet,
rainbowWallet,
Expand All @@ -23,7 +23,7 @@ import { ConfigureProfile } from '../../components/ConfigureProfile/ConfigurePro

export function Home(props: Dm3Props) {
const { chains, publicClient } = configureChains(
[mainnet],
[goerli],
[
jsonRpcProvider({
rpc: () => ({
Expand Down
2 changes: 1 addition & 1 deletion packages/messenger-widget/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"moduleResolution": "node16",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,27 @@ export async function handleCcipRequest(
return ethers.utils.defaultAbiCoder.encode(['string'], [profile]);
case 'addr(bytes32)':
req.app.locals.logger.info('Reading addr(bytes32))');
return await handleAddr(req.app.locals.db, request);
const addrProfile = await handleAddr(req.app.locals.db, request);
if (!addrProfile) {
return null;
}
return ethers.utils.defaultAbiCoder.encode(
['string'],
[addrProfile],
);
case 'addr(bytes32,uint256)':
req.app.locals.logger.info('Reading addr(bytes32,uint256))');
return await handleAddr(req.app.locals.db, request);
const addrProfileCoinType = await handleAddr(
req.app.locals.db,
request,
);
if (!addrProfileCoinType) {
return null;
}
return ethers.utils.defaultAbiCoder.encode(
['string'],
[addrProfileCoinType],
);

default:
return null;
Expand Down
17 changes: 11 additions & 6 deletions packages/offchain-resolver/src/http/resolverEndpoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,16 @@ describe('Resolver Endpoint', () => {
'resolve',
[encodeEnsName(ensName), innerCall],
);
const { body, status } = await request(ccipApp)
const { text, status } = await request(ccipApp)
.get(`/${ethers.constants.AddressZero}/${outerCall}`)
.send();
expect(status).to.equal(200);
expect(body.response).to.equal(

const [decoded] = ethers.utils.defaultAbiCoder.decode(
['string'],
text,
);
expect(decoded).to.equal(
'0x25A643B6e52864d0eD816F1E43c0CF49C83B8292',
);
});
Expand Down Expand Up @@ -127,15 +132,15 @@ describe('Resolver Endpoint', () => {
'resolve',
[encodeEnsName(ensName), innerCall],
);
const { body, status } = await request(ccipApp)
const { text, status } = await request(ccipApp)
.get(`/${ethers.constants.AddressZero}/${outerCall}`)
.send();

expect(status).to.equal(200);

const [decoded] = ethers.utils.defaultAbiCoder.decode(
['string'],
body.response,
text,
);
expect(decoded).to.equal('test');
});
Expand Down Expand Up @@ -185,13 +190,13 @@ describe('Resolver Endpoint', () => {
'resolve',
[encodeEnsName(name), innerCall],
);
const { body, status } = await request(ccipApp)
const { text, status } = await request(ccipApp)
.get(`/${ethers.constants.AddressZero}/${outerCall}`)
.send();

const [decoded] = ethers.utils.defaultAbiCoder.decode(
['string'],
body.response,
text,
);

expect(status).to.equal(200);
Expand Down
9 changes: 4 additions & 5 deletions packages/offchain-resolver/src/http/resolverEndpoint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logError } from 'dm3-lib-shared';
import { logError, logWarning } from 'dm3-lib-shared';
import express from 'express';
import { handleCcipRequest } from './handleCcipRequest/handleCcipRequest';
import { WithLocals } from './types';
Expand Down Expand Up @@ -30,11 +30,10 @@ export function resolverEndpoint() {
);

if (!response) {
logError('Record not found');

res.status(404).send({ message: 'Record not found' });
logWarning('Record not found');
res.status(200).send('0x');
} else {
res.status(200).send({ response });
res.status(200).send(response);
}
} catch (e) {
req.app.locals.logger.warn((e as Error).message);
Expand Down
Loading

0 comments on commit ff99a38

Please sign in to comment.