-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(js): create nestjs-specific files
- Loading branch information
1 parent
cb4b485
commit d343fa6
Showing
29 changed files
with
747 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,6 @@ Thumbs.db | |
.commit | ||
.devbox | ||
.envrc | ||
|
||
coverage | ||
.nyc_output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.md | ||
*.yml | ||
*.yaml | ||
*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/nest-cli", | ||
"collection": "@nestjs/schematics", | ||
"sourceRoot": "src", | ||
"compilerOptions": { | ||
"deleteOutDir": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module.exports = { | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: 'tsconfig.json', | ||
tsconfigRootDir: __dirname, | ||
sourceType: 'module', | ||
}, | ||
plugins: ['@typescript-eslint/eslint-plugin'], | ||
extends: [ | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:prettier/recommended', | ||
], | ||
root: true, | ||
env: { | ||
node: true, | ||
jest: true, | ||
}, | ||
ignorePatterns: ['.eslintrc.js'], | ||
rules: { | ||
'@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', | ||
}, | ||
}; |
127 changes: 127 additions & 0 deletions
127
js/{{ cookiecutter.project_name }}/nestjs/.github/workflows/build.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
name: Build | ||
on: | ||
push: | ||
branches: | ||
- main | ||
tags: | ||
- "v*.*.*" | ||
pull_request: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
permissions: | ||
contents: write | ||
packages: write | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version-file: go.mod | ||
|
||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.x | ||
|
||
- name: Install dependencies | ||
run: go install ./... | ||
|
||
- name: go-vet | ||
run: go vet -v ./... | ||
|
||
- uses: pre-commit/[email protected] | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
needs: | ||
- test | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 # Required for goreleaser changelog to work correctly | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v2 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: {{ '${{ github.actor }}' }} | ||
password: {{ '${{ secrets.GITHUB_TOKEN }}' }} | ||
|
||
- name: Get branch names | ||
id: branch-name | ||
uses: tj-actions/branch-names@v6 | ||
with: | ||
strip_tag_prefix: v | ||
|
||
- name: Generate Docker tag | ||
id: docker | ||
run: | | ||
if [ "{{ '${{ steps.branch-name.outputs.is_tag }}' }}" = "true" ]; | ||
then | ||
# Latest tag | ||
IMG_NAME="ghcr.io/${GITHUB_REPOSITORY,,}:latest" | ||
# Tag name (usually vX.Y.Z) | ||
IMG_NAME="${IMG_NAME},ghcr.io/${GITHUB_REPOSITORY,,}:{{ '${{ steps.branch-name.outputs.tag }}' }}" | ||
echo "image_name=${IMG_NAME}" >> "$GITHUB_OUTPUT" | ||
echo "platforms=linux/amd64,linux/arm64,linux/arm/v7" >> "$GITHUB_OUTPUT" | ||
else | ||
# Use branch naming convention | ||
TAG="branch-{{ '${{ steps.branch-name.outputs.current_branch }}' }}" | ||
# Change "/" for "-" | ||
TAG="${TAG//\//-}" | ||
# Set to lowercase | ||
TAG="${TAG,,}" | ||
echo "image_name=ghcr.io/${GITHUB_REPOSITORY,,}:${TAG}" >> "$GITHUB_OUTPUT" | ||
echo "platforms=linux/amd64" >> "$GITHUB_OUTPUT" | ||
fi | ||
if [ "{{ '${{ steps.branch-name.outputs.is_tag }}' }}" = "true" ]; | ||
then | ||
echo "version={{ '${{ steps.branch-name.outputs.tag }}' }}" >> "$GITHUB_OUTPUT" | ||
else | ||
echo "version=development" >> "$GITHUB_OUTPUT" | ||
fi | ||
echo "container_tagged_image=ghcr.io/${GITHUB_REPOSITORY,,}:${GITHUB_SHA}" >> "$GITHUB_OUTPUT" | ||
echo "commit_id=${GITHUB_SHA}" >> "$GITHUB_OUTPUT" | ||
echo "gitRepo=github.com/${GITHUB_REPOSITORY}" >> "$GITHUB_OUTPUT" | ||
- name: Build and push | ||
uses: docker/build-push-action@v3 | ||
with: | ||
context: . | ||
build-args: | | ||
GIT_COMMIT={{ '${{ steps.docker.outputs.commit_id }}' }} | ||
GIT_REPO={{ '${{ steps.docker.outputs.gitRepo }}' }} | ||
VERSION={{ '${{ steps.docker.outputs.version }}' }} | ||
platforms: {{ '${{ steps.docker.outputs.platforms }}' }} | ||
push: {{ '${{ github.ref == \'refs/heads/main\' }}' }} | ||
tags: {{ '${{ steps.docker.outputs.image_name }},${{ steps.docker.outputs.container_tagged_image }}' }} | ||
|
||
- name: Set up Go | ||
if: steps.branch-name.outputs.is_tag == 'true' | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: '>=1.20.0' | ||
|
||
- name: Run GoReleaser | ||
if: steps.branch-name.outputs.is_tag == 'true' | ||
uses: goreleaser/goreleaser-action@v4 | ||
with: | ||
version: latest | ||
args: release --clean | ||
env: | ||
GIT_REPO: {{ '${{ steps.docker.outputs.gitRepo }}' }} | ||
GITHUB_TOKEN: {{ '${{ secrets.GITHUB_TOKEN }}' }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"printWidth": 80 | ||
} |
17 changes: 17 additions & 0 deletions
17
js/{{ cookiecutter.project_name }}/nestjs/.vscode/settings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"editor.formatOnSave": true, | ||
"editor.rulers": [ | ||
80 | ||
], | ||
"yaml.schemas": { | ||
"https://json.schemastore.org/github-workflow.json": [ | ||
".github/workflows/*.{yml,yaml}" | ||
] | ||
}, | ||
"[javascript]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
}, | ||
"[typescript]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
FROM node:lts-alpine AS dev | ||
ARG GIT_COMMIT | ||
ARG GIT_REPO | ||
ARG VERSION | ||
USER node | ||
WORKDIR /home/node/app | ||
ENV GIT_REPO="${GIT_REPO}" | ||
ENV GIT_COMMIT="${GIT_COMMIT}" | ||
ENV VERSION="${VERSION}" | ||
COPY --chown=node:node . . | ||
ENV PORT=3000 | ||
EXPOSE 3000 | ||
CMD [ "npm", "run", "start:dev" ] | ||
|
||
FROM node:lts-alpine AS builder | ||
USER node | ||
USER node | ||
WORKDIR /home/node/app | ||
COPY --from=dev /home/node/app . | ||
RUN npm ci \ | ||
&& npm run build | ||
|
||
FROM node:lts-alpine | ||
ARG GIT_COMMIT | ||
ARG GIT_REPO | ||
ARG VERSION | ||
WORKDIR /opt/app | ||
ENV GIT_REPO="${GIT_REPO}" | ||
ENV GIT_COMMIT="${GIT_COMMIT}" | ||
ENV VERSION="${VERSION}" | ||
ENV SERVER_PORT=3000 | ||
COPY --from=builder /home/node/app/dist dist | ||
COPY --from=builder /home/node/app/node_modules node_modules | ||
COPY --from=builder /home/node/app/package.json package.json | ||
COPY --from=builder /home/node/app/package-lock.json package-lock.json | ||
RUN npm prune --production \ | ||
&& npm rebuild \ | ||
&& npm dedupe \ | ||
&& npm version ${VERSION} --no-git-tag-version --allow-same-version || true | ||
USER node | ||
EXPOSE 3000 | ||
CMD [ "npm", "run", "start:prod" ] |
32 changes: 32 additions & 0 deletions
32
js/{{ cookiecutter.project_name }}/nestjs/docker-compose.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
services: | ||
app: | ||
build: | ||
context: . | ||
target: dev | ||
environment: | ||
DB_TYPE: mysql | ||
DB_HOST: mysql | ||
DB_USERNAME: app | ||
DB_PASSWORD: password | ||
DB_NAME: app | ||
DB_PORT: "3306" | ||
DB_MIGRATIONS_RUN: "true" | ||
DB_SYNC: "false" | ||
volumes: | ||
- .:/home/node/app | ||
ports: | ||
- 9000:3000 | ||
links: | ||
- mysql | ||
restart: on-failure | ||
|
||
# Third-party services | ||
mysql: | ||
image: mysql:8 | ||
environment: | ||
MYSQL_RANDOM_ROOT_PASSWORD: "true" | ||
MYSQL_USER: app | ||
MYSQL_PASSWORD: password | ||
MYSQL_DATABASE: app | ||
ports: | ||
- 4000:3306 |
54 changes: 54 additions & 0 deletions
54
js/{{ cookiecutter.project_name }}/nestjs/src/app.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { ConfigModule, ConfigService } from '@nestjs/config'; | ||
import { Module } from '@nestjs/common'; | ||
import { LoggerModule, Params, PinoLogger } from 'nestjs-pino'; | ||
import config from './config'; | ||
import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm'; | ||
import { PinoTypeOrmLogger } from './lib/pinoTypeOrmLogger'; | ||
import { LoggerOptions } from 'typeorm'; | ||
import { HealthModule } from './health/health.module'; | ||
|
||
@Module({ | ||
imports: [ | ||
ConfigModule.forRoot({ | ||
isGlobal: true, | ||
load: config, | ||
}), | ||
LoggerModule.forRootAsync({ | ||
imports: [ConfigModule], | ||
inject: [ConfigService], | ||
useFactory: async (configService: ConfigService): Promise<Params> => | ||
configService.get<Params>('logger'), | ||
}), | ||
TypeOrmModule.forRootAsync({ | ||
imports: [ConfigModule, LoggerModule], | ||
inject: [ConfigService, PinoLogger], | ||
useFactory: async ( | ||
configService: ConfigService, | ||
pinoLogger: PinoLogger, | ||
): Promise<TypeOrmModuleOptions> => { | ||
const db = configService.get<TypeOrmModuleOptions>('db'); | ||
|
||
/* Replace the default TypeOrm logger with PinoTypeOrmLogger */ | ||
let logger: 'debug' | PinoTypeOrmLogger = 'debug'; | ||
let logging = false; | ||
|
||
if (configService.get<LoggerOptions>('db.logging', false)) { | ||
logger = new PinoTypeOrmLogger(pinoLogger); | ||
logging = true; | ||
} | ||
|
||
return { | ||
...db, | ||
logging, | ||
logger, | ||
}; | ||
}, | ||
}), | ||
|
||
// Load the internal modules | ||
HealthModule, | ||
], | ||
controllers: [], | ||
providers: [], | ||
}) | ||
export class AppModule {} |
Oops, something went wrong.