Skip to content

Commit

Permalink
Feat/setup (#1)
Browse files Browse the repository at this point in the history
* dev setup

* forward envs

* strict typeing

* production dockerfile updates

* update pipline
  • Loading branch information
killroy192 authored Aug 12, 2024
1 parent be55e1a commit db757d6
Show file tree
Hide file tree
Showing 25 changed files with 2,066 additions and 320 deletions.
18 changes: 18 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Dockerfile
.dockerignore
node_modules
npm-debug.log
README.md
.git
.gitignore
.linterstagedrc.json
jest.config.js
.husky
dist
.vscode
test

conf/.env
conf/.env.keys
conf/.example.secrets.env
conf/.example.env
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off"
"@typescript-eslint/no-explicit-any": "error"
}
}
23 changes: 17 additions & 6 deletions .github/workflows/quality-gate.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Quality gate
on:
push:
# branches-ignore:
# - main
branches-ignore:
- "main"

permissions:
contents: read
Expand All @@ -14,13 +14,24 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- run: make typecheck;
- run: make lint
test:
typecheck:
needs: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- name: Run unit tests
run: make test
- run: make typecheck
test:
needs: typecheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- run: make test
build:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: make build.prod;
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ lerna-debug.log*
.env.test.local
.env.production.local
.env.local
.env.keys
.local.secrets.env

# temp directory
.temp
Expand Down
17 changes: 17 additions & 0 deletions .swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"sourceMaps": true,
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true,
"dynamicImport": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
},
"baseUrl": "./"
},
"minify": false
}
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach to API",
"address": "localhost",
"port": 9229,
"localRoot": "${workspaceFolder}",
"remoteRoot": "/app",
"trace": true,
"restart": true,
"sourceMaps": true,
"skipFiles": ["<node_internals>/**"]
}
]
}
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM node:20-alpine as base
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk update && apk add --no-cache libc6-compat
WORKDIR /app
EXPOSE 3000

# Rebuild the source code only when needed
FROM base as deps
RUN apk add --no-cache make && apk add --no-cache bash
COPY . .
RUN npm ci

FROM deps as prod
ENV NODE_ENV=production
RUN make build
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 prod-nodejs
USER prod-nodejs
CMD ["make", "start.prod"]

FROM deps as dev
EXPOSE 9229
ENV NODE_ENV=development
RUN make build
CMD ["make", "start.debug.open"]
20 changes: 18 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SHELL := /bin/bash

.PHONY: init build clear lint typecheck test pre-commit pre-push migrate up up-all list funding fuel report profiles recover decrypt encrypt

all: init clean typecheck test
all: init clean typecheck

init:; npm i

Expand All @@ -22,7 +22,7 @@ test.cov :; npx jest --passWithNoTests --coverage

test.debug :; node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand

test.e2e: npx jest --config ./test/jest-e2e.json
test.e2e:; npx jest --config ./test/jest-e2e.json

pre-commit: typecheck lint-stg

Expand All @@ -38,6 +38,22 @@ start.dev:; npx nest start --watch

start.debug:; npx nest start --debug --watch

start.debug.open:; npx nest start --debug 0.0.0.0 --watch

start.prod:; node dist/main

# docker aliases

up.dev:
@docker compose up -d && docker compose logs -f

build.prod:
@docker compose -f docker-compose.prod.yml build

up.prod:
@docker compose -f docker-compose.prod.yml up -d && docker compose -f docker-compose.prod.yml logs -f

clear.prod:
@docker compose -f docker-compose.prod.yml down

-include ${FCT_PLUGIN_PATH}/makefile-external
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
# web3-glue

Development starter kit for web3 node.js apps with nestjs & viem

## Installation

```bash
npm install
make
```

## Running the app

```bash
# development
$ npm run start
$ make start

# watch mode
$ npm run start:dev
$ make start.dev

# production mode
$ npm run start:prod
$ make start.prod
```

## Test

```bash
# unit tests
$ npm run test
$ make test

# e2e tests
$ npm run test:e2e
$ make test.e2e

# test coverage
$ npm run test:cov
$ make test.cov
```

## License
Expand Down
2 changes: 2 additions & 0 deletions conf/.example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://viem.sh/docs/chains/introduction
NETWORK="mainnet"
3 changes: 3 additions & 0 deletions conf/.example.secrets.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NODE_PK="0x0000000000000000000000000000000000000000000000000000000000000000"
RPC="https://ethereum.publicnode.com"
WS_RPC="wss://ethereum.publicnode.com"
Empty file added conf/.production.secrets.env
Empty file.
17 changes: 17 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3.7'

services:
nest-app-prod:
hostname: nest-app-prod
image: nest-app-prod
restart: always
build:
context: .
target: prod
ports:
- 3000:${EXPOSE_PORT:-80}
logging:
driver: "json-file"
options:
max-file: "5"
max-size: "100m"
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3.7'

services:
nest-app-develop:
hostname: nest-app-develop
image: nest-app-develop
restart: always
build:
context: .
target: dev
ports:
- 3000:3000
- 9229:9229
volumes:
- ./src:/app/src:cached
3 changes: 2 additions & 1 deletion nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true
"deleteOutDir": true,
"builder": "swc"
}
}
Loading

0 comments on commit db757d6

Please sign in to comment.