Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nestjs starter template & backend-compose extension #42

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions extensions/backend-compose/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
.git
build
dist
65 changes: 65 additions & 0 deletions extensions/backend-compose/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# syntax=docker/dockerfile:1.4

FROM node:16.16-alpine AS development

# Set working directory
WORKDIR /usr/src/app

# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \
# Allow install without lockfile, so example works even without Node.js installed locally
else echo "Warning: Lockfile not found. It is recommended to commit lockfiles to version control." && yarn install; \
fi


RUN npm cache clean --force

RUN npm install --frozen-lockfile

# Copy the rest of the files
COPY . .

CMD [ "npm", "run", "dev" ]

FROM node:16.16-alpine AS build

# Set working directory
WORKDIR /usr/src/app

# Install dependencies to use npm
COPY --chown=node:node package.json package-lock.json ./
COPY --chown=node:node --from=development /usr/src/app/node_modules node_modules

# Copy the rest of the files
COPY --chown=node:node . .

# Run the build command to build the app
RUN npm run build

# Set the NODE_ENV to production
ENV NODE_ENV=production

# Install production dependencies and clean up the cache
RUN npm ci

# Use the node user from the image as the user to run the app
USER node

FROM node:16.16-alpine AS production

# Set working directory
WORKDIR /usr/src/app

# Copy the bundled code from the build stage to the production image
COPY --chown=node:node --from=build /usr/src/app/dist dist
COPY --chown=node:node --from=build /usr/src/app/node_modules node_modules

# Use the node user from the image as the user to run the app
USER node

# Start the server using the production build
CMD [ "node", "dist/main.js" ]
8 changes: 8 additions & 0 deletions extensions/backend-compose/compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
app:
build:
context: .
target: production
ports:
- '3000:3000'
restart: always
11 changes: 11 additions & 0 deletions extensions/backend-compose/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3.8'
services:
app:
build:
context: .
target: development
ports:
- 3000:3000
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
31 changes: 29 additions & 2 deletions templates.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
{
"$schema": "./templates.schema.json",
"templates": [
{
"name": "NestJS Boilerplate",
"description": "NestJS Framework .",
"url": "https://github.com/Create-Node-App/cna-templates/tree/main/templates/nestjs-starter",
"type": "backend",
"category": "Backend API WIP",
"labels": [
"TypeScript",
"ESLint",
"Prettier",
"NestJS"
]
},
{
"name": "Turborepo Boilerplate",
"description": "A highly opinionated mono repo boilerplate with TypeScript, ESLint, Prettier, and more. Aimed at developers who want to get started with a mono repo quickly.",
Expand Down Expand Up @@ -264,7 +277,7 @@
"name": "GitHub Setup",
"description": "This extension adds GitHub setup to your project including GitHub Actions, Dependabot, Issue Templates, Pull Request Templates, and more.",
"url": "https://github.com/Create-Node-App/cna-templates/tree/main/extensions/all-github-setup",
"type": ["sls", "react", "webextension-react", "monorepo"],
"type": ["sls", "react", "webextension-react", "monorepo", "backend"],
"category": "Tooling",
"labels": [
"GitHub",
Expand Down Expand Up @@ -294,7 +307,7 @@
"name": "Husky + Lint Staged",
"description": "Extension to add Husky and Lint Staged to your project",
"url": "https://github.com/Create-Node-App/cna-templates/tree/main/extensions/all-husky-lint-staged",
"type": ["sls", "react", "webextension-react", "webdriverio"],
"type": ["sls", "react", "webextension-react", "webdriverio", "backend"],
"category": "Tooling",
"labels": ["Husky", "Lint Staged"]
},
Expand Down Expand Up @@ -488,6 +501,20 @@
"Development"
]
},
{
"name": "Docker Compose Setup",
"description": "Add docker environments for development and production to your Backend project setup with docker-compose",
"url": "https://github.com/Create-Node-App/cna-templates/tree/main/extensions/backend-compose",
"type": "backend",
"category": "Tooling",
"labels": [
"Docker",
"Docker Compose",
"React",
"Production",
"Development"
]
},
{
"name": "Android Tools",
"description": "Avoid using heavy IDEs by installing this extension that creates an elegant tool setup for your android app",
Expand Down
25 changes: 25 additions & 0 deletions templates/nestjs-starter/.eslintrc.js
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',
},
};
Loading