Skip to content

Commit

Permalink
chore: housekeeping - docker compose, makefile, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyoptimist committed May 15, 2024
1 parent 80aa56e commit b7d56a7
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 29 deletions.
15 changes: 14 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
node_modules/
.git
.github
.husky
deployments
dist
node_modules
test
.env.example
.eslint*
.gitignore
.prettier*
LICENSE.md
Makefile
README.md
webpack*
4 changes: 0 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# APP
APP_ENV=development
APP_URL=http://localhost:3000

# JWT AUTH
JWT_SECRET_KEY=3uper**3ecret
JWT_EXPIRATION_TIME=3600
Expand Down
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
node_modules/

# IDEs and editors
/.idea
.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
docker:
docker compose -f ./deployments/compose.yaml build
up:
docker compose -f ./deployments/compose.yaml up -d
down:
docker compose -f ./deployments/compose.yaml down
log:
docker compose -f ./deployments/compose.yaml logs -f

.PHONY: deployments test
30 changes: 14 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ Build a modular REST API with NestJS framework.

## What is this?

This is a NestJS RESTful API starter with JWT auth, Open API 3 documentation, TypeORM integrated.
This is a NestJS RESTful API starter that includes JWT authentication, OpenAPI 3 documentation, and TypeORM integration.

Why am I maintianing this? By using this template, you will be able to spin up a production-ready RESTful API super fast, writing very little boilerplate code.
The reason I maintain it is because using this template allows you to quickly set up a production-ready RESTful API with minimal boilerplate code.

## Getting started

Create dotenv file and fill out with proper values
Create a dotenv file and fill it out with the appropriate values.

```bash
cp .env.example .env
Expand All @@ -49,13 +49,13 @@ HMR(Hot Module Reload) is configured with webpack.

## DB Migrations

If you don't need incremental database migrations, set `DB_SYNC` env variable to `true`, which will keep syncing the database structure with the schema defined in the code base.
If you don't require incremental database migrations, set the DB_SYNC environment variable to true. This will continuously synchronize the database structure with the schema defined in the codebase.

**Do NOT set `DB_SYNC` to `true` in production. You may lose production data if you do!**
__However, DO NOT set DB_SYNC to true in a production environment, as doing so may result in data loss!__

### Generate a Migration
#### Generate a New Migration

Make sure to use `npm` for commands follow, because `yarn` does not support `$npm_config_name`.
Make sure to use npm for the following commands, as yarn does not support `$npm_config_name`.

```bash
npm run migration:generate --name=AddAgeColumnToUser
Expand All @@ -67,15 +67,15 @@ Or with docker:
docker exec -it nest npm run migration:generate --name=AddAgeColumnToUser
```

Migration files are placed under `src/migrations`.
Migration files located placed in the `src/migrations` directory.

### Run Pending Migrations
#### Run Pending Migrations

```bash
npm run migration:run
```

### Revert a Migration
#### Revert Migrations

Revert the last migration

Expand All @@ -87,13 +87,13 @@ npm run migration:revert

```bash
# unit tests
yarn test
npm run test

# e2e tests
yarn test:e2e
npm run test:e2e

# test coverage
yarn test:cov
npm run test:cov
```

## Environment Configuration
Expand All @@ -106,9 +106,7 @@ OpenAPI 3.0 is configured, and the API docs is hosted at `BASE_URL/api/docs`.

## Authentication

JWT authentication is configured.

It would be greater to change the current password hashing to something more secure.
JWT authentication has been configured.

## License

Expand Down
9 changes: 5 additions & 4 deletions docker-compose.yaml → deployments/compose.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
version: "3"
name: "nest-starter"

services:
nest:
api:
image: nest
build:
context: .
context: ../
dockerfile: deployments/prod.Dockerfile
image: nest
container_name: nest
ports:
- 3000:3000
Expand Down
2 changes: 1 addition & 1 deletion deployments/prod.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use a Node.js base image with the desired version
FROM node:lts-alpine AS base
FROM node:20-alpine AS base

# Set the working directory inside the container
WORKDIR /app
Expand Down

0 comments on commit b7d56a7

Please sign in to comment.