Skip to content

Commit

Permalink
🪢 Merge backend and RWD into dev (Joystream#4634)
Browse files Browse the repository at this point in the history
  • Loading branch information
thesan authored Nov 20, 2023
2 parents 5e0385d + 65ae16b commit 437f2f0
Show file tree
Hide file tree
Showing 287 changed files with 17,140 additions and 2,418 deletions.
38 changes: 29 additions & 9 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
"plugin:import/warnings",
"plugin:import/typescript"
],
"plugins": ["import", "react-hooks"],
"ignorePatterns": [".eslintrc.js"],
"plugins": [
"import"
],
"ignorePatterns": [
".eslintrc.js",
"index.html"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
Expand Down Expand Up @@ -41,12 +46,22 @@
"import/order": [
"error",
{
"groups": ["builtin", "external", "parent", ["index", "sibling"]],
"groups": [
"builtin",
"external",
"parent",
[
"index",
"sibling"
]
],
"pathGroups": [
{ "pattern": "@test/**", "position": "after", "group": "builtin" },
{ "pattern": "@/**", "position": "after", "group": "external" }
],
"pathGroupsExcludedImportTypes": ["builtin"],
"pathGroupsExcludedImportTypes": [
"builtin"
],
"newlines-between": "always",
"alphabetize": {
"order": "asc",
Expand All @@ -59,25 +74,30 @@
{
"noUselessIndex": true
}
],
"react-hooks/rules-of-hooks": "error"
]
},
"overrides": [
{
"files": ["test/**/*.{js,ts,tsx}"],
"files": [
"test/**/*.{js,ts,tsx}"
],
"rules": {
"@typescript-eslint/no-non-null-assertion": "off",
"no-unused-expressions": "off"
}
},
{
"files": ["**/__generated__/**/*.{js,ts,tsx}"],
"files": [
"**/__generated__/**/*.{js,ts,tsx}"
],
"rules": {
"import/order": "off"
}
},
{
"files": ["src/common/logger/*.ts"],
"files": [
"src/common/logger/*.ts"
],
"rules": {
"no-console": "off"
}
Expand Down
69 changes: 61 additions & 8 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@ jobs:
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT

- uses: actions/cache@v3
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- if: ${{ steps.yarn-cache.outputs.cache-hit != 'true' }}
name: Install dependencies
- name: Install dependencies
run: yarn --immutable

- name: Verify formatting
run: yarn lint

ui-unit-tests:
needs: install
timeout-minutes: 60
Expand Down Expand Up @@ -62,15 +63,13 @@ jobs:
- name: Install dependencies
run: yarn --immutable

- name: Verify linting
run: yarn lint

- name: Build Pioneer
working-directory: packages/ui
run: yarn build

- name: Run tests
run: node --max_old_space_size=7000 --expose-gc $(yarn bin jest) --logHeapUsage --silent
working-directory: packages/ui
run: node --max_old_space_size=7000 --expose-gc $(yarn bin jest) --logHeapUsage --silent

interaction-tests:
needs: install
Expand Down Expand Up @@ -149,6 +148,60 @@ jobs:
COMMIT_SHA: ${{ github.event.pull_request.head.sha || github.sha }}

- name: Run Storybook tests
run: yarn workspace @joystream/pioneer test-storybook
working-directory: packages/ui
run: yarn test-storybook
env:
TARGET_URL: https://${{ env.VERCEL_DEPLOYMENT_URL }}

backend-integration-tests:
needs: install
timeout-minutes: 60
strategy:
matrix: { node: ["18.x"], os: [ubuntu-latest] }
runs-on: ${{ matrix.os }}

services:
db:
image: postgres
env: { POSTGRES_PASSWORD: "postgres" }
ports: ["5432:5432"]
# Set health checks to wait until Postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT

- uses: actions/cache@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn --immutable

- name: Build
working-directory: packages/server
run: yarn build
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres

- name: Run tests
working-directory: packages/server
run: yarn test --silent
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres
48 changes: 48 additions & 0 deletions backend.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
FROM node:20 AS base
WORKDIR /app

RUN set -eux; \
apt-get update -y; \
apt-get install -y --no-install-recommends openssl; \
rm -rf /var/lib/apt/list/*

FROM base AS builder

COPY packages/server/package.json ./
COPY yarn.lock ./
RUN yarn --immutable

COPY tsconfig.json ./base.tsconfig.json
COPY packages/server/tsconfig.json ./
RUN sed -i 's/"extends":.*/"extends": ".\/base.tsconfig.json",/' tsconfig.json

COPY packages/server/prisma ./
COPY packages/server/codegen.ts ./
COPY packages/server/src ./src
RUN yarn build:local

RUN rm -rf node_modules
ENV NODE_ENV=production
RUN yarn --prod --immutable
RUN yarn prisma generate

FROM base

USER www-data

COPY --from=builder --chown=www-data /app/dist ./dist
COPY --from=builder --chown=www-data /app/node_modules ./node_modules
COPY packages/server/prisma ./prisma
COPY packages/server/docker/prod/entrypoint.sh /entrypoint.sh
COPY packages/server/docker/prod/notify.sh /usr/bin/notify

ENV QUERY_NODE_ENDPOINT "https://query.joystream.org/graphql"
ENV PIONEER_URL "https://pioneerapp.xyz"
ENV STARTING_BLOCK 1
ENV NODE_ENV=production
ENV APP_LOG_LEVEL "verbose"
ENV PORT 3000
EXPOSE 3000/tcp

ENTRYPOINT ["/entrypoint.sh"]
CMD ["api"]
42 changes: 42 additions & 0 deletions backend.dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
FROM node:18-alpine3.18 AS builder
WORKDIR /app

COPY packages/server/package.json ./
COPY yarn.lock ./
RUN yarn --immutable

COPY tsconfig.json ./base.tsconfig.json
COPY packages/server/tsconfig.json ./
RUN sed -i 's/"extends":.*/"extends": ".\/base.tsconfig.json",/' tsconfig.json

COPY packages/server/prisma ./
COPY packages/server/codegen.ts ./
COPY packages/server/src ./src
RUN yarn build:local

RUN rm -rf node_modules
ENV NODE_ENV=production
RUN yarn --prod --immutable
RUN yarn prisma generate

FROM postgres:16.0-alpine3.18
WORKDIR /app
RUN apk add --no-cache nodejs

COPY --from=builder --chown=postgres /app/dist ./dist
COPY --from=builder --chown=postgres /app/node_modules ./node_modules
COPY packages/server/prisma ./prisma
COPY packages/server/docker/dev/entrypoint.sh /entrypoint.sh
COPY packages/server/docker/dev/notify.sh /usr/bin/notify
COPY packages/server/docker/dev/env.sh ./
COPY packages/server/docker/dev/prisma-deploy.sh /docker-entrypoint-initdb.d/

ENV QUERY_NODE_ENDPOINT "https://query.joystream.org/graphql"
ENV PIONEER_URL "https://pioneerapp.xyz"
ENV STARTING_BLOCK 1
ENV APP_LOG_LEVEL "verbose"
ENV PORT 3000
EXPOSE 3000/tcp

ENTRYPOINT ["/entrypoint.sh"]
CMD ["api"]
18 changes: 8 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,20 @@
]
},
"scripts": {
"lint": "wsrun --package @joystream/pioneer -c lint",
"lint:fix": "wsrun --package @joystream/pioneer -c lint:fix",
"build": "wsrun --fast-exit --stages -c --exclude @joystream/markdown-editor build",
"build:storybook": "wsrun --fast-exit --stages -c --exclude @joystream/pioneer --exclude-missing build && wsrun --package @joystream/pioneer -c build:storybook",
"lint": "wsrun -x @joystream/markdown-editor -c lint",
"lint:fix": "wsrun -x @joystream/markdown-editor -c lint:fix",
"build": "wsrun --fast-exit --package @joystream/pioneer -c build",
"build:storybook": "wsrun --fast-exit --stages -p @joystream/markdown-editor -c build && wsrun -p @joystream/pioneer -c build:storybook",
"storybook": "wsrun --exclude-missing -c storybook",
"test": "wsrun --fast-exit --package @joystream/pioneer -c test",
"test": "wsrun --fast-exit --exclude-missing -c test",
"test-storybook": "wsrun --package @joystream/pioneer -c test-storybook",
"start": "wsrun --package @joystream/pioneer -c start",
"prepare": "husky install"
},
"dependencies": {
"eslint-plugin-import": "^2.23.4",
"wsrun": "^5.2.4"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.50.0",
"@typescript-eslint/parser": "^5.50.0",
"husky": ">=6",
"lint-staged": ">=10"
},
Expand All @@ -52,11 +50,11 @@
"@joystream/[email protected]": "patch:@joystream/js@npm%3A1.2.0#./.yarn/patches/@joystream-js-npm-1.2.0-a8795e7496.patch"
},
"engines": {
"node": ">=14.18.0",
"node": ">=18",
"yarn": "^1.22.0"
},
"lint-staged": {
"packages/ui/src/**/*.{js,ts,tsx,html}": [
"packages/{ui,server}/src/**/*.{js,ts,tsx,html}": [
"eslint --fix",
"prettier --write"
]
Expand Down
64 changes: 64 additions & 0 deletions packages/server/.env.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#
# Database
#

POSTGRES_DB: "pioneer"
POSTGRES_USER: "pioneer"
POSTGRES_PASSWORD: "pioneer"

# Use a non standard port to not interfere with the local Joystream mono-repo `db` service.
DB_PORT: 5433

# URL Prisma uses to connect to the database (this value is not used when runing the api from the docker compose file).
DATABASE_URL: "postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:${DB_PORT}/${POSTGRES_DB}"

#
# Joystream environment
#

# Query node to fetch from:
# - http://localhost:8081/graphql to connect to a query node running locally.
# - http://graphql-server:8081/graphql to connect to the Joystream mono-repo docker service from its network.
# - https://query.joystream.org/graphql to connect to the Joystream's mainnet query node.
QUERY_NODE_ENDPOINT: "https://query.joystream.org/graphql"

# Pioneer instance to link to in the notification (Use "http://localhost:8080" for the local instance).
PIONEER_URL: "https://pioneerapp.xyz"

# Block to start fetching the events from.
STARTING_BLOCK: 1

#
# General
#

# Port to run the api on.
PORT: 3000

# The key used to to sign JSON Web Token with.
APP_SECRET_KEY: "SECRET_1234"

# Log level.
APP_LOG_LEVEL: "verbose"

NODE_ENV: "development"

#
# Email
#

# EMAIL_SENDER: "[email protected]"

# Only one of the api provider should be defined
# SENDGRID_API_KEY: "SG.1234567890qwerty"

# MAILGUN_API_KEY: "qwerty12345"
# MAILGUN_DOMAIN: "example.com"
# MAILGUN_API_URL: "https://api.eu.mailgun.net" # this is needed for EU domains

#
# For development only:
#

# Create default members (their tokens will be displayed when the server start).
INITIAL_MEMBERSHIPS: '[{ "id": 1, "name": "Alice", "email": "[email protected]" }, { "id": 2, "name": "Bob", "email": "[email protected]" }]'
1 change: 1 addition & 0 deletions packages/server/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/__generated__
8 changes: 8 additions & 0 deletions packages/server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
__generated__
dist

# Keep environment variables out of version control
.env

.react-email
1 change: 1 addition & 0 deletions packages/server/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/__generated__
6 changes: 6 additions & 0 deletions packages/server/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"semi": false,
"singleQuote": true,
"printWidth": 120,
"bracketSpacing": true
}
Loading

0 comments on commit 437f2f0

Please sign in to comment.