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

Change working directory for hosts #110

Open
emil-nasso opened this issue Apr 10, 2017 · 4 comments
Open

Change working directory for hosts #110

emil-nasso opened this issue Apr 10, 2017 · 4 comments

Comments

@emil-nasso
Copy link

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
Copy link
Collaborator

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

@emil-nasso
Copy link
Author

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
Copy link
Collaborator

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

@seguidor777
Copy link

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

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

No branches or pull requests

3 participants