Skip to content

Commit

Permalink
xx
Browse files Browse the repository at this point in the history
  • Loading branch information
killroy192 committed Aug 10, 2024
1 parent a967608 commit 4813572
Show file tree
Hide file tree
Showing 16 changed files with 5,374 additions and 10,008 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ README.md
.linterstagedrc.json
jest.config.js
.env.example
.husky
Empty file added .env.production
Empty file.
57 changes: 57 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"env": {
"mocha": true,
"node": true,
"jest": true,
},

"globals": {
"BufferEncoding": "readonly",
},

"root": true,

"plugins": ["@typescript-eslint", "json", "promise", "import", "prettier"],

"extends": [
"eslint:recommended",
"plugin:node/recommended",
"plugin:json/recommended",
"plugin:promise/recommended",
"plugin:import/typescript",
"prettier",
],

"settings": {
"import/resolver": {
"typescript": true,
"node": true,
},
"import/parsers": {
"@typescript-eslint/parser": [".ts"],
},
},

"parser": "@typescript-eslint/parser",

"rules": {
"node/no-missing-import": "off",
"node/no-unpublished-import": "off",
"prettier/prettier": "warn",
"import/order": [
"warn",
{
"alphabetize": {
"order": "asc",
"caseInsensitive": true,
},
},
],
"sort-vars": ["warn", { "ignoreCase": true }],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"import/no-unresolved": "error",
},

"ignorePatterns": ["dist", "**/*.d.ts"],
}
53 changes: 0 additions & 53 deletions .eslintrc.js

This file was deleted.

6 changes: 1 addition & 5 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run typecheck;
npx lint-staged;
make pre-commit
7 changes: 1 addition & 6 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run lint;
npm run typecheck;
npm run test;
make pre-push
25 changes: 9 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
# Install dependencies only when needed
FROM node:18-alpine AS deps
FROM node:20-alpine AS deps

# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app

# Install dependencies
COPY package.json package-lock.json* ./
RUN npm ci
RUN npm ci --legacy-peer-deps

# Rebuild the source code only when needed
FROM node:18-alpine AS builder
FROM node:20-alpine
RUN apk update && apk add --no-cache make && apk add --no-cache bash
WORKDIR /app
COPY . .
COPY --from=deps /app/node_modules ./node_modules

ENV NODE_ENV production
RUN npm run build

# Run code from build with proper user
FROM node:18-alpine
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY --from=builder /app/dist ./

ENV NODE_ENV production
ARG NODE_ENV
ENV NODE_ENV=${NODE_ENV}

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 automation-nodejs
RUN adduser --system --uid 1001 prod-nodejs

USER automation-nodejs
USER prod-nodejs

CMD ["node", "index.js"]
CMD ["make", "prod"]
57 changes: 57 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
SHELL := /bin/bash

.PHONY: init typecheck lint lint-stg test pre-commit pre-push builddev updev watch stopdev cleandev buildprod upprod cleanprod dev prod

all: init typecheck test

init:
@npm i --legacy-peer-deps

typecheck:
@npx tsc --project tsconfig.json

lint:
@npx eslint src/**/*.ts

lint-stg:
@npx lint-staged

test:
@npx jest --passWithNoTests

pre-commit: typecheck lint-stg

pre-push: lint typecheck test

# docker aliases

builddev:
@docker compose build

updev:
@docker compose up -d && docker compose logs -f

watch:
@docker compose up -d --watch && docker compose logs -f

stopdev:
@docker compose stop

cleandev:
@docker compose down

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

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

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

# shortcuts for docker
prod :
@npx tsx src

dev:
@npx dotenvx run -- tsx --watch src
19 changes: 19 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: "3.7"

services:
automation-node-prod:
hostname: automation-node-prod
image: automation-node-prod
restart: always
build:
context: .
args:
- NODE_ENV=production
logging:
driver: "json-file"
options:
max-file: "5"
max-size: "100m"
secrets:
master_key:
file: .env.keys
27 changes: 14 additions & 13 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
version: "3.7"

services:
automation-node:
hostname: automation-node
image: automation-node
automation-node-develop:
hostname: automation-node-develop
image: automation-node-develop
restart: always
build:
context: .
logging:
driver: "json-file"
options:
max-file: "5"
max-size: "100m"
environment:
- NODE_PK=${NODE_PK}
- RPC=${RPC}
- WS_RPC=${WS_RPC}
- NETWORK=${NETWORK}
args:
- NODE_ENV=develop
command: ["make", "dev"]
develop:
watch:
# sync static content
- path: ./src
action: sync
target: /app
ignore:
- node_modules/
6 changes: 0 additions & 6 deletions jest.config.js

This file was deleted.

15 changes: 15 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"testPathIgnorePatterns": ["dist"],
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.js$": "$1"
},
"extensionsToTreatAsEsm": [".ts"],
"transform": {
"^.+\\.(mt|t|cj|j)s$": [
"ts-jest",
{
"useESM": true
}
]
}
}
Loading

0 comments on commit 4813572

Please sign in to comment.