Search code examples
sshmakefilelocal

How to "write" a makefile which performs actions locally then on the SSH connected VM?


I'm discovering a new stack (Python/Flask, Makefile, Pip...) instead of my usual Node/Express, Npm, package.json...).
Sorry then if my question is bit dumb.

I'm currently writing a Makefile that copy (scp) file on my VM...

build:
    ... some actions...
    scp -v build.tar.gz root@xxx.xxx.xxx.xxx:
    

... and then run automatically actions inside this very same VM...

    ssh root@xxx.xxx.xxx.xxx
    docker load -i build.tar.gz
    docker run -dp 80:5000 myimg

However, this second part doesn't work.
My makefile does connect via SSH, but doesn't after use the two last docker instructions.

How to "pass" these instructions for a fully automated script?
Thanks.


Solution

  • You can pass a command to be run as arguments to ssh. So you can use:

    ssh root@xxx.xxx.xxx.xxx docker load -i build.tar.gz
    ssh root@xxx.xxx.xxx.xxx docker run -dp 80:5000 myimg
    

    There are other ways to do it as well.