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

Hooks for executing custom scripts #535

Closed
FabianKramm opened this issue May 6, 2019 · 11 comments
Closed

Hooks for executing custom scripts #535

FabianKramm opened this issue May 6, 2019 · 11 comments
Assignees
Labels
area/building-images Issues related to building Docker images area/config Issues related to the config kind/feature New feature or feature request

Comments

@FabianKramm
Copy link
Collaborator

It can be helpful to run user-defined commands/scripts after or before certain pipeline steps. This allows more customization of the pipeline and gives the user more freedom of integrating devspace into his own pipeline or use devspace as the primary pipeline tool.

@FabianKramm FabianKramm added kind/feature New feature or feature request priority/longterm area/building-images Issues related to building Docker images area/config Issues related to the config labels May 6, 2019
@FabianKramm FabianKramm self-assigned this May 6, 2019
@musicformellons
Copy link
Contributor

Yeah, that would be great. I am now trying some scripting solution. Any idea how to script the pod selection? See also this.

@FabianKramm
Copy link
Collaborator Author

FabianKramm commented May 8, 2019

@musicformellons for which command do you try to automatically select a pod? Usually the commands have additional flags that allow you to specify a pod and prevent a select, if not we could add the parameter to the command where you need it

@musicformellons
Copy link
Contributor

@FabianKramm Ah, thanks, I found the flags and now indeed can get into my containers without the select! That's nice. When I am at the prompt of my container I can no longer script anything it seems, I am trying (with tilix terminal) e.g.:
tilix -e bash -c 'cd /myapp; devspace enter -c mycontainer -n default -l app=myapp-pod; sleep 5; cd /folder_on_my_container; $SHELL'
But it stops at the container prompt and does not run the cd /folder_on_my_container. Any suggestions?

@LukasGentele
Copy link
Contributor

Hi @musicformellons! I just took a look at this script. For me, the current behavior seems correct but probably not what you intend to do with this script.

From what I see the script does the following within the tilix shell:

  1. Switch to /myapp
  2. Run devspace enter
  3. sleep 5 seconds
  4. ....

Your issue is that 3. and the rest will never be executed. The reason for this is that 2. "devspace enter" waits for an input and 3. can never be executed until the "devspace enter" process terminates. Are you trying to run 3., 4., ... within the terminal of the container or on your local computer?

Let me know what your script is meant to do and I will probably be able to help you with this.

@musicformellons
Copy link
Contributor

@LukasGentele On the terminal of the container!

@LukasGentele
Copy link
Contributor

Ok, got it. If you want to run "devspace enter" and then execute something within the container terminal, you can provide it as a argument to the command. So, I would change your code like this:

tilix -e bash -c 'cd /myapp; devspace enter -c mycontainer -n default -l app=myapp-pod bash -c "sleep 5; cd /folder_on_my_container; $SHELL"'

the bash -c "sleep 5; cd /folder_on_my_container; $SHELL" as an argument to devspace enter opens the command bash just like you open tilix and passes the 3 commands sleep, cd, and $SHELL with the -c flag to this shell within the container. Does this work as intended? @musicformellons

FabianKramm added a commit that referenced this issue May 9, 2019
@musicformellons
Copy link
Contributor

musicformellons commented May 9, 2019

Ha! I tried similar things before but gave up on it as I did not get it working, but now I got it working!! With three small adjustments to your line. Working line is:
tilix -e bash -c 'cd /myapp; devspace enter -c mycontainer -n default -l app=myapp-pod -- bash -c "sleep 5; cd ./folder_on_my_container; $SHELL"; $SHELL'

So I added -- before bash, and a . in front of the foldername and added the ; $SHELL at the end.
Now that I have that out of the way, my following requirement would be to have multiple of these lines, but make them synchronous. So I would like to first have one server started up using the terminal command we just got, and when that runs, have a second one start up with a similar terminal command. Any idea how to go about that?

@musicformellons
Copy link
Contributor

I would think the same approach would work on the devspace dev command, but it stops and does not run the commands in the container. Any idea why?

@musicformellons
Copy link
Contributor

Actually, after correcting a typo it also works with devspace dev command.

@LukasGentele
Copy link
Contributor

Great! Regarding your question in "my following requirement would be to have multiple of these lines, but make them synchronous..." - you can run several tasks in parallel in the background by using "&" at the end of the line. So this would run 3 commands in parallel:

devspace enter ... &;
devspace enter ... &;
devspace enter ... &;

They run in parallel but are not necessarily synchronized. They are just run in the background. I hope that helps. I think we should not continue this discussion in the comments of this issue as this is not directly related to this issue about hooks for DevSpace CLI. Feel free to ping me on slack if you have any further questions about shell scripting.

@FabianKramm
Copy link
Collaborator Author

Is part of version v3.5.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/building-images Issues related to building Docker images area/config Issues related to the config kind/feature New feature or feature request
Projects
None yet
Development

No branches or pull requests

3 participants