Skip to content
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

Setup a fs monitor inside the container #209

Closed
rodrigoaguilera opened this issue Jan 10, 2017 · 10 comments
Closed

Setup a fs monitor inside the container #209

rodrigoaguilera opened this issue Jan 10, 2017 · 10 comments
Labels

Comments

@rodrigoaguilera
Copy link

I got docker-sync working and I use the two-way strategy with unison
When I change files on the mac host the get synchronized to the container but when I change files inside the container I have to run "docker-sync sync" to get them on my docker host.

Is this the normal behavior?
If not, How can I debug what is happening?
If yes, How can I setup a monitor inside the container?

Thank you

@EugenMayer
Copy link
Owner

@rodrigoaguilera this should actually not be the case, thats exactly what "2 way means". @mickaelperrin do you have a hint here how to debug this?

@rodrigoaguilera i can at least tell you, for me, it is working both ways.

Are you sure you did not miss-configure the excludes somehow? Could you pastbin you docker-sync.yml and explain your setup?

Thanks

@mickaelperrin
Copy link
Contributor

Which version of docker sync are you using ?

Could you paste your configuration?

It makes me think you're using the old unison strategy and not the new one which is using the unison unox pattern.

@rodrigoaguilera
Copy link
Author

Thanks for the answer

I'm using MacOS sierra with docker for mac beta and docker-sync 0.1.5

I installed unison-fsmonitor and:
pip install macfsevents
brew install fswatch
Are all needed? macfsevents and unison-fsmonitor are not mentioned in the wiki, only when I was running docker-sync in the command line.

my sync strategy is "unison". should I write "unox"?. Is not very clear on the strategy wiki or the migration guide(I didn't migrate, I started fresh from 0.1.5)

options:
  # default: docker-compose.yml if you like, you can set a custom location (path) of your compose file like ~/app/compose.yml
  compose-file-path: 'docker-compose.yml'

  # 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

  # if its there, it gets used, if you name it explicitly, it HAS to exist
  #compose-dev-file-path: 'docker-compose-dev.yml'

  # optional, activate this if you need to debug something, default is false
  # IMPORTANT: do not run stable with this, it creates a memory leak, turn of verbose when you are done testin
  verbose: false

  # ADVANCED: default:eugenmayer/rsync -  the image to use for the rsync container. Do not change this until you exactly know, what you are doing
  # optional, default eugenmayer/rsync, you cannot just use "some unison" container, you entrypoint needs features, check the Dockerfiles
  rsync_image: 'eugenmayer/rsync'

  # ADVANCED: default:leighmcculloch/unison -  the image to use for the unison container. Do not change this until you exactly know, what you are doing
  # optional, default eugenmayer/unison, you cannot just use "some unison" container, you entrypoint needs features, check the Dockerfiles
  unison_image: 'eugenmayer/unison'

  # optional, default auto, can be docker-sync, thor or auto and defines how the sync will be invoked on the cli. Mostly depending if your are using docker-sync solo, scaffolded or in development ( thor )
  cli_mode: 'auto'

syncs:
  # IMPORTANT: this name must be unique and should NOT match your real application container name!
  drupal-sync:
    # enable terminal_notifier. On every sync sends a Terminal Notification regarding files being synced. ( Mac Only ).
    # good thing in case you are developing and want to know exactly when your changes took effect.
    # be aware in case of unison this only gives you a notification on the initial sync, not the syncs after changes.
    notify_terminal: true

    # which folder to watch / sync from - you can use tilde (~), it will get expanded. Be aware that the trailing slash makes a difference
    # if you add them, only the inner parts of the folder gets synced, otherwise the parent folder will be synced as top-level folder
    src: './'

    # which destination on the sync-container. Since you will use volumes_from to mount this, this should match your code-deployment location in the real container
    dest: '/var/www/html'

    # when a port of a container is exposed, on which IP does it get exposed. Localhost for docker for mac, something else for docker-machine
    sync_host_ip: '127.0.0.1'

    # should be a unique port this sync instance uses on the host to offer the rsync service on
    sync_host_port: 10871

    # optional, a list of excludes for rsync - see rsync docs for details
    sync_excludes: ['Gemfile.lock', 'Gemfile', 'config.rb', 'sass-cache/', 'bower.json', 'Gruntfile*', 'bower_components/', '.gitignore', '.git/', '*.coffee']

    # use this to change the exclude syntax.
    # Path: you match the exact path ( nesting problem )
    # Name: If a file or a folder does match this string ( solves nesting problem )
    # Regex: Define a regular expression
    # none: You can define a type for each sync exclude, so sync_excludes: ['Name .git', 'Path Gemlock']
    #
    # for more see http://www.cis.upenn.edu/~bcpierce/unison/download/releases/stable/unison-manual.html#pathspec
    sync_excludes_type: 'Path'

    # optional: use this to switch to rsync verbose mode
    #sync_args: '-v'

    # optional, a list of regular expressions to exclude from the fswatch - see fswatch docs for details

    # optional, default can be either rsync or unison See Strategies in the wiki for explanation
    sync_strategy: 'unison'

    # optional, use this to map the files to a specific user on sync. Helps fixing permissions. You can use names and uids
    #sync_user: 'rodrigoaguilera'

    # this does not user groupmap but rather configures the server to map
    # optional: usually if you map users you want to set the user id of your application container here
    #sync_userid: '5000'

    # optional, use this to map the files to a specific group on sync. Helps fixing permissions, You can use names and guids
    #sync_group: 'staff'

    # optional: usually if you map groups you want to set the group id of your application container here
    # this does not user groupmap but rather configures the server to map
    #sync_groupid: '6000'

    watch_excludes: ['.*/.git', '.*/node_modules', '.*/bower_components', '.*/sass-cache', '.*/.sass-cache', '.coffee', '.scss', '.sass', '.gitignore']

    # optional: use this to switch to fswatch verbose mode
    watch_args: '-v'

    # optional: default is fswatch, if set to disable, no watcher will be used and you would need to start the sync manually
    watch_strategy: 'fswatch'

my docker-compose

version: "2"
services:
  web:
    build: docker/drupal
    #  volumes:
    #    - .:/var/www/html
    volumes_from:
      - container:drupal-sync:rw
    ports:
    - "80:80"
    restart: always
volumes:
  drupal-sync:
    external: true

The only thing weird I notice is when I do CTRL-C on the docker-sync-stack start I can read:
error Stopping failed of drupal-sync:

Thank you for looking, without this tool I won't be using docker :)

@rodrigoaguilera
Copy link
Author

BTW my use case is editing code on the host machine but I run some commands on the container that change or generate code that I need on the repo like composer.lock, .po translations

@EugenMayer
Copy link
Owner

That is perfectly valid, I do the same with bundle install and the gemfile.lock. thus it works in general

@andyvpm
Copy link

andyvpm commented Jan 18, 2017

I also have the same issue. If I manually run docker-sync sync then my changes are synced. Otherwise I do not get syncing back from the container to the host.

@rodrigoaguilera
Copy link
Author

I'm using docker sync daily and syncing manually when I do changes on the container but I've seen it working a couple of times. Completely random.

@EugenMayer
Copy link
Owner

we are using it daily with a pretty huge codebase ( 20k+ ) and actually it seems to work pretty solid, though i admit, the back-sync case is rare and probably not happening too often

@mickaelperrin
Copy link
Contributor

mickaelperrin commented Jan 18, 2017

@rodrigoaguilera Thanks for posting your detailed configuration. I indeed successfully reproduced the issue.

The problem is simple, you're forcing the fswatch as watcher strategy, simply comment the watch_strategy line to automatically use the unison strategy which implements a native unison watcher in the container.

Please close the issue if it worked for you.

@rodrigoaguilera
Copy link
Author

Thank you so much @mickaelperrin . Now everything works like a charm :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants