diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a3391ae --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +.dockerignore +.git +docker-compose.yml +Dockerfile +node_modules +dist +data +logs diff --git a/.gitignore b/.gitignore index 61a1867..aab2965 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ dist/ .tmp logs/ src/Contexts/Mooc/Courses/infrastructure/persistence/courses.* +data diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..49bf43a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM node:12.16.3-slim + +WORKDIR /code + +COPY package.json package-lock.json ./ +RUN npm install diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b490c5b --- /dev/null +++ b/Makefile @@ -0,0 +1,39 @@ +.PHONY = default deps build test start clean start-database + +IMAGE_NAME := codelytv/typescript-ddd-skeleton +SERVICE_NAME := app + +# Test if the dependencies we need to run this Makefile are installed +DOCKER := $(shell command -v docker) +DOCKER_COMPOSE := $(shell command -v docker-compose) +deps: +ifndef DOCKER + @echo "Docker is not available. Please install docker" + @exit 1 +endif +ifndef DOCKER_COMPOSE + @echo "docker-compose is not available. Please install docker-compose" + @exit 1 +endif + +default: build + +# Build image +build: + docker build -t $(IMAGE_NAME):dev . + +# Run tests +test: build + docker-compose run --rm $(SERVICE_NAME) bash -c 'npm run build && npm run test' + +# Start the application +start: build + docker-compose up $(SERVICE_NAME) && docker-compose down + +# Clean containers +clean: + docker-compose down --rmi local --volumes --remove-orphans + +# Start mongodb container in background +start_database: + docker-compose up -d mongo diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..830a578 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +version: '3.8' + +services: + app: + build: . + command: bash -c "npm run build && npm run start" + ports: + - 3000:3000 + environment: + - MONGO_URL=mongodb://mongo:27017/dev + depends_on: + - mongo + volumes: + - .:/code:delegated + - node_modules:/code/node_modules:delegated + + mongo: + image: mongo:3.4.6 + volumes: + - ./data/mongo:/data/db:delegated + ports: + - 27017:27017 + +volumes: + node_modules: diff --git a/package.json b/package.json index 59a19f4..3d5fc66 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "start": "NODE_ENV=production node dist/src/apps/mooc_backend/server", "build": "npm run build:clean && npm run build:tsc && npm run build:di", "build:tsc": "tsc -p tsconfig.prod.json", - "build:di": "copy 'src/**/*.yaml' dist/src", + "build:di": "copy 'src/**/*.{json,yaml}' dist/src", "build:clean": "rm -r dist; exit 0" }, "dependencies": { diff --git a/src/apps/mooc_backend/config/config.ts b/src/apps/mooc_backend/config/config.ts index 481409f..11b1dba 100644 --- a/src/apps/mooc_backend/config/config.ts +++ b/src/apps/mooc_backend/config/config.ts @@ -11,7 +11,8 @@ const convictConfig = convict({ url: { doc: 'The Mongo connection URL', format: String, - env: 'MONGO_URL' + env: 'MONGO_URL', + default: 'mongodb://mongo:27017/dev' } } }); diff --git a/src/apps/mooc_backend/config/production.json b/src/apps/mooc_backend/config/production.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/src/apps/mooc_backend/config/production.json @@ -0,0 +1 @@ +{}