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

Change working directory for hosts #110

Open emil-nasso opened 7 years ago

emil-nasso commented 7 years ago

I think it would be very nice to be able to change the default working directory for a network.

Most of my experiments/mini-projects run on one server (that is running docker containers). I have one user that i SSH with to manage all these projects. Each project is in a directory in that users home directory.

Take a look at this example:

networks:
  local:
    hosts:
     - localhost

commands:
  chdir:
    run: cd /tmp && pwd
  echo-dir:
    run: pwd
  echo-date:
    run: pwd && date 

targets:
  all:
    - chdir
    - echo-dir
    - echo-date

Imagine I had some real commands there instead. Every time a command is run, it is done in a new session. Me changing the directory in the chdir command doesn't affect the other commands. It makes sense and I think it would be a bit chaotic if it wasn't like that. I'm not proposing to change that.

The fact is that the Sup files become messy though. I have to prefix every single command with cd /my/directory; .... And even worse, it breaks my local environment. I don't use the same directory structure there...

What I propose it this:

networks:
  local:
    hosts:
     - localhost
    workdir: /my/local/directory
  production:
    hosts:
     - api1.example.com
     - api2.example.com
    workdir: /my/production/directory

You specify working directory for each network. It is optional. If it is not specified, the behavior would continue to be exactly what it is today. Before sup runs each command it would change the directory to what is specified in workdir, if it exists.

It would help clean up my Supfile and it would make me possible to deploy to both localhost and production with the same file.

I would like to make this change. I'm willing to write the code, tests, documentation etc.

I just wanted to vent it here first, just to make sure I was proposing something that was already being worked on, was not wanted or if there are better solutions.

Let me know what you think!

VojtechVitek commented 7 years ago

I'm thinking of $SUP_PWD or $SUP_WORKDIR env var. But what would we do if the directory didn't exist?

emil-nasso commented 7 years ago

Do you mean that the user sets the $SUP_PWD and $SUP_WORKDIR with the -e flag when executing the sup binary and sup uses that to change directory?

I'm not sure what to do when the directory doesn't exist. We could just mkdir -p it but it feels safer to just print out an error message.

VojtechVitek commented 7 years ago

Yea, user could either pass the env var via -e flag or define the vars globally / per network in the Supfile.

seguidor777 commented 5 years ago

Hello, Is this feature still pending or is there another way to set the working directory? Thanks