Skip to content

Commit 326487c

Browse files
committed
enable docker-sync-stack to understand docker-compose-dev and do adjust our example reflecting that
1 parent 53a1786 commit 326487c

File tree

5 files changed

+58
-28
lines changed

5 files changed

+58
-28
lines changed

example/docker-compose-dev.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Development environment reusing production and just adding mounts for docker-sync
2+
version: "2"
3+
services:
4+
someapp:
5+
environment:
6+
RAILS_ENV: 'development'
7+
volumes_from:
8+
- container:fullexample-sync:rw # will be mounted on /var/www
9+
otherapp:
10+
volumes_from:
11+
- container:simpleexample-sync:rw # will be mounted on /app/code
12+
13+
volumes:
14+
fullexample-sync:
15+
external: true
16+
simpleexample-sync:
17+
external: true

example/docker-compose.yml

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
1+
# production docker-compose file without any reference to docker-sync
2+
13
version: "2"
24
services:
35
someapp:
46
image: alpine
57
container_name: 'fullexample_app'
6-
# that the important thing
7-
volumes_from:
8-
- container:fullexample-sync:rw # will be mounted on /var/www
98
command: ['watch', '-n1', 'cat /var/www/somefile.txt']
109
otherapp:
1110
image: alpine
1211
container_name: 'simpleexample_app'
13-
command: ['watch', '-n1', 'cat /app/code/somefile.txt']
14-
# thats the important thing
15-
volumes_from:
16-
- container:simpleexample-sync:rw # will be mounted on /app/code
17-
18-
# thats the important thing
19-
volumes:
20-
fullexample-sync:
21-
external: true
22-
simpleexample-sync:
23-
external: true
12+
command: ['watch', '-n1', 'cat /app/code/somefile.txt']

example/docker-sync.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# for a simpler example, see the boilerplate at https://github.com/EugenMayer/docker-sync-boilerplate
22
options:
3-
# default: docker-compose.yml if you like, you can set a custom location (path) of your compose file
3+
# optional, default: docker-compose.yml if you like, you can set a custom location (path) of your compose file
44
compose-file-path: 'docker-compose.yml'
5+
# optional, default: docker-compose-dev.yml if you like, you can set a custom location (path) of your compose file. Do not set it, if you do not want to use it at all
6+
# if its there, it gets used, if you name it explicitly, it HAS to exist
7+
compose-dev-file-path: 'docker-compose-dev.yml'
58
# optional, activate this if you need to debug something, default is false
69
verbose: true
710
# ADVANVED: default:eugenmayer/rsync - the image to use for the rsync container. Do not change this until you exactly know, what you are doing

lib/docker-sync/compose.rb

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,38 @@ class ComposeManager
66
@global_options
77
def initialize(global_options)
88
@global_options = global_options
9-
compose_file_path = 'docker-compose.yml'
9+
10+
### production docker-compose.yml
11+
compose_files = [File.expand_path('docker-compose.yml')]
1012
if @global_options.key?('compose-file-path')
1113
path = File.expand_path(@global_options['compose-file-path'])
1214
unless File.exist?(path)
1315
raise("Your referenced docker-compose file in docker-sync.yml was not found at #{@global_options['compose-file-path']}")
1416
end
15-
compose_file_path = @global_options['compose-file-path']
17+
compose_files = [path] # replace
18+
end
19+
20+
### development docker-compose-dev.yml
21+
if @global_options.key?('compose-dev-file-path')
22+
# explicit path given
23+
path = File.expand_path(@global_options['compose-dev-file-path'])
24+
unless File.exist?(path)
25+
raise("Your referenced docker-compose-dev file in docker-sync.yml was not found at #{@global_options['compose-dev-file-path']}")
26+
end
27+
say_status 'ok',"Found explicit docker-compose-dev.yml and using it from #{@global_options['compose-dev-file-path']}", :green
28+
compose_files.push @global_options[path] # add
29+
else
30+
# try to find docker-compose-dev.yml
31+
e = compose_files.to_enum
32+
production_compose_file = File.expand_path(e.peek)
33+
working_dir = File.dirname(production_compose_file)
34+
compose_dev_path = "#{working_dir}/docker-compose-dev.yml"
35+
if File.exist?(compose_dev_path)
36+
say_status 'ok',"Found implicit docker-compose-dev.yml and using it from #{compose_dev_path}", :green
37+
compose_files.push compose_dev_path
38+
end
1639
end
17-
@compose_session = Docker::Compose::Session.new(dir:'./', :file => compose_file_path)
40+
@compose_session = Docker::Compose::Session.new(dir:'./', :file => compose_files)
1841
end
1942

2043
def run

tasks/stack/stack.thor

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,15 @@ class Stack < Thor
4444

4545
begin
4646
compose_thread.join
47-
#@sync_manager.join_threads
48-
rescue SystemExit, Interrupt
49-
say_status 'shutdown', 'Shutting down...', :blue
50-
51-
@sync_manager.stop
52-
@compose_manager.stop
53-
rescue Exception => e
54-
55-
puts "EXCEPTION: #{e.inspect}"
56-
puts "MESSAGE: #{e.message}"
47+
#@sync_manager.join_threads
48+
rescue SystemExit, Interrupt
49+
say_status 'shutdown', 'Shutting down...', :blue
5750

51+
@sync_manager.stop
52+
@compose_manager.stop
53+
rescue Exception => e
54+
puts "EXCEPTION: #{e.inspect}"
55+
puts "MESSAGE: #{e.message}"
5856
end
5957
end
6058

0 commit comments

Comments
 (0)