Skip to content

Commit 48da110

Browse files
authored
Merge pull request #60 from CodelyTV/add_dependencies_docker
Add docker-compose with external dependencies
2 parents feb2c24 + d87a55f commit 48da110

File tree

8 files changed

+83
-2
lines changed

8 files changed

+83
-2
lines changed

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.dockerignore
2+
.git
3+
docker-compose.yml
4+
Dockerfile
5+
node_modules
6+
dist
7+
data
8+
logs

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ dist/
33
.tmp
44
logs/
55
src/Contexts/Mooc/Courses/infrastructure/persistence/courses.*
6+
data

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM node:12.16.3-slim
2+
3+
WORKDIR /code
4+
5+
COPY package.json package-lock.json ./
6+
RUN npm install

Makefile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
.PHONY = default deps build test start clean start-database
2+
3+
IMAGE_NAME := codelytv/typescript-ddd-skeleton
4+
SERVICE_NAME := app
5+
6+
# Test if the dependencies we need to run this Makefile are installed
7+
DOCKER := $(shell command -v docker)
8+
DOCKER_COMPOSE := $(shell command -v docker-compose)
9+
deps:
10+
ifndef DOCKER
11+
@echo "Docker is not available. Please install docker"
12+
@exit 1
13+
endif
14+
ifndef DOCKER_COMPOSE
15+
@echo "docker-compose is not available. Please install docker-compose"
16+
@exit 1
17+
endif
18+
19+
default: build
20+
21+
# Build image
22+
build:
23+
docker build -t $(IMAGE_NAME):dev .
24+
25+
# Run tests
26+
test: build
27+
docker-compose run --rm $(SERVICE_NAME) bash -c 'npm run build && npm run test'
28+
29+
# Start the application
30+
start: build
31+
docker-compose up $(SERVICE_NAME) && docker-compose down
32+
33+
# Clean containers
34+
clean:
35+
docker-compose down --rmi local --volumes --remove-orphans
36+
37+
# Start mongodb container in background
38+
start_database:
39+
docker-compose up -d mongo

docker-compose.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
version: '3.8'
2+
3+
services:
4+
app:
5+
build: .
6+
command: bash -c "npm run build && npm run start"
7+
ports:
8+
- 3000:3000
9+
environment:
10+
- MONGO_URL=mongodb://mongo:27017/dev
11+
depends_on:
12+
- mongo
13+
volumes:
14+
- .:/code:delegated
15+
- node_modules:/code/node_modules:delegated
16+
17+
mongo:
18+
image: mongo:3.4.6
19+
volumes:
20+
- ./data/mongo:/data/db:delegated
21+
ports:
22+
- 27017:27017
23+
24+
volumes:
25+
node_modules:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"start": "NODE_ENV=production node dist/src/apps/mooc_backend/server",
1919
"build": "npm run build:clean && npm run build:tsc && npm run build:di",
2020
"build:tsc": "tsc -p tsconfig.prod.json",
21-
"build:di": "copy 'src/**/*.yaml' dist/src",
21+
"build:di": "copy 'src/**/*.{json,yaml}' dist/src",
2222
"build:clean": "rm -r dist; exit 0"
2323
},
2424
"dependencies": {

src/apps/mooc_backend/config/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const convictConfig = convict({
1111
url: {
1212
doc: 'The Mongo connection URL',
1313
format: String,
14-
env: 'MONGO_URL'
14+
env: 'MONGO_URL',
15+
default: 'mongodb://mongo:27017/dev'
1516
}
1617
}
1718
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

0 commit comments

Comments
 (0)