Skip to content

Commit

Permalink
Merge pull request #493 from andrechristikan/development
Browse files Browse the repository at this point in the history
docker installation update, file helper update
  • Loading branch information
andrechristikan authored Nov 29, 2023
2 parents d9e22d1 + 40d9118 commit dc875d5
Show file tree
Hide file tree
Showing 22 changed files with 973 additions and 927 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jobs:
docker stop ${{ env.APP_NAME }} && docker rm ${{ env.APP_NAME }}
docker network create ${{ env.APP_NETWORK }} --driver=bridge
docker run -itd \
--build-arg NODE_ENV=production \
--hostname ${{ env.APP_NAME }} \
--publish ${{ secrets.APP_PORT }}:${{ env.APP_PORT }} \
--network ${{ env.APP_NETWORK }} \
Expand Down Expand Up @@ -148,6 +149,7 @@ jobs:
docker stop ${{ env.APP_NAME }} && docker rm ${{ env.APP_NAME }}
docker network create ${{ env.APP_NETWORK }} --driver=bridge
docker run -itd \
--build-arg NODE_ENV=staging \
--hostname ${{ env.APP_NAME }} \
--publish ${{ env.APP_PORT_EXPOSE }}:${{ env.APP_PORT }} \
--network ${{ env.APP_NETWORK }} \
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

env:
DOCKER_HUB: ${{ secrets.DOCKER_HUB }}
DOCKERFILE: .github/dockerfile
DOCKERFILE: ./ci/dockerfile

steps:
- name: Git checkout
Expand Down Expand Up @@ -73,6 +73,8 @@ jobs:
with:
builder: ${{ steps.main.outputs.name }}
file: ${{ env.DOCKERFILE }}
args: |
NODE_ENV=production
target: main
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.DOCKER_HUB }}:latest
Expand All @@ -86,6 +88,8 @@ jobs:
with:
builder: ${{ steps.main.outputs.name }}
file: ${{ env.DOCKERFILE }}
args: |
NODE_ENV=staging
target: main
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.DOCKER_HUB }}:staging_v${{ steps.version.outputs.current-version }}
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@

> Very limited documentation, and will move to stateful authorization
* The features will be relate with AWS
* The features will be relate with AWS / Amazon web service
* Stateless Authorization
* If you want to implement `database transactions`. You must run MongoDB as a `replication set`.
* If you want to implement `Google SSO`.
1. You must have google account, then set your app on `google console` to get the `clientId` and `clientSecret`.
* If you want to implement `Google SSO`. You must have google cloud console account, then create your own SSO / Credential API to get the `clientId` and `clientSecret`.
* If you change the environment value of `APP_ENV` to `production`, that will trigger.
1. CorsMiddleware will implement `src/configs/middleware.config.ts`.
2. Documentation will `disable`.
* For monitoring, this project will use sentry.io, and only send `500` or `internal server error`.

## Todo

Expand All @@ -52,8 +52,8 @@
* [x] Debugger env change
* [x] Add exception filter to Sentry.io
* [x] Add Email Module with AWS SES
* [ ] Push docker image to AWS ECR
* [ ] CI/CD Using AWS ECS and deploy to AWS EC2
* [ ] CI Push docker image to AWS ECR
* [ ] CD Using AWS ECS and deploy to AWS EC2
* [ ] Update Package, and remove unused package
* [ ] Update Documentation, add behaviors
* [ ] Update Documentation, and include an diagram for easier comprehension
Expand Down
42 changes: 42 additions & 0 deletions ci/docker-compose.mongo-replica.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
version: '3.8'
services:
mongo1:
container_name: mongo1
hostname: mongo1
image: mongo
restart: always
networks:
- app-network
volumes:
- dbdata1:/data/db
command: mongod --bind_ip_all --replSet rs0

mongo2:
container_name: mongo2
hostname: mongo2
image: mongo
networks:
- app-network
restart: always
volumes:
- dbdata2:/data/db
command: mongod --bind_ip_all --replSet rs0

mongo3:
container_name: mongo3
hostname: mongo3
image: mongo
networks:
- app-network
restart: always
volumes:
- dbdata3:/data/db
command: mongod --bind_ip_all --replSet rs0
networks:
app-network:
name: app-network
driver: bridge
volumes:
dbdata1:
dbdata2:
dbdata3:
3 changes: 2 additions & 1 deletion .github/dockerfile → ci/dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
FROM node:lts-alpine as builder
LABEL maintainer "[email protected]"

ENV NODE_ENV=test

WORKDIR /app
COPY package.json yarn.lock ./

Expand All @@ -16,7 +18,6 @@ RUN yarn build
FROM node:lts-alpine as main
LABEL maintainer "[email protected]"

ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

WORKDIR /app
Expand Down
4 changes: 1 addition & 3 deletions data/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
!.gitignore
!README.md
*
swagger.json
47 changes: 5 additions & 42 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
version: '3.8'
services:
service:
build: .
build:
context: .
args:
NODE_ENV: 'development'
container_name: service
hostname: service
ports:
Expand All @@ -12,47 +15,7 @@ services:
- ./src/:/app/src/
- .env/:/app/.env
restart: unless-stopped
depends_on:
- mongo1
- mongo2
- mongo3
mongo1:
container_name: mongo1
hostname: mongo1
image: mongo
restart: always
networks:
- app-network
volumes:
- dbdata1:/data/db
command: mongod --bind_ip_all --replSet rs0

mongo2:
container_name: mongo2
hostname: mongo2
image: mongo
networks:
- app-network
restart: always
volumes:
- dbdata2:/data/db
command: mongod --bind_ip_all --replSet rs0

mongo3:
container_name: mongo3
hostname: mongo3
image: mongo
networks:
- app-network
restart: always
volumes:
- dbdata3:/data/db
command: mongod --bind_ip_all --replSet rs0
networks:
app-network:
name: app-network
driver: bridge
volumes:
dbdata1:
dbdata2:
dbdata3:
driver: bridge
2 changes: 2 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
FROM node:lts-alpine
LABEL maintainer "[email protected]"

ENV NODE_ENV=${NODE_ENV}

WORKDIR /app
EXPOSE 3000

Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Installation will describe in difference doc. [here][doc-installation].

## API Spec

You can check The API Spec after running this project. in `localhost:3000/docs`.
You can check The API Spec after running this project. Url `localhost:3000/docs`.


[doc-installation]: /docs/installation.md
Expand Down
8 changes: 4 additions & 4 deletions docs/database/database_migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ api key secret: `ZLCtDd2rh3TAyVhfAeo3JOPvWfAsTp0Oq6rHl69D`

1. Super Admin
- email: `[email protected]`
- password: `aaAA@@123444`
- password: `aaAA@123`
2. Admin
- email: `[email protected]`
- password: `aaAA@@123444`
- password: `aaAA@123`
3. Member
- email: `[email protected]`
- password: `aaAA@@123444`
- password: `aaAA@123`
4. User
- email: `[email protected]`
- password: `aaAA@@123444`
- password: `aaAA@123`

<!-- Reference -->
[ref-nestjs]: http://nestjs.com
Expand Down
32 changes: 23 additions & 9 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,35 @@ For docker installation, we need more tools to be installed.
1. [Docker][ref-docker]
2. [Docker-Compose][ref-dockercompose]

### Create environment

Make your own environment file with a copy of `env.example` and adjust values to suit your own environment.

```bash
cp .env.example .env
```

then run

```bash
docker-compose up -d
```

`After all containers up, we not finish yet`. We need to manual configure mongodb as replication set.
## Database Migration

This project need to do migration for running. [Read this][ack-database-migration-doc]


## Database Mongo Replication locally

> Optional
If we want run mongo replication locally, i already provide docker compose.

1. Go to `./ci`
2. then run `docker-compose -f docker-compose.mongo-replica.yml up -d`

After that, we need manual configure mongodb.
In this case primary will be `mongo1`

1. Enter the `mongo1 container`
Expand Down Expand Up @@ -114,14 +136,6 @@ In this case primary will be `mongo1`
docker restart service
```
## Database Migration
This project need to do migration for running. [Read this][ack-database-migration-doc]
## API Reference
You can check The API Spec after running this project. in `localhost:3000/docs`.
[ack-database-migration-doc]: ./database/database_migration.md
<!-- Reference -->
Expand Down
6 changes: 3 additions & 3 deletions docs/structures/structure_folder.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Folder Structure

1. `/app` The final wrapper module
2. `/common` The common module
2. `/common` The common module, or shared module
3. `/configs` The configurations for this project
4. `/health` health check module for every service integrated
5. `/jobs` cron job or schedule task
5. `/jobs` cron job or schedule task.
6. `/language` json languages
7. `/migration` migrate all init data
7. `/migration` migration module. seeding, and rollback.
8. `/modules` other modules based on service based on project
9. `/router` endpoint router. `Controller` will put in this
Loading

0 comments on commit dc875d5

Please sign in to comment.