Skip to content

Commit a63f882

Browse files
authored
Merge pull request #29 from fullstack-development/repository-refactor
Repository refactor
2 parents 3990ea6 + 31c62d3 commit a63f882

File tree

96 files changed

+10584
-5958
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+10584
-5958
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
**/node_modules
2+
**/dist
3+
**/build
4+
api/.prisma-lib

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
node_modules/
22

33
.vscode
4+
yarn-error.log
5+
.env
6+
.e2e.env

Dockerfile.api

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,46 @@
1-
FROM node:14-alpine as deps
1+
# REPOSITORY DEPENDENCIES
2+
FROM node:18.12-alpine as repository_deps
23
RUN apk add --no-cache libc6-compat
4+
5+
WORKDIR /app
6+
COPY ./libs/repository ./
7+
8+
RUN yarn install --frozen-lockfile
9+
RUN yarn prisma:generate
10+
# ------------
11+
12+
# API DEPENDENCIES
13+
FROM node:18.12-alpine as api_deps
14+
RUN apk add --no-cache libc6-compat
15+
316
WORKDIR /app
417
COPY ./api/yarn.lock ./api/package.json ./
5-
COPY ./schema.prisma ./src/schema.prisma
6-
RUN yarn install --ignore-scripts --frozen-lockfile --silent
7-
RUN npx prisma generate --schema="./src/schema.prisma"
818

9-
FROM node:14-alpine as builder
19+
RUN yarn install --frozen-lockfile
20+
# ------------
21+
22+
# BUILD API
23+
FROM node:18.12-alpine as api
1024
WORKDIR /app
11-
COPY --from=deps /app/node_modules ./node_modules
12-
COPY ./api .
13-
COPY ./schema.prisma ./src/schema.prisma
14-
RUN yarn build
1525

16-
FROM node:14-alpine as runner
26+
COPY --from=api_deps /app/node_modules ./api/node_modules
27+
COPY --from=repository_deps /app ./libs/repository
28+
29+
COPY ./api ./api
30+
31+
RUN cd ./api && yarn build
32+
# ------------
33+
34+
FROM node:18.12-alpine as main
35+
1736
WORKDIR /app
37+
1838
RUN addgroup -g 1001 -S nodejs
1939
RUN adduser -S nestjs -u 1001
2040

21-
COPY --from=builder --chown=nestjs:nodejs /app/dist ./dist
22-
COPY --from=builder --chown=nestjs:nodejs /app/node_modules ./node_modules
23-
COPY --from=builder --chown=nestjs:nodejs /app/src/swagger.yaml ./src/swagger.yaml
41+
COPY --from=api --chown=nestjs:nodejs /app/api/dist ./dist
42+
COPY --from=api --chown=nestjs:nodejs /app/api/node_modules ./node_modules
43+
COPY --from=api --chown=nestjs:nodejs /app/api/src/swagger.yaml ./src/swagger.yaml
2444

2545
ENV DB_ADDRESS=$DB_ADDRESS
2646
ENV DB_USER=$DB_USER
@@ -38,4 +58,4 @@ USER nestjs
3858

3959
EXPOSE 3000
4060

41-
CMD ["sh", "-c", "ENVIRONMENT=$ENVIRONMENT DB_ADDRESS=$DB_ADDRESS DB_USER=$DB_USER DB_PASSWORD=$DB_PASSWORD DB_NAME=$DB_NAME DB_PORT=$DB_PORT JWT_SECRET=$JWT_SECRET JWT_EXPIRES_IN=$JWT_EXPIRES_IN PORT_API=$PORT_API JWT_REFRESH_TOKEN_SECRET=$JWT_REFRESH_TOKEN_SECRET JWT_REFRESH_TOKEN_EXPIRATION_TIME=$JWT_REFRESH_TOKEN_EXPIRATION_TIME NODE_ENV=production node dist/src/main"]
61+
CMD ["sh", "-c", "ENVIRONMENT=$ENVIRONMENT DB_ADDRESS=$DB_ADDRESS DB_USER=$DB_USER DB_PASSWORD=$DB_PASSWORD DB_NAME=$DB_NAME DB_PORT=$DB_PORT JWT_SECRET=$JWT_SECRET JWT_EXPIRES_IN=$JWT_EXPIRES_IN PORT_API=$PORT_API JWT_REFRESH_TOKEN_SECRET=$JWT_REFRESH_TOKEN_SECRET JWT_REFRESH_TOKEN_EXPIRATION_TIME=$JWT_REFRESH_TOKEN_EXPIRATION_TIME NODE_ENV=production node dist/main"]

api/.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = {
1414
rules: {
1515
'max-len': [
1616
'error',
17-
110,
17+
100,
1818
{
1919
ignorePattern: '^import\\s.+\\sfrom\\s.+;$',
2020
ignoreUrls: true,

api/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ coverage
3434
src/schema.prisma
3535
env/dev.env
3636
env/dev.docker.env
37+
38+
.prisma-lib

api/.prettierrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = {
88
trailingComma: 'all',
99
useTabs: false,
1010
endOfLine: 'lf',
11+
organizeImportsSkipDestructiveCodeActions: true,
1112
overrides: [
1213
{
1314
files: '*.json',

api/Dockerfile_test

Lines changed: 0 additions & 27 deletions
This file was deleted.

api/buildPrepare.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const root = path.resolve(__dirname);
5+
const dist = path.resolve(__dirname, 'dist');
6+
const enginesDir = path.resolve(__dirname, '../libs/repository/node_modules/@prisma/engines');
7+
8+
if (!fs.existsSync(dist)) {
9+
fs.mkdirSync(dist);
10+
}
11+
12+
fs.copyFileSync(
13+
path.resolve(root, '../libs/repository/schema.prisma'),
14+
path.resolve(dist, 'schema.prisma'),
15+
);
16+
17+
let engine = getEngine();
18+
if (!engine) {
19+
throw `Cannot find engine for '${process.platform}'`;
20+
}
21+
22+
const engineFile = path.resolve(enginesDir, engine);
23+
fs.copyFileSync(engineFile, path.resolve(dist, engine));
24+
25+
function getEngine() {
26+
const libConfigFile = path.resolve(__dirname, '.prisma-lib');
27+
28+
if (fs.existsSync(libConfigFile)) {
29+
return JSON.parse(fs.readFileSync(libConfigFile)).lib;
30+
}
31+
32+
const files = fs.readdirSync(enginesDir);
33+
const findEngine = (regexp) =>
34+
files.find(
35+
(f) => !fs.statSync(path.resolve(enginesDir, f)).isDirectory() && regexp.test(f),
36+
);
37+
38+
let engine = null;
39+
switch (process.platform) {
40+
case 'linux':
41+
engine = findEngine(new RegExp(/.*\.so\.node$/gi));
42+
break;
43+
case 'win32':
44+
engine = findEngine(new RegExp(/.*\.dll\.node$/gi));
45+
break;
46+
}
47+
48+
if (engine !== null) {
49+
fs.writeFileSync(libConfigFile, JSON.stringify({ lib: engine }));
50+
}
51+
52+
return engine;
53+
}

api/env/dev.example.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ JWT_REFRESH_TOKEN_SECRET=secret_refresh_key
99
JWT_REFRESH_TOKEN_EXPIRATION_TIME="2 days"
1010
PORT_API=3000
1111
DATABASE_URL=postgres://$DB_USER:$DB_PASSWORD@$DB_ADDRESS:$DB_PORT/$DB_NAME
12-
ENVIRONMENT=local # local | stage | prod
12+
# local | stage | prod
13+
ENVIRONMENT="local"

api/nest-cli.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
{
22
"collection": "@nestjs/schematics",
3-
"sourceRoot": "src",
4-
"$schema": "https://json.schemastore.org/nest-cli"
3+
"sourceRoot": "./src",
4+
"$schema": "https://json.schemastore.org/nest-cli",
5+
"projects": {
6+
"repository": {
7+
"type": "library",
8+
"root": "../libs/repository",
9+
"entryFile": "index",
10+
"sourceRoot": "../libs/repository/src",
11+
"compilerOptions": {
12+
"tsConfigPath": "../libs/repository/tsconfig.api.json"
13+
}
14+
}
15+
}
516
}

0 commit comments

Comments
 (0)