Skip to content
This repository has been archived by the owner on Jul 2, 2023. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
aslupin committed Oct 29, 2020
0 parents commit 17a779d
Show file tree
Hide file tree
Showing 45 changed files with 10,243 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dist
test
.vscode
.github
/node_modules
tsconfig.tsbuildinfo
24 changes: 24 additions & 0 deletions .github/workflows/jest-unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Unit test - Node (v12.x v14.x)

on:
push:
branches:
- develop

jobs:
test:
name: Unit test with jest on node v${{ matrix.node-version }}
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x]
steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm install
run: npm install
- name: npm test with jest
run: npm run test:github-action
25 changes: 25 additions & 0 deletions .github/workflows/postman-api-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Postman - APIs Test with newman-cli

on:
push:
branches:
- staging

jobs:
test:
name: APIs Testing
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Building APIs
run: pwd && ls -al && docker-compose up -d
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: '12'
- name: Install newman
run: npm install -g newman
- name: Waiting APIs launched
run: make pm-github-action
- name: Run newman
run: make postman-test-api
70 changes: 70 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# compiled output
/dist
/node_modules

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

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

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json


# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log

# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
# .tfvars files are managed as part of configuration and so should be included in
# version control.
#
# example.tfvars

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
#
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

# Ignore CLI configuration files
.terraformrc
terraform.rc
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"singleQuote": true,
"trailingComma": "all",
"semi": false,
"printWidth": 120
}
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
SERVICE_NAME := boilerplate-typescript-fastify-clean-architecture
.DEFAULT_GOAL := setup
MONGO_AUTH_NAME := admin
POSTMAN_COLLECTION_PATH := test/_postman/collection/${SERVICE_NAME}_test.postman.collection.json
POSTMAN_ENVIRONMENT_PATH := test/_postman/environment/${SERVICE_NAME}_oopback.postman.environment.json

mgo-shutdown: shutdown-mongo-on-local
pm-github-action: postman-test-api-on-gh-action

shutdown-mongo-on-local:
mongo --eval "db.getSiblingDB('${MONGO_AUTH_NAME}').shutdownServer()"

start-init:
docker-compose up --build --force-recreate --renew-anon-volumes

compilation-and-run:
npm run build
npm run start

start:
docker-compose up --build

stop:
@ echo "> Stop development environment"
@ docker-compose down
@ echo "> ----- Complete -----"

postman-test-api:
newman run ${POSTMAN_COLLECTION_PATH} -e ${POSTMAN_ENVIRONMENT_PATH} --verbose

postman-test-api-on-gh-action:
sh postman.api_test.gh_action.sh
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# boilerplate-typescript-fastify-clean-architecture
The repository is template for starting project with "boilerplate-typescript-fastify-clean-architecture" by develop CRUD for TODO APIs.

note:
- Explain about defination of clean architecture will come soon.
- Now, testing coverage is not 100%.

### Installation - Todo APIs

```bash
npm install
```

### Usage

```bash
docker-compose up
# or
npm run dev
# or
npm run build
npm run start
```

### Testing

#### Unit test

```bash
npm run test
```

#### APIs test

```bash
npm run test:postman
```
4 changes: 4 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// babel.config.js
module.exports = {
presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript'],
}
4 changes: 4 additions & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
imports:
- { resource: 'development.yml', property: 'development' }
- { resource: 'production.yml', property: 'production' }
- { resource: 'staging.yml', property: 'staging' }
20 changes: 20 additions & 0 deletions config/development.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
app:
kind: development
port: 8080

db:
mongo:
username: root
password: root
host: localhost
port: 27017
name: todo_template
auth: admin
collection: todo

queue:
connection:
username: guest
password: guest
host: 127.0.0.1
port: 5672
20 changes: 20 additions & 0 deletions config/production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
app:
kind: production
port: 8080

db:
mongo:
username: root
password: root
host: mongo
port: 27017
name: todo_template
auth: admin
collection: todo

queue:
connection:
username: guest
password: guest
host: rabbitmq
port: 5672
20 changes: 20 additions & 0 deletions config/staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
app:
kind: development
port: 8080

db:
mongo:
username: root
password: root
host: 127.0.0.1
port: 27017
name: todo_template
auth: admin
collection: todo

queue:
connection:
username: guest
password: guest
host: 127.0.0.1
port: 5672
50 changes: 50 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
version: "3.1"
services:
boilerplate-typescript-fastify-clean-architecture:
container_name: boilerplate-typescript-fastify-clean-architecture
image: boilerplate-typescript-fastify-clean-architecture:v1
build:
context: ./
dockerfile: ./docker/prod.Dockerfile
restart: always
ports:
- 8080:8080
depends_on:
- mongo
# - rabbitmq
# command: sh -c "dockerize -wait tcp://mongo:27017 -wait tcp://rabbitmq:5672 -timeout 300s -wait-retry-interval 30s npm start"
command: sh -c "dockerize -wait tcp://mongo:27017 -timeout 300s -wait-retry-interval 30s npm run start:production"
logging:
driver: "json-file"
options:
max-size: "50m"
max-file: "10"
labels:
kompose.service.type: LoadBalancer

# rabbitmq:
# container_name: rabbitmq
# image: rabbitmq:management
# ports:
# - "15672:15672"
# - "5672:5672"
# logging:
# driver: "json-file"
# options:
# max-size: "50m"
# max-file: "10"

mongo:
container_name: mongo
image: mongo:4.0
ports:
- 27017:27017
environment:
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=root
- MONGO_INITDB_DATABASE=database
logging:
driver: "json-file"
options:
max-size: "50m"
max-file: "10"
19 changes: 19 additions & 0 deletions docker/prod.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:14.2
WORKDIR /home/api
COPY ./package*.json ./
RUN npm install
COPY . .
RUN npm run build
COPY . .
RUN ls -la
EXPOSE 8080

# Add dockerize
RUN apt-get update && apt-get install -y wget

ENV DOCKERIZE_VERSION v0.6.1
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz

CMD ["npm", "run" ,"start:production"]
12 changes: 12 additions & 0 deletions docker/staging.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:14.3

WORKDIR /home/api

COPY ./package*.json ./
RUN npm install
COPY . .
RUN npm run build
COPY . .
EXPOSE 8080

CMD ["npm", "run", "start:staging"]
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
testEnvironment: 'node'
};
Loading

0 comments on commit 17a779d

Please sign in to comment.