GithubHelp home page GithubHelp logo

dfsync's Introduction

๐Ÿ”„ dfsync

A tool to intelligently synchronize files and direcotries to remote machines.

dfsync watches local files and folders for changes and copies those changes to a remote machine. This is super useful for software development when you have to edit on one machine but must run the code on a second machine (likely on some specialized hardware).

Usage scenarios

Say you have some sensors attached to a Raspberry PI board, dfsync copies the python code you are editing on your developer machine (a laptop) to the Raspberry PI. It monitors your source folder for changes and every time you save a file, it syncs that file to the Raspberry PI, quickly and automatically.

What if you are developing apps targeting deployment in a kubernetes cluster? Every time you change a file, dfsync copies that source code file into the container. Sure you could use use port-forwarding or some of the other development tools or you could use dfsync a light-weight alternative, no server component, no priviledged DaemonSet required.

So, you are doing AI/ML development and you have a big GPU/TPU server somewhere and you have to edit your code on one machine and run it on the big server, dfsync has you covered, every time you save a file, it automatically syncs that file to the big server. The code is in sync, now it's up to you to run it.


๐Ÿ“ฆ Installation

  • Requirements
    • Python Version
      $ python --version
      Python 3.8  # Python version 3.8 or above are required
    • Install using pip package manager
      $ pip install dfsync

๐Ÿ”จ Development

  • Build and install dfsync on your computer
    • Make Sure poetry dependency management and built tool is install in your System.
    • You can find the installation instruction and other information about poetry by clicking on link.
    • After Installation of poetry verify that it's available
      $ poety --version
      Poetry (version 1.5.1)
    • Clone the dfsync repository
      $ git clone https://github.com/MihaiBalint/dfsync.git
      $ cd dfsync
      $ poety install # install project dependencies
      $ poetry shell
      (.venv) $ dfsync --help  # Try running dfsync from the development venv that poerty created
      (.venv) $ exit. # exit the dfsync development venv
      $ poety build   # build and generate arch neutral dfsync-<version>-py3-none-any.whl and an archive tar.gz file.
    • If the build completed without errors and you are in the dfsync source dir, install the build on your system's python using pip command
      $ pip install ./dist/dfsync-0.4.2-py3-none-any.whl   # Version might be different

๐Ÿ“ˆ Command-line usages Example

Example Usages:
  1. Watch src directory and sync changes to a destination on the local file system.
    $ dfsync [src] [destination]
    # OR
    $ dfsync [destination] # Current directory will be treated as [src]
    $ dfsync src /home/user/absolute/path/to/target/dir # sync src directory to destination.
            Destination, rsync: '/home/user/Desktop/'
            Watching dir(s): 'dist/'; press [Ctrl-C] to exit
    $ dfsync . ../../relative/path/to/target/dir  # Sync current directory (.) into relatively mentioned path.
            Destination, rsync: '../../Desktop/'
            Watching dir(s): '.'; press [Ctrl-C] to exit
    $ dfsync ../../relative/path/to/target/dir # if source directory is omitted, current directory is considered at src directory.
  2. Watch [src] [dir] and sync changes to a remote target using ssh
    $ dfsync src user@target-host:/home/user/absolute/paths/to/remote/host/dir # [src] to [dest] absolute directory.
    # OR
    $ dfsync build user@target-host:~/relative/path/to/user/home # [src=build] to [relative path]
  3. Watch a directory [src] and sync changes to kubernetes pod/containers using the given image name
    $ dfsync src kube://image-name-of-awesome-api:/home/user/awesome-api # 
    # OR
    $ dfsync kube://quay.io/project/name-of-container-image:/home/path/within/container/awesome-api

๐Ÿ‘€ Command-line Reference

$ dfsync --help
Usage: dfsync [OPTIONS] [SOURCE]... [DESTINATION]

  Watches a folder for changes and propagates all file changes to a
  destination.

  SOURCE is a path to the folder that dfsync will monitor for changes (or
  current dir if missing)

  DESTINATION is a destination path / psuedo-url

  Example usages:

  1. Watch a dir and sync changes to a target on the local filesystem
     dfsync src /home/user/absolute/paths/to/target/dir
     dfsync . ../../relative/path/to/target/dir
     dfsync ../../relative/path/to/target/dir (if source_dir is omitted, will watch the current dir)

  2. Watch a dir and sync changes to a remote target using ssh
     dfsync src user@target-host:/home/user/absolute/paths/to/remote/host/dir
     dfsync build user@target-host:~/relative/path/to/user/home

  3. Watch a dir and sync changes to kubernetes pod/containers using the given image name
     dfsync src kube://image-name-of-awesome-api:/home/user/awesome-api
     dfsync kube://quay.io/project/name-of-container-image:/home/path/within/container/awesome-api

  dfsync is:
  * git-aware: changes to git internals, files matching .gitignore patterns and untracked files will be ignored
  * editor-aware: changes to temporary files created by source code editors will be ignored
  * transparent: every action is diligently logged in the console

Options:
  --supervisor / --no-supervisor  Try to install supervisor in container
  --kube-host TEXT                Kubernetes api host server address/hostname
  --pod-timeout INTEGER           Pod reconfiguration timeout (default is 30
                                  seconds)

  --help                          Show this message and exit.

๐Ÿ“„ Pyproject.toml configuration reference

Instead of passing a large number of arguments from the command line, these can be added to a pyproject.toml file located in the source dir. See example below:

[tool.dfsync.configuration]
destination = "kube://quay.io/project/app-image-prefix:/home/app-location"
pod_timeout = 30
additional_sources = ["../api-client-lib", "../domain-lib"]
container_command = "./.venv/bin/uvicorn --host 0 --reload myproject:app"

dfsync's People

Contributors

cristibaca avatar mihaibalint avatar rajendrakumaryadav avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

dfsync's Issues

Incorrect pods selection for sync when multiple pods have a name starting with the same string

We have two projects that result in images on harbor with the following names:
/central-hub
/central-hubspot-enricher

Now, if we do a dfsync to sync central-hub, we will actually replace the code on both projects. It seems like dfsync checks only that the image name on Kubernetes starts with the specified image name not that it is exactly what we specified as first parameter.

Add ability to sync untracked git files

I was working on a new feature with uncommitted changes and found out only after a while that a new untracked file was not syncing. By looking at dfsync sync --help it doesn't seem to be possible to sync untracked files.

Add usage instructions

Awesome work, thanks a lot!

Can we get info on stuff such as:

  • installation
  • cmdline usage examples
  • cmdline reference
  • tool configuration
    ?

Thanks a lot for your hard work, this is very helpful!

I am getting python threading error related to FileChangedEventHandler

Watching dir(s): '.'; press [Ctrl-C] to exit

Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.9/threading.py", line 973, in _bootstrap_inner
self.run()
File "/home/.../.venv/lib/python3.9/site-packages/watchdog/observers/api.py", line 199, in run
self.dispatch_events(self.event_queue, self.timeout)
File "/home/.../.venv/lib/python3.9/site-packages/watchdog/observers/api.py", line 372, in dispatch_events
handler.dispatch(event)
File "/home/.../.venv/lib/python3.9/site-packages/watchdog/events.py", line 282, in dispatch
self.event_dispatch_mapevent.event_type
AttributeError: 'FileChangedEventHandler' object has no attribute 'event_dispatch_map'

Testing with multiple python version

It's likely that developers will want to use dfsync in various environments with various python versions, it would be great if we could use something like tox to at least run the test suite with the most popular versions of python (like those shipped by OS distributions)

Enforce permissions for `~/.kube/config`

~/.kube/config is a sensitive file, it's permissions should be at least equivalent to "chmod go-rwx"

Without this, kubectl will also complain when trying tu use that file

Quality of life improvements

  • Add command to print tool version + the latest available version
  • Generate a warning message if using an outdated version of dfsync
  • Enable running from within the project folder

Integrate with pyproject.toml

it turns out that the length and number of command line arguments keeps growing, it would be more user friendly to move some of that into the tools section of pyproject.toml

Deal with "Conflict" responses from kubernetes

Sometimes multiple processes will try and modify pods resulting in a "Conflict" response from the kubernetes API.

Usually the fix for this is to retry the update. Right now, a traceback is generated and dfsync exits.

Getting `container isn't ready: Unknown` error

When trying to dfsync a container that for some reason has crashed (e.g. previously synced changes contained some bug), I get this error:

<path-to-file> will not sync in <container-name>, container isn't ready: Unknown

As a result, I can't sync files any more (unless I press Ctrl-C or X and let dfsync restore the original container).

Note: This issue was created prior to the release of 0.4.6.

Feature roadmap

  • Run kubectl exec in the same shell as dfsync to avoid having to switch between terminals
  • Detect and start the app process automatically after having synced the code in the container
  • Implement key-bindings (similar to screen) for useful commands: force full sync, restart the app, etc

Automated unit testing

There are many cases to cover when syncing file changes to a destination so a minimal test suite would be a good thing

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.