Only mount coffee and needed files into Docker so js isn't written back to local system

This commit is contained in:
James Allen 2017-11-24 16:28:24 +00:00
parent 492b37aa6e
commit 49057a5ab7
5 changed files with 80 additions and 29 deletions

View file

@ -73,3 +73,4 @@ Gemfile.lock
app/views/external
/modules/
docker-shared.yml

View file

@ -8,38 +8,46 @@ all: install test
@echo " make install to set up the project dependencies (in docker)"
@echo " make test to run all the tests for the project (in docker)"
add:
add: docker-shared.yml
$(NPM) install --save ${P}
add_dev:
add_dev: docker-shared.yml
$(NPM) install --save-dev ${P}
install:
install: docker-shared.yml
$(NPM) install
clean:
rm app.js
rm -r app/js
rm -r test/unit/js
rm -r test/acceptance/js
clean: docker-shared.yml
rm -f app.js
rm -rf app/js
rm -rf test/unit/js
rm -rf test/acceptance/js
# Deletes node_modules volume
docker-compose down --volumes
# Delete after docker-compose command
rm -f docker-shared.yml
# Need regenerating if you change the web modules you have installed
docker-shared.yml:
bin/generate_volumes_file
test: test_unit test_acceptance
test_unit:
test_unit: docker-shared.yml
docker-compose -f docker-compose.yml ${DOCKER_COMPOSE_FLAGS} run --rm test_unit npm run test:unit -- ${MOCHA_ARGS}
test_acceptance: test_acceptance_start_service test_acceptance_run test_acceptance_stop_service
test_acceptance_start_service:
test_acceptance_start_service: docker-shared.yml
docker-compose -f docker-compose.yml ${DOCKER_COMPOSE_FLAGS} up -d test_acceptance
test_acceptance_stop_service:
docker-compose -f docker-compose.yml ${DOCKER_COMPOSE_FLAGS} stop test_acceptance
test_acceptance_stop_service: docker-shared.yml
docker-compose -f docker-compose.yml ${DOCKER_COMPOSE_FLAGS} stop test_acceptance redis mongo
test_acceptance_run:
test_acceptance_run: docker-shared.yml
docker-compose -f docker-compose.yml ${DOCKER_COMPOSE_FLAGS} exec -T test_acceptance npm run test:acceptance -- ${MOCHA_ARGS}
.PHONY:
add install update test test_unit test_acceptance \
all add install update test test_unit test_acceptance \
test_acceptance_start_service test_acceptance_stop_service \
test_acceptance_run

View file

@ -0,0 +1,26 @@
#!/usr/bin/env python2
from os import listdir
from os.path import isfile, isdir, join
volumes = []
for module in listdir("modules/"):
if module[0] != '.':
if isfile(join("modules", module, 'index.coffee')):
volumes.append(join("modules", module, 'index.coffee'))
for directory in ['app/coffee', 'app/views', 'public/coffee', 'test/unit/coffee', 'test/acceptance/coffee']:
if isdir(join("modules", module, directory)):
volumes.append(join("modules", module, directory))
volumes_string = map(lambda vol: "- ./" + vol + ":/app/" + vol + ":ro", volumes)
volumes_string = "\n ".join(volumes_string)
with open("docker-shared.template.yml", "r") as f:
docker_shared_file = f.read()
docker_shared_file = docker_shared_file.replace("MODULE_VOLUMES", volumes_string)
with open("docker-shared.yml", "w") as f:
f.write(docker_shared_file)

View file

@ -5,25 +5,21 @@ volumes:
services:
npm:
image: node:6.9.5
volumes:
- .:/app
- node_modules:/app/node_modules
working_dir: /app
extends:
file: docker-shared.yml
service: app
command: npm install
test_unit:
image: node:6.9.5
volumes:
- .:/app
- node_modules:/app/node_modules
working_dir: /app
extends:
file: docker-shared.yml
service: app
command: npm run test:unit
test_acceptance:
image: node:6.9.5
volumes:
- .:/app
- node_modules:/app/node_modules
extends:
file: docker-shared.yml
service: app
environment:
REDIS_HOST: redis
MONGO_HOST: mongo
@ -32,7 +28,6 @@ services:
depends_on:
- redis
- mongo
working_dir: /app
command: npm run start
redis:

View file

@ -0,0 +1,21 @@
version: "2"
services:
app:
image: node:6.9.5
volumes:
- ./package.json:/app/package.json
- ./npm-shrinkwrap.json:/app/npm-shrinkwrap.json
- node_modules:/app/node_modules
- ./bin:/app/bin
- ./public:/app/public
- ./app.coffee:/app/app.coffee:ro
- ./app/coffee:/app/app/coffee:ro
- ./app/templates:/app/app/templates:ro
- ./app/views:/app/app/views:ro
- ./config:/app/config
- ./test/unit/coffee:/app/test/unit/coffee:ro
- ./test/acceptance/coffee:/app/test/acceptance/coffee:ro
- ./test/smoke/coffee:/app/test/smoke/coffee:ro
MODULE_VOLUMES
working_dir: /app