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

feat: local setup via docker-compose #3030

Merged
merged 6 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 24 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Common file for apps that rely on root context
.git
.github
.husky
audits
docs
scripts
**/node_modules
**/build
**/dist

# Core package artifacts
# Hardhat files
**/abis
**/artifacts
**/cache
**/.deps
# TypeScript bindings output directory
**/typechain-types

# Docker-related
.dockerignore
**/Dockerfile*
**/docker-compose*
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ node_modules

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
.env.*.local

# Log files
npm-debug.log*
Expand Down
2 changes: 0 additions & 2 deletions packages/apps/human-app/frontend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ VITE_HUMAN_PROTOCOL_HELP_URL= #string
VITE_HUMAN_SUPPORT_EMAIL= #string
# link to human web page
VITE_HUMAN_PROTOCOL_URL= #string
# link to "Learn more" in wallet connect modal
VITE_WALLET_CONNECT_MODAL_LINK= #string
# link to human web page in main page navbar
VITE_NAVBAR__LINK__PROTOCOL_URL= #string
# link to human web page section in main page navbar
Expand Down
28 changes: 28 additions & 0 deletions packages/apps/human-app/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Using bullseye instead of slim because it needs Python and build tools for node-gyp
FROM node:18-bullseye
ARG APP_PATH=packages/apps/human-app/frontend

# Create app directory
WORKDIR /usr/src/app

# Copy expected yarn dist
COPY .yarn ./.yarn
COPY .yarnrc ./
# Copy files for deps installation
COPY package.json yarn.lock ./
COPY ${APP_PATH}/package.json ./${APP_PATH}/package.json
# Some deps are referenced as "*", so we need to build them
COPY tsconfig.json ./
COPY packages/core ./packages/core
COPY packages/sdk ./packages/sdk

RUN yarn install

# Copy everything else to ensure proper build process
COPY . .

WORKDIR ./${APP_PATH}
RUN yarn build

# Start the server using the build
CMD [ "yarn", "start:prod" ]
4 changes: 3 additions & 1 deletion packages/apps/human-app/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@human-protocol/sdk": "*",
"@mui/icons-material": "^6.2.0",
"@mui/material": "^5.16.7",
"@mui/x-date-pickers": "^7.23.6",
"@reown/appkit": "1.3.2",
"@reown/appkit-adapter-wagmi": "1.3.2",
"@synaps-io/verify-sdk": "^4.0.45",
Expand All @@ -32,7 +33,7 @@
"i18next": "^23.8.2",
"jwt-decode": "^4.0.0",
"lodash": "^4.17.21",
"material-react-table": "^3.0.1",
"material-react-table": "3.0.1",
"mui-image": "^1.0.7",
"notistack": "^3.0.1",
"query-string": "^9.0.0",
Expand All @@ -43,6 +44,7 @@
"react-imask": "^7.4.0",
"react-number-format": "^5.4.3",
"react-router-dom": "^6.22.0",
"serve": "^14.2.4",
"viem": "^2.21.44",
"vite-plugin-svgr": "^4.2.0",
"wagmi": "2.14.6",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { t } from 'i18next';
import { Grid, Typography } from '@mui/material';
import { Trans } from 'react-i18next';
import { Link } from 'react-router-dom';
import { useEffect } from 'react';
import { Button } from '@/shared/components/ui/button';
import { ConnectWalletBtn } from '@/shared/components/ui/connect-wallet-btn';
import { useModalStore } from '@/shared/components/ui/modal/modal.store';
import { env } from '@/shared/env';
import { useWalletConnect } from '@/shared/hooks/use-wallet-connect';

export function WalletConnectModal() {
Expand Down Expand Up @@ -46,21 +44,7 @@ export function WalletConnectModal() {
}}
>
<Typography variant="body1">
<Trans
components={{
1: (
<Link
rel="noreferrer"
style={{
color: 'inherit',
}}
target="_blank"
to={env.VITE_WALLET_CONNECT_MODAL_LINK}
/>
),
}}
i18nKey="walletConnectModal.paragraph"
/>
<Trans i18nKey="walletConnectModal.paragraph" />
</Typography>
<ConnectWalletBtn fullWidth>
{t('walletConnectModal.connectBtn')}
Expand Down
2 changes: 0 additions & 2 deletions packages/apps/human-app/frontend/src/shared/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const envSchema = z.object({
VITE_NAVBAR__LINK__HOW_IT_WORK_URL: z.string(),
VITE_HUMAN_SUPPORT_EMAIL: z.string(),
VITE_HUMAN_PROTOCOL_HELP_URL: z.string(),
VITE_WALLET_CONNECT_MODAL_LINK: z.string(),
VITE_H_CAPTCHA_SITE_KEY: z.string(),
VITE_HMT_DAILY_SPENT_LIMIT: z
.string()
Expand Down Expand Up @@ -59,7 +58,6 @@ try {
validEnvs = envSchema.parse(import.meta.env);
} catch (error) {
if (error instanceof ZodError) {
console.error('Invalid .env file');
error.issues.forEach((issue) => {
console.error('Invalid env:', issue.path.join());
console.error(issue);
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/human-app/frontend/src/shared/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@
},
"walletConnectModal": {
"header": "Connect Wallet",
"paragraph": "HUMAN App is a multichain platform, please provide a wallet address which will be compatible with different chains. <1>Learn more or FAQ link.</1>",
"paragraph": "HUMAN App is a multichain platform, please provide a wallet address which will be compatible with different chains.",
"connectBtn": "Connect Wallet",
"cancelBtn": "Cancel"
},
Expand Down
5 changes: 0 additions & 5 deletions packages/apps/human-app/server/.dockerignore

This file was deleted.

28 changes: 19 additions & 9 deletions packages/apps/human-app/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
# Base image
FROM node:18
FROM node:18-slim
ARG APP_PATH=packages/apps/human-app/server

# Create app directory
WORKDIR /usr/src/app

# Bundle app source
COPY . .
# Copy expected yarn dist
COPY .yarn ./.yarn
COPY .yarnrc ./
# Copy files for deps installation
COPY package.json yarn.lock ./
COPY ${APP_PATH}/package.json ./${APP_PATH}/package.json
# Some deps are referenced as "*", so we need to build them
COPY tsconfig.json ./
COPY packages/core ./packages/core
COPY packages/sdk ./packages/sdk

# Install app dependencies
RUN yarn install

# Creates a "dist" folder with the production build
RUN yarn workspace @human-protocol/human-app-server build
# Copy everything else to ensure proper build process
COPY . .

WORKDIR ./${APP_PATH}
RUN yarn build

# Start the server using the production build
CMD [ "node", "packages/apps/human-app/server/dist/src/main.js" ]
# Start the server using the build
CMD [ "yarn", "start:prod" ]
7 changes: 7 additions & 0 deletions packages/apps/human-app/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"@nestjs/common": "^10.2.7",
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.3.10",
"@nestjs/platform-express": "^10.3.10",
"@nestjs/schedule": "^4.0.1",
"@nestjs/swagger": "^7.4.2",
"@nestjs/terminus": "^10.2.3",
"cache-manager": "^5.4.0",
Expand All @@ -38,7 +40,10 @@
"class-validator": "^0.14.1",
"ethers": "^6.12.1",
"joi": "^17.13.3",
"jsonwebtoken": "^9.0.2",
"jwt-decode": "^4.0.0",
"lodash": "^4.17.21",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.2.0"
},
"devDependencies": {
Expand All @@ -47,6 +52,8 @@
"@nestjs/testing": "^10.4.6",
"@types/express": "^4.17.13",
"@types/jest": "29.5.12",
"@types/jsonwebtoken": "^9.0.7",
"@types/lodash": "^4.17.14",
"@types/node": "22.10.5",
"@types/supertest": "^2.0.15",
"@typescript-eslint/eslint-plugin": "^5.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/apps/human-app/server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const JOI_BOOLEAN_STRING_SCHEMA = Joi.string().valid('true', 'false');
REPUTATION_ORACLE_ADDRESS: Joi.string().required(),
REDIS_PORT: Joi.number().required(),
REDIS_HOST: Joi.string().required(),
REDIS_DB: Joi.number(),
RPC_URL: Joi.string().required(),
HCAPTCHA_LABELING_STATS_API_URL: Joi.string().required(),
HCAPTCHA_LABELING_VERIFY_API_URL: Joi.string().required(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const CacheFactoryConfig: CacheModuleAsyncOptions = {
host: configService.cacheHost,
port: configService.cachePort,
},
database: configService.cacheDbNumber,
disableOfflineQueue: true,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ export class EnvironmentConfigService {
return this.configService.getOrThrow<string>('REDIS_HOST');
}

/**
* The DB number of the Redis cache server
*/
get cacheDbNumber(): number {
return this.configService.get<number>('REDIS_DB', 0);
}

/**
* The cache time-to-live (TTL) for oracle statistics.
* Default: 12 hours
Expand Down
28 changes: 28 additions & 0 deletions packages/apps/job-launcher/client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Using bullseye instead of slim because it needs Python and build tools for node-gyp
FROM node:18-bullseye
ARG APP_PATH=packages/apps/job-launcher/client

# Create app directory
WORKDIR /usr/src/app

# Copy expected yarn dist
COPY .yarn ./.yarn
COPY .yarnrc ./
# Copy files for deps installation
COPY package.json yarn.lock ./
COPY ${APP_PATH}/package.json ./${APP_PATH}/package.json
# Some deps are referenced as "*", so we need to build them
COPY tsconfig.json ./
COPY packages/core ./packages/core
COPY packages/sdk ./packages/sdk

RUN yarn install

# Copy everything else to ensure proper build process
COPY . .

WORKDIR ./${APP_PATH}
RUN yarn build

# Start the server using the build
CMD [ "yarn", "start:prod" ]
3 changes: 0 additions & 3 deletions packages/apps/job-launcher/server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,3 @@ STRIPE_APP_INFO_URL=

# Sendgrid
SENDGRID_API_KEY=

# Cron Job Secret
CRON_SECRET="cron-secret"
28 changes: 19 additions & 9 deletions packages/apps/job-launcher/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
# Base image
FROM node:18
FROM node:18-slim
ARG APP_PATH=packages/apps/job-launcher/server

# Create app directory
WORKDIR /usr/src/app

# Bundle app source
COPY . .
# Copy expected yarn dist
COPY .yarn ./.yarn
COPY .yarnrc ./
# Copy files for deps installation
COPY package.json yarn.lock ./
COPY ${APP_PATH}/package.json ./${APP_PATH}/package.json
# Some deps are referenced as "*", so we need to build them
COPY tsconfig.json ./
COPY packages/core ./packages/core
COPY packages/sdk ./packages/sdk

# Install app dependencies
RUN yarn install

# Creates a "dist" folder with the production build
RUN yarn workspace @human-protocol/job-launcher-server build
# Copy everything else to ensure proper build process
COPY . .

WORKDIR ./${APP_PATH}
RUN yarn build

# Start the server using the production build
CMD [ "node", "packages/apps/job-launcher/server/dist/src/main.js" ]
# Start the server using the build
CMD [ "yarn", "start:prod" ]
5 changes: 5 additions & 0 deletions packages/apps/job-launcher/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,22 @@
"@nestjs/core": "^10.3.10",
"@nestjs/jwt": "^10.2.0",
"@nestjs/passport": "^10.0.0",
"@nestjs/platform-express": "^10.3.10",
"@nestjs/schedule": "^4.0.1",
"@nestjs/serve-static": "^4.0.1",
"@nestjs/swagger": "^7.4.2",
"@nestjs/terminus": "^10.2.1",
"@nestjs/typeorm": "^10.0.1",
"@sendgrid/mail": "^8.1.3",
"@types/passport-jwt": "^4.0.1",
"@types/uuid": "^10.0.0",
"async-mutex": "^0.5.0",
"bcrypt": "^5.1.1",
"body-parser": "^1.20.3",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"decimal.js": "^10.4.3",
"helmet": "^7.1.0",
"joi": "^17.13.3",
"json-stable-stringify": "^1.1.1",
"nestjs-minio-client": "^2.2.0",
Expand Down
Loading