-
Notifications
You must be signed in to change notification settings - Fork 222
Add docker-compose with external dependencies #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e34995f
f2d217d
58a5343
9f264e2
d87a55f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.dockerignore | ||
.git | ||
docker-compose.yml | ||
Dockerfile | ||
node_modules | ||
dist | ||
data | ||
logs |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ dist/ | |
.tmp | ||
logs/ | ||
src/Contexts/Mooc/Courses/infrastructure/persistence/courses.* | ||
data |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FROM node:12.16.3-slim | ||
|
||
WORKDIR /code | ||
|
||
COPY package.json package-lock.json ./ | ||
RUN npm install |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
Comment on lines
+6
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very good one! 🙌 |
||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about adding the Node dependencies management to the Makefile in order to make it easier to handle them from within the Node Docker container? You have an example in the PHP repository. In that case, we even create a temporal Docker container to run Composer (the PHP dependencies manager). This way we don't need to install Composer in the PHP container, but because Node integrates it all in the same service, we could simplify it just directly interacting with the Node Container. The goal behind this would be to ensure we install/update dependencies using the very same Node version that executes our code in an easy way (just a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea! We will take a look and include that possibility here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if I am missing something, but I think we are getting the requirement of ensuring that we install the dependencies using the same Node version every time we launch a Example: # 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' Setting the build as a dependency of the Does it make sense for you? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it. 🎩