Skip to content

Commit 61378ee

Browse files
committed
chore: add scaffold
1 parent 798259a commit 61378ee

File tree

191 files changed

+13495
-0
lines changed

Some content is hidden

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

191 files changed

+13495
-0
lines changed

Diff for: .deepsource.toml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version = 1
2+
3+
[[analyzers]]
4+
enabled = true
5+
name = "javascript"
6+
7+
[[transformers]]
8+
enabled = true
9+
name = "prettier"
10+
11+
test_patterns = [
12+
"test/**/*",
13+
"**/*.spec.ts"
14+
]
15+
16+
exclude_patterns = [
17+
"**/node_modules/",
18+
"**/*memory*"
19+
]

Diff for: .editorconfig

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
# The JSON files contain newlines inconsistently
13+
[*.json]
14+
insert_final_newline = ignore
15+
16+
[*.md]
17+
trim_trailing_whitespace = false
18+

Diff for: .env.example

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Environment
2+
NODE_ENV=development
3+
4+
# Server
5+
HOST=localhost
6+
PORT=3331
7+
RATE_MAX_REQUEST=100
8+
RATE_INTERVAL=1000
9+
10+
# Database
11+
DB_HOST=localhost
12+
DB_PORT=27125
13+
DB_USERNAME=root
14+
DB_PASSWORD=secret
15+
DB_DATABASE=app
16+
17+
# JWT
18+
JWT_EXPIRES=365d
19+
JWT_SECRET=secret
20+
21+
# S3
22+
S3_ACCESS_KEY=AKIAIOSFODNN7EXAMPLE
23+
S3_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
24+
S3_BUCKET=default
25+
S3_ENDPOINT=http://127.0.0.1:9000
26+
27+
28+
SES_REGION=us-east-1
29+
SES_ACCESS_KEY=AKIAIOSFODNN7EXAMPLE
30+
SES_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
31+
SES_BCC=
32+
33+
# Docker Registry
34+
DOCKER_REGISTRY_URI=registry.example.com
35+
36+
# Docker Compose
37+
COMPOSE_PROJECT_NAME=nestjs-mongodb-hexagonal-template

Diff for: .eslintrc.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
parserOptions: {
4+
project: 'tsconfig.json',
5+
sourceType: 'module',
6+
},
7+
plugins: ['@typescript-eslint/eslint-plugin'],
8+
extends: [
9+
'plugin:@typescript-eslint/recommended',
10+
'plugin:prettier/recommended',
11+
'plugin:yml/standard',
12+
],
13+
root: true,
14+
env: {
15+
node: true,
16+
jest: true,
17+
},
18+
ignorePatterns: ['.eslintrc.js'],
19+
rules: {
20+
'@typescript-eslint/interface-name-prefix': 'off',
21+
'@typescript-eslint/explicit-function-return-type': 'off',
22+
'@typescript-eslint/explicit-module-boundary-types': 'off',
23+
'@typescript-eslint/no-explicit-any': 'off',
24+
},
25+
};

Diff for: .github/workflows/build.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Docker Image Build
2+
3+
on:
4+
pull_request:
5+
branches: [ "main", "develop" ]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- name: Build the Docker image
13+
run: docker build . --tag app:$(date +%s)

Diff for: .github/workflows/lint.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Lint
2+
3+
on:
4+
pull_request:
5+
branches: ["main", "develop"]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
node-version: [18.x]
13+
defaults:
14+
run:
15+
working-directory: .
16+
steps:
17+
- uses: actions/checkout@v2
18+
with:
19+
fetch-depth: 0
20+
- uses: actions/setup-node@v1
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
- name: Install libraries
24+
run: yarn install
25+
- name: Run linter
26+
run: yarn lint

Diff for: .github/workflows/test.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
branches: ["main", "develop"]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
node-version: [18.x]
13+
defaults:
14+
run:
15+
working-directory: .
16+
steps:
17+
- uses: actions/checkout@v2
18+
with:
19+
fetch-depth: 0
20+
- uses: actions/setup-node@v1
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
- name: Install libraries
24+
run: yarn install
25+
- name: Run test
26+
run: yarn test

Diff for: .gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,15 @@ dist
128128
.yarn/build-state.yml
129129
.yarn/install-state.gz
130130
.pnp.*
131+
132+
# MacOS
133+
.DS_Store
134+
135+
# Env files
136+
.env
137+
.env.*
138+
!.env.example
139+
140+
# Docker resources
141+
.mongodb
142+
.minio

Diff for: .nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v.18

Diff for: .prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all",
4+
"printWidth": 96
5+
}

Diff for: .vscode/settings.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"editor.tabSize": 2,
3+
"editor.formatOnSave": true
4+
}

Diff for: Dockerfile

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM node:16 as build
2+
3+
WORKDIR /src
4+
5+
COPY package.json .
6+
COPY yarn.lock .
7+
8+
RUN yarn install
9+
10+
COPY . .
11+
12+
RUN yarn build
13+
RUN rm -rf node_modules
14+
RUN yarn install --production=true
15+
16+
FROM node:16-alpine as deploy
17+
18+
WORKDIR /app
19+
20+
COPY --from=build /src/dist/ /app
21+
COPY --from=build /src/node_modules ./node_modules
22+
23+
ENTRYPOINT [ "node", "main.js" ]

Diff for: deploy.sh

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
# Cargar las variables de ambiente del archivo .env
4+
if [ -f .env ]; then
5+
source .env
6+
fi
7+
8+
# Obtener el nombre del contenedor a partir del nombre del proyecto de Docker Compose
9+
CONTAINER_NAME="$COMPOSE_PROJECT_NAME"
10+
TAG=$1
11+
12+
# Autenticarse en ECR
13+
AWS_REGION=$(echo "$DOCKER_REGISTRY_URI" | cut -d '.' -f 4)
14+
DOCKER_REGISTRY_HOST=$(echo "$DOCKER_REGISTRY_URI" | cut -d '/' -f 1)
15+
aws ecr get-login-password --region "$AWS_REGION" | docker login --username AWS --password-stdin "$DOCKER_REGISTRY_HOST"
16+
17+
docker pull "$DOCKER_REGISTRY_URI:$TAG"
18+
19+
CURRENT_CONTAINER_ID=$(docker ps -qf "name=$CONTAINER_NAME")
20+
21+
if [ -z "$CURRENT_CONTAINER_ID" ]
22+
docker stop "$CURRENT_CONTAINER_ID" && docker rm "$CURRENT_CONTAINER_ID"
23+
then
24+
echo "No current container $CONTAINER_NAME"
25+
fi
26+
27+
shift
28+
29+
TEMP_CONTAINER_NAME="$CONTAINER_NAME-temp"
30+
31+
docker run -d --name "$TEMP_CONTAINER_NAME" "$@" "$DOCKER_REGISTRY_URI:$TAG"
32+
docker rename "$TEMP_CONTAINER_NAME" "$CONTAINER_NAME"

Diff for: docker-compose.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
version: '3.8'
2+
3+
services:
4+
mongodb:
5+
container_name: ${COMPOSE_PROJECT_NAME}_mongodb
6+
image: mongo:5.0
7+
environment:
8+
- MONGO_INITDB_DATABASE=app
9+
- MONGO_INITDB_ROOT_USERNAME=root
10+
- MONGO_INITDB_ROOT_PASSWORD=secret
11+
ports:
12+
- 27125:27017
13+
volumes:
14+
- .mongodb:/data/db
15+
16+
minio:
17+
container_name: ${COMPOSE_PROJECT_NAME}_minio
18+
image: minio/minio:latest
19+
command: server --console-address :9001 /data
20+
environment:
21+
- MINIO_ROOT_USER=AKIAIOSFODNN7EXAMPLE
22+
- MINIO_ROOT_PASSWORD=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
23+
volumes:
24+
- .minio:/data
25+
ports:
26+
- 9000:9000
27+
- 9001:9001

Diff for: docker.sh

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
3+
if [ -z "$DOCKER_REGISTRY_URI" ]; then
4+
echo "Error: DOCKER_REGISTRY_URI variable is not defined"
5+
exit 1
6+
fi
7+
8+
if [ -z "$COMPOSE_PROJECT_NAME" ]; then
9+
echo "Error: COMPOSE_PROJECT_NAME variable is not defined"
10+
exit 1
11+
fi
12+
13+
get_remote() {
14+
echo $(docker image ls --filter "reference=$PUBLISH_TAG" --format "{{.Repository}}:{{.Tag}}")
15+
}
16+
17+
get_tag() {
18+
BRANCH=$(git branch --show-current)
19+
20+
if [ "$BRANCH" == "main" ] || [ "$BRANCH" == "master" ]; then
21+
echo ""
22+
elif [ "$BRANCH" == "develop" ]; then
23+
echo "develop"
24+
else
25+
echo "$BRANCH"
26+
fi
27+
}
28+
29+
TAG=$(get_tag)
30+
VERSION=$(awk -F'"' '/"version": ".+"/{ print $4; exit; }' package.json)
31+
DOCKER_REGISTRY_HOST=$(echo $DOCKER_REGISTRY_URI | awk -F/ '{print $1}')
32+
REGION=$(echo $DOCKER_REGISTRY_URI | awk -F[/.] '{print $4}')
33+
HASH=$(git rev-parse HEAD)
34+
IMAGE_NAME=$COMPOSE_PROJECT_NAME
35+
36+
if [ -n "$TAG" ]; then
37+
IMAGE_NAME="$IMAGE_NAME:$TAG-$HASH"
38+
REGISTRY_IMAGE_TAG=$DOCKER_REGISTRY_URI:$TAG
39+
PUBLISH_TAG=$REGISTRY_IMAGE_TAG-$HASH
40+
else
41+
IMAGE_NAME="$IMAGE_NAME:$HASH"
42+
REGISTRY_IMAGE_TAG=$DOCKER_REGISTRY_URI:$HASH
43+
PUBLISH_TAG=$REGISTRY_IMAGE_TAG
44+
fi
45+
46+
47+
if [ -z "$IMAGE_NAME" ]; then
48+
echo "There's no local image to delete"
49+
else
50+
docker rmi $IMAGE_NAME
51+
fi
52+
53+
if [ -z $(get_remote) ]; then
54+
echo "There's no remote tag to delete"
55+
else
56+
docker rmi $(get_remote)
57+
fi
58+
59+
docker build --platform linux/amd64 -t $IMAGE_NAME .
60+
docker tag $IMAGE_NAME $PUBLISH_TAG
61+
aws ecr get-login-password --region $REGION --profile $1 | docker login --username AWS --password-stdin $DOCKER_REGISTRY_HOST
62+
docker push $PUBLISH_TAG
63+
64+
UNTAGGED_IMAGES=$(aws ecr list-images --no-cli-pager --region $REGION --profile $1 --repository-name $COMPOSE_PROJECT_NAME --filter "tagStatus=UNTAGGED" --query 'imageIds[*].[imageDigest]' --output text | sed -e 's/^/imageDigest=/')
65+
66+
if [ -z "$UNTAGGED_IMAGES" ]; then
67+
echo "There's no remote images to delete"
68+
else
69+
aws ecr batch-delete-image --no-cli-pager --region $REGION --profile $1 --repository-name $COMPOSE_PROJECT_NAME --image-ids $UNTAGGED_IMAGES >/dev/null
70+
fi
71+
72+
for image in $(get_remote); do
73+
docker rmi -f "$image"
74+
done

Diff for: libs/common/src/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export * from './types/general/json.type';
2+
export * from './types/database/database-connnection.type';
3+
export * from './types/http/http-server.type';
4+
export * from './types/ses/ses-configuration.type';
5+
export * from './types/jwt/jwt.configuration';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export type DatabaseConnection = {
2+
host: string;
3+
port?: number;
4+
username?: string;
5+
password?: string;
6+
database?: string;
7+
};
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export type EnvironmentConfig = {
2+
nodeEnv: string;
3+
};

Diff for: libs/common/src/types/general/file.type.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export type File = {
2+
originalname: string;
3+
fieldname: string;
4+
enconding: string;
5+
mimetype: string;
6+
buffer: Buffer;
7+
size: number;
8+
};

Diff for: libs/common/src/types/general/json.type.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export type Json = {
2+
[key: string]: any;
3+
};

0 commit comments

Comments
 (0)