pressly / sup

Super simple deployment tool - think of it like 'make' for a network of servers
https://pressly.github.io/sup
MIT License
2.48k stars 178 forks source link

Uploading with rsync #68

Open eduardonunesp opened 8 years ago

eduardonunesp commented 8 years ago

Hey everyone, I managed to upload my src files using rsync instead using the native option (tar), so I want to show my Supfile and to share my idea, I hope that action bring new ideas and show how much Sup is a cool and flexible option.

version: 0.3

env:
  TMP_DIR: /tmp/mydir
  DEV_USER: docker
  DEV_HOST: 192.168.99.100

networks:
  local:
    hosts:
      - localhost

  dev:
    hosts:
      - docker@192.168.99.100

commands:
  ping:
    desc: Print uname and current date/time.
    run: uname -a; date

  pre-build:
    run: mkdir $TMP_DIR; exit 0

  rsync:
    local: rsync -aczP src/ $DEV_USER@$DEV_HOST:$TMP_DIR

  remote-test:
    run: $TMP_DIR/test.sh

targets:
  deploy:
    - ping
    - pre-build
    - rsync
    - remote-test
docker@192.168.99.100:22 | + uname -a
docker@192.168.99.100:22 | + date
docker@192.168.99.100:22 | Linux dev 4.1.19-boot2docker #1 SMP Mon Mar 7 17:44:33 UTC 2016 x86_64 GNU/Linux
docker@192.168.99.100:22 | Thu Apr 14 02:32:29 UTC 2016
docker@192.168.99.100:22 | + mkdir /tmp/mydir
docker@192.168.99.100:22 | + exit 0
eduardonunesp@localhost | + rsync -aczP src/ docker@192.168.99.100:/tmp/mydir
eduardonunesp@localhost | building file list ...
2 files to considerhost |  0 files...
eduardonunesp@localhost | ./
eduardonunesp@localhost | test.sh
          45 100%    0.00kB/s    0:00:00 (xfer#1, to-check=0/2):00
eduardonunesp@localhost |
eduardonunesp@localhost | sent 210 bytes  received 48 bytes  172.00 bytes/sec
eduardonunesp@localhost | total size is 45  speedup is 0.17
docker@192.168.99.100:22 | + /tmp/mydir/test.sh
docker@192.168.99.100:22 | REMOTE DATE Thu Apr 14 02:32:30 UTC 2016

Important to note: rsync command is working in local src directory and the ssh address is using environment variables (created inside the Supfile). Well, it would be cool if we had some way to get array of hosts like we have the SUP_NETWORK for instance.

eduardonunesp commented 8 years ago

About the current host used, never mind, I found the SUP_HOST variable, which inform the current host. Just need to add in README :neckbeard:

Unfortunately the SUP_HOST doesn't make difference in this case, because when rsync runs the current host is localhost. :cry:

eduardonunesp commented 8 years ago

Is it possible to create an intermediary command, just to inject variables at the global ? something like:

  trick:
    export: TRICK_ENV=$SUP_HOST

  rsync:
    local: rsync -aczP src/ $TRICK_ENV:$TMP_DIR

targets:
  deploy:
    - trick
    - rsync

I know that command export doesn't exists, but it's just an option to set some variable at runtime. Actually if I have more then one host it need to have an option to run the local rsync for each host as well.

hauleth commented 8 years ago

It would be great to have option to use rsync in upload, like:

commands:
    upload:
        desc: Upload dist files to all hosts
        upload:
          - src: ./dist
            dst: /tmp/
        uploader: rsync
kulak commented 7 years ago

I am interested in being able to pass name of the current remote computer, so I command like the following can be written against all computers and not hardcoded to one:

rsync:
  local: rsync -aczP src/ $each_remote_computer_name:$HOME/blah

I could not figure out if there is already a built-in variable that reflects the name of current remote computer connection.