Skip to content

Commit

Permalink
build: docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
hai-ko committed Aug 29, 2023
1 parent 1943a6d commit e9dda20
Show file tree
Hide file tree
Showing 15 changed files with 194 additions and 68 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Push Workflow
on: push

jobs:
messenger-demo-deploy:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/${{ vars.STAGING_BRANCH }}'
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
registry-url: 'https://npm.pkg.github.com'
node-version: 18.0.0
cache: 'yarn'
- name: Prepare SSH
run: |
mkdir ~/.ssh
echo "${{ secrets.STAGING_HOST_SSH }}" > ~/.ssh/known_hosts
echo "${{ secrets.DO_SSH_KEY }}" > ./ssh-key
chmod 600 ./ssh-key
- name: Create .env file
run: |
echo "REACT_APP_ADDR_ENS_SUBDOMAIN=.beta-addr.dm3.eth" >> ./.env
echo "REACT_APP_BACKEND=http://${{ secrets.STAGING_HOST }}" >> ./.env
echo "REACT_APP_DEFAULT_DELIVERY_SERVICE=beta-ds.dm3.eth" >> ./.env
echo "REACT_APP_DEFAULT_SERVICE=http://${{ secrets.STAGING_HOST }}" >> ./.env
echo "REACT_APP_ETHEREUM_PROVIDER=${{ secrets.REACT_APP_ETHEREUM_PROVIDER }}" >> ./.env
echo "REACT_APP_PROFILE_BASE_URL=http://dm3-beta2-resolver.herokuapp.com" >> ./.env
echo "REACT_APP_RESOLVER_BACKEND=http://dm3-beta2-resolver.herokuapp.com" >> ./.env
echo "REACT_APP_USER_ENS_SUBDOMAIN=.beta-user.dm3.eth" >> ./.env
echo "REACT_APP_WALLET_CONNECT_PROJECT_ID=${{ secrets.REACT_APP_WALLET_CONNECT_PROJECT_ID }}" >> ./.env
echo "RESOLVER_ADDR=0x45F7Ed7d05c563D408898A80d9C705CC3328D2EF" >> ./.env
echo WEB_PORT=80 >> ./.env
- name: Sync files
run: |
rsync -avz -e 'ssh -i ./ssh-key' ./ app@${{ secrets.STAGING_HOST }}:/home/app/
63 changes: 12 additions & 51 deletions .github/workflows/on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on: push
jobs:
code-quality:
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/${{ vars.STAGING_BRANCH }}'
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
Expand All @@ -22,7 +23,7 @@ jobs:

build:
runs-on: ubuntu-latest

if: github.ref != 'refs/heads/${{ vars.STAGING_BRANCH }}'
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
Expand Down Expand Up @@ -50,6 +51,7 @@ jobs:
path: packages/lib/**/schema/
backend-test:
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/${{ vars.STAGING_BRANCH }}'
needs: build
defaults:
run:
Expand All @@ -63,6 +65,7 @@ jobs:
package-pat: ${{ secrets.PACKAGE_PAT }}
integration-test:
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/${{ vars.STAGING_BRANCH }}'
needs: build
defaults:
run:
Expand All @@ -76,6 +79,7 @@ jobs:
package-pat: ${{ secrets.PACKAGE_PAT }}
lib-crypto-test:
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/${{ vars.STAGING_BRANCH }}'
needs: build
defaults:
run:
Expand All @@ -89,6 +93,7 @@ jobs:
package-pat: ${{ secrets.PACKAGE_PAT }}
lib-delivery-test:
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/${{ vars.STAGING_BRANCH }}'
needs: build
defaults:
run:
Expand All @@ -102,6 +107,7 @@ jobs:
package-pat: ${{ secrets.PACKAGE_PAT }}
lib-messaging-test:
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/${{ vars.STAGING_BRANCH }}'
needs: build
defaults:
run:
Expand All @@ -115,6 +121,7 @@ jobs:
package-pat: ${{ secrets.PACKAGE_PAT }}
lib-profile-test:
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/${{ vars.STAGING_BRANCH }}'
needs: build
defaults:
run:
Expand All @@ -128,6 +135,7 @@ jobs:
package-pat: ${{ secrets.PACKAGE_PAT }}
lib-shared-test:
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/${{ vars.STAGING_BRANCH }}'
needs: build
defaults:
run:
Expand All @@ -141,6 +149,7 @@ jobs:
package-pat: ${{ secrets.PACKAGE_PAT }}
lib-storage-test:
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/${{ vars.STAGING_BRANCH }}'
needs: build
defaults:
run:
Expand All @@ -154,6 +163,7 @@ jobs:
package-pat: ${{ secrets.PACKAGE_PAT }}
offchain-resolver-test:
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/${{ vars.STAGING_BRANCH }}'
needs: build
defaults:
run:
Expand All @@ -164,53 +174,4 @@ jobs:
uses: ./test-action
with:
workspace-name: 'dm3-offchain-resolver'
package-pat: ${{ secrets.PACKAGE_PAT }}
messenger-demo-deploy:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/new-ui'
steps:
# Check-out your repository.
- name: Checkout
uses: actions/checkout@v2
- name: Create env file
run: |
echo "REACT_APP_ADDR_ENS_SUBDOMAIN=.beta-addr.dm3.eth" >> ./packages/messenger-demo/.env
echo "REACT_APP_BACKEND=https://dm3-beta2.herokuapp.com" >> ./packages/messenger-demo/.env
echo "REACT_APP_DEFAULT_DELIVERY_SERVICE=beta-ds.dm3.eth" >> ./packages/messenger-demo/.env
echo "REACT_APP_DEFAULT_SERVICE=https://dm3-beta2.herokuapp.com" >> ./packages/messenger-demo/.env
echo "REACT_APP_ETHEREUM_PROVIDER=${{ secrets.REACT_APP_ETHEREUM_PROVIDER }}" >> ./packages/messenger-demo/.env
echo "REACT_APP_PROFILE_BASE_URL=https://dm3-beta2-resolver.herokuapp.com" >> ./packages/messenger-demo/.env
echo "REACT_APP_RESOLVER_BACKEND=https://dm3-beta2-resolver.herokuapp.com" >> ./packages/messenger-demo/.env
echo "REACT_APP_USER_ENS_SUBDOMAIN=.beta-user.dm3.eth" >> ./packages/messenger-demo/.env
echo "REACT_APP_WALLET_CONNECT_PROJECT_ID=${{ secrets.REACT_APP_WALLET_CONNECT_PROJECT_ID }}" >> ./packages/messenger-demo/.env
echo "RESOLVER_ADDR=0x45F7Ed7d05c563D408898A80d9C705CC3328D2EF" >> ./packages/messenger-demo/.env
- name: Build, Push and Release a Docker container to Heroku. # Your custom step name
uses: gonuit/[email protected] # GitHub action name (leave it as it is).
with:
# Below you must provide variables for your Heroku app.

# The email address associated with your Heroku account.
# If you don't want to use repository secrets (which is recommended) you can do:
# email: [email protected]
email: ${{ secrets.HEROKU_EMAIL }}

# Heroku API key associated with provided user's email.
# Api Key is available under your Heroku account settings.
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}

# Name of the heroku application to which the build is to be sent.
heroku_app_name: ${{ secrets.HEROKU_APP_NAME }}

# (Optional, default: "./")
# Dockerfile directory.
# For example, if you have a Dockerfile in the root of your project, leave it as follows:
dockerfile_directory: ./

# (Optional, default: "Dockerfile")
# Dockerfile name.
dockerfile_name: ./packages/messenger-demo/Dockerfile
# (Optional, default: "web")
# Select the process type for which you want the docker container to be uploaded.
# By default, this argument is set to "web".
# For more information look at https://devcenter.heroku.com/articles/process-model
process_type: web
package-pat: ${{ secrets.PACKAGE_PAT }}
7 changes: 7 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM --platform=linux/amd64 node:18-alpine
WORKDIR /app
COPY . .
RUN apk add --update python3 make g++\
&& rm -rf /var/cache/apk/*
RUN yarn install
RUN yarn build
2 changes: 2 additions & 0 deletions docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
docker build --progress=plain -t dm3-backend -f ./docker/Dockerfile .
58 changes: 58 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
version: "3.1"
services:

backend:
image: dm3org/dm3-backend:v0.2.1
command: yarn workspace dm3-backend start
depends_on:
- db
environment:
- REDIS_URL=redis://db:6379

db:
image: redis
restart: always

offchain-resolver-db:
image: postgres
restart: always
container_name: offchain_resolver_db
environment:
POSTGRES_PASSWORD: example
ports:
- '5432:5432'

offchain-resolver:
image: dm3-backend
command: yarn workspace dm3-offchain-resolver start
depends_on:
- offchain-resolver-db
environment:
DATABASE_URL: postgresql://postgres:example@offchain-resolver-db:5432
ports:
- '8082:8082'

web:
image: dm3-backend
command: yarn workspace messenger-demo start
ports:
- '${WEB_PORT}:8080'

ccip-resolver:
image: ccip-resolver
restart: always
depends_on:
- offchain-resolver
environment:
SIGNER_PRIVATE_KEY: ${SIGNER_PRIVATE_KEY}
LOG_LEVEL: debug
CONFIG: |
{
"0x5e0F81D5ca51D309B3A046FAeea70C4C70Df8079": {
"type": "signing",
"handlerUrl": "http://offchain-resolver:8081"
}
}
PORT: 8181
ports:
- '8181:8181'
10 changes: 6 additions & 4 deletions packages/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
FROM node:18-alpine
WORKDIR /app
COPY . .

RUN apk add --update python3 make g++\
&& rm -rf /var/cache/apk/*
RUN ls
RUN pwd
RUN yarn install
# RUN yarn build
CMD cd packages/backend && yarn start
EXPOSE 3000
RUN yarn build
CMD yarn workspace messenger-demo start
2 changes: 1 addition & 1 deletion packages/backend/src/persistance/getDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function getRedisClient(logger: winston.Logger) {
url,
...socketConf,
}
: {},
: { url },
);

client.on('error', (err) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/billboard-client/src/persitance/getDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function getRedisClient(logger: winston.Logger) {
url,
...socketConf,
}
: {},
: { url },
);

client.on('error', (err) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/offchain-resolver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"scripts": {
"docker:up": "docker-compose up -d",
"test": "yarn docker:up && yarn prisma:migrate && yarn mocha --require ts-node/register --extension .test.ts --recursive ./src",
"start": "yarn ts-node --transpile-only ./src/index.ts",
"start:dev": "yarn prisma:migrate && yarn ts-node --transpile-only ./src/index.ts",
"start": "yarn prisma:migrate && node ./dist",
"build": "yarn prisma generate --schema=./src/persistance/schema.prisma && yarn tsc",
"prisma:migrate": "yarn prisma migrate dev --name init --schema src/persistance/schema.prisma"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DecodedCcipRequest } from '../types';
import { decodeAddr } from './decode/decodeAddr';
import { decodeText } from './decode/decodeText';
import { getResolverInterface } from './getResolverInterface';
import { TransactionDescription } from 'ethers/lib/utils';

/**
Decodes a given calldata string and returns a DecodedCcipRequest object containing the signature and request.
Expand All @@ -14,14 +15,16 @@ export function decodeRequest(calldata: string): DecodedCcipRequest {
try {
const textResolver = getResolverInterface();

//Parse the calldata returned by a contra
const [ensName, data] = textResolver.parseTransaction({
data: calldata,
}).args;
//Parse the calldata returned by a contrat
const [ensName, data] = (
textResolver.parseTransaction({
data: calldata,
}) as TransactionDescription
).args;

const { signature, args } = textResolver.parseTransaction({
data,
});
}) as TransactionDescription;

switch (signature) {
case 'text(bytes32,string)':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,32 @@ import { ethers } from 'ethers';

export function getResolverInterface() {
return new ethers.utils.Interface([
'function resolve(bytes calldata name, bytes calldata data) external view returns(bytes)',
// eslint-disable-next-line max-len
'function resolveWithContext(bytes calldata name,bytes calldata data,bytes calldata context) external view returns (bytes memory result)',
// eslint-disable-next-line max-len
'function resolveWithProof(bytes calldata response, bytes calldata extraData) external view returns (bytes memory)',
//Text
'function text(bytes32 node, string calldata key) external view returns (string memory)',
//Address
'function addr(bytes32 node) external view returns (address)',
//ABI
// eslint-disable-next-line max-len
'function ABI(bytes calldata context,bytes32 node,uint256 contentTypes) external view returns(uint256, bytes memory)',
//ContentHash
'function contenthash(bytes calldata context, bytes32 node) external view returns (bytes memory)',
'function contenthash(bytes32 node) external view returns (bytes memory)',
//Interface
// eslint-disable-next-line max-len
'function interfaceImplementer (bytes calldata context, bytes32 node, bytes4 interfaceID) external view returns (address)',
//Name

'function name(bytes calldata context ,bytes32 node) external view returns (string memory)',
//Pubkey
'function pubkey(bytes calldata context ,bytes32 node) external view returns (bytes memory x, bytes memory y)',
//DNS
// eslint-disable-next-line max-len
'function dnsRecord(bytes calldata context,bytes32 node,bytes32 name,uint16 resource) public view returns(bytes memory)',
'function hasDNSRecords(bytes calldata context, bytes32 node, bytes32 name) public view returns (bool)',
'function zonehash(bytes calldata context, bytes32 node) external view returns (bytes memory)',
]);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import express from 'express';
import { handleAddr } from './handler/handleAddr';
import { handleText } from './handler/resolveText';
import { ethers } from 'ethers';
export async function handleCcipRequest(
req: express.Request,
signature: string,
Expand All @@ -9,7 +10,10 @@ export async function handleCcipRequest(
switch (signature) {
case 'text(bytes32,string)':
req.app.locals.logger.info('Reading text(bytes32,string)');
return await handleText(req.app.locals.db, request);
return ethers.utils.defaultAbiCoder.encode(
['string'],
[await handleText(req.app.locals.db, request)],
);
case 'addr(bytes32)':
req.app.locals.logger.info('Reading addr(bytes32))');
return await handleAddr(req.app.locals.db, request);
Expand Down
2 changes: 1 addition & 1 deletion packages/offchain-resolver/src/http/resolverEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function resolverEndpoint() {

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

0 comments on commit e9dda20

Please sign in to comment.