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

Add an .devspacerc file #1068

Closed
blairham opened this issue Apr 12, 2020 · 16 comments
Closed

Add an .devspacerc file #1068

blairham opened this issue Apr 12, 2020 · 16 comments
Labels
area/config Issues related to the config kind/design Must be conceptually designed kind/feature New feature or feature request

Comments

@blairham
Copy link

Is your feature request related to a problem?
No

Which solution do you suggest?
adding a .devspacerc file where you can put in things like namespace or context so you don't have to type it out on the CLI every time

Which alternative solutions exist?
the global flag --namespace and the --switch-context

Additional context
This would be very useful when working in multiple contexts at the same time and not have to constantly type this switches out.

/kind feature

@FabianKramm
Copy link
Collaborator

FabianKramm commented Apr 14, 2020

@blairham thanks for opening this issue! In general I like the idea, however I'm not sure how the .devspacerc should look like, did you try the devspace use namespace and devspace use context commands, they will change the namespace and context globally so you don't have to retype the context and namespace. Alternatively, for common flags for your project, you could also create a command like:

version: v1beta9
commands:
- name: deploysingle
  command: devspace deploy --deployments mydeployment

With the next devspace version, you are then also able to use variables for commands, which could be a good alternative as well.

@FabianKramm FabianKramm added area/config Issues related to the config kind/design Must be conceptually designed kind/feature New feature or feature request labels Apr 14, 2020
@LukasGentele
Copy link
Contributor

I think we could address this using defaultFlags for CLI commands that users can specify in devspace.yaml as suggested here: #977

@blairham
Copy link
Author

@FabianKramm yes, I have to switch both context and namespace each time or provide them on the CLI every time. So when I'm working on project A I would have to change, then I have to do something on project B I would again switch, then going back to project A, I would have to switch back yet again so on and so on.

I think either one of the solutions would be equivalent and would make it easier. However, one thing to keep in mind is there typically get checked in so how would we identify a user's space if they are all different?

@LukasGentele
Copy link
Contributor

@blairham -s would be sufficient for you, right? If you provide -s, DevSpace will switch context and namespace. So, if you set -s as default flag, you won't have to hard-code anything and will still able to push this to git and everybody will be able to switch back and forth between projects without having to explicitly provide the -s flag every time. That is your goal, right?

@blairham
Copy link
Author

I think that might actually do what I'm thinking, yes.

@LukasGentele
Copy link
Contributor

LukasGentele commented Apr 16, 2020

@blairham this should now be possible with the latest release. Create a file .env in your project and then add the following content:

DEVSPACE_FLAGS=-s

More info here: https://devspace.sh/cli/docs/configuration/env-file

@blairham
Copy link
Author

I afraid it's not working as intended:

in project 1:
devspace create space blairham
devspace deploy
[info] Using kube context 'devspace-blairham'
[info] Using namespace 'blairham'
[done] √ Deployed helm chart (Release revision: 0)
[done] √ Successfully deployed mysql with helm
[done] √ Successfully deployed!

in project 2:
devspace create space blairh
devspace deploy
[info] Using kube context 'devspace-blairh'
[info] Using namespace 'blairh'
[done] √ Deployed helm chart (Release revision: 0)
[done] √ Successfully deployed mysql with helm
[done] √ Successfully deployed!

back to project 1:
devspace deploy
[info] Switching to context 'devspace-blairh' and namespace 'blairh'
[info] Using kube context 'devspace-blairh'
[info] Using namespace 'blairh'
[info] Skipping deployment mysql
[done] √ Successfully deployed!

@blairham
Copy link
Author

it looks like I need to update the cli, which I had installed with brew. let me update that and retry

@LukasGentele
Copy link
Contributor

Yes, you will need the latest stable version v4.12 for this to work.

@blairham
Copy link
Author

I'm seeing this error:
devspace -p local deploy
[info] Applying extra flags from environment: -s
[info] Switching to context 'devspace-blairham' and namespace 'blairham'
[info] Using kube context 'devspace-blairham'
[info] Using namespace 'blairham'
[done] √ Created namespace: blairham
[fatal] Unable to create namespace: Post "https://.../api/v1/namespaces": getting credentials: decoding stdout: yaml: control characters are not allowed

@LukasGentele
Copy link
Contributor

@blairham seems like the -s is working. The error you see below appears because devspace tries to create a namespace. Do you have any namespaces hard-coded inside your devspace.yaml?

@blairham
Copy link
Author

blairham commented Apr 17, 2020

I don't, if I remove the env var, and run it with devspace -s deploy I don't see this issue

 $ devspace -p local  deploy      
[info]   Applying extra flags from environment: -s
[info]   Switching to context 'devspace-blairham' and namespace 'blairham'
[info]   Using kube context 'devspace-blairham'
[info]   Using namespace 'blairham'
[done] √ Created namespace: blairham
[fatal]  Unable to create namespace: Post "https://..../api/v1/namespaces": getting credentials: decoding stdout: yaml: control characters are not allowed

(deleted env var)

$ devspace -s -p local deploy
[info]   Switching to context 'devspace-blairham' and namespace 'blairham'
[info]   Using kube context 'devspace-blairham'
[info]   Using namespace 'blairham'
[info]   Skipping deployment common-mysql
[info]   Skipping deployment users-service-redis
[done] √ Successfully deployed!
         
Run: 
- `devspace open` to create an ingress for the app and open it in the browser 
- `devspace enter` to open a shell into the container 
- `devspace logs` to show the container logs
- `devspace analyze` to analyze the space for potential issues

@FabianKramm
Copy link
Collaborator

Can you run DEVSPACE_FLAGS=-s devspace deploy -p local -d -b and devspace deploy -s -p local -d -b and check if that makes a difference?

@blairham
Copy link
Author

$ DEVSPACE_FLAGS=-s devspace deploy -p local -d -b
[info]   Applying extra flags from environment: -s
[info]   Switching to context 'devspace-blairham' and namespace 'blairham'
[info]   Using kube context 'devspace-blairham'
[info]   Using namespace 'blairham'
[done] √ Created namespace: blairham
[fatal]  Unable to create namespace: Post "https://.../api/v1/namespaces": getting credentials: decoding stdout: yaml: control characters are not allowed
$ devspace deploy -s -p local -d -b
[info]   Switching to context 'devspace-blairham' and namespace 'blairham'
[info]   Using kube context 'devspace-blairham'
[info]   Using namespace 'blairham'
[done] √ Deployed helm chart (Release revision: 0)                       
[done] √ Successfully deployed common-mysql with helm                    
[done] √ Deployed helm chart (Release revision: 0)                       
[done] √ Successfully deployed users-service-redis with helm             
[done] √ Successfully deployed!
         
Run: 
- `devspace open` to create an ingress for the app and open it in the browser 
- `devspace enter` to open a shell into the container 
- `devspace logs` to show the container logs
- `devspace analyze` to analyze the space for potential issues

@FabianKramm
Copy link
Collaborator

@blairham thanks for the information, I found the issue: the problem is that the .env file is always applied, even for the devspace token command that provides the authentication token for devspace-cloud to kubectl. The problem here is that the token command also prints [info] Applying extra flags from environment: -s at the beginning which cannot be parsed by kubectl and results in the above error, so it currently works fine for all non devspace-cloud clusters and spaces. I'll fix this now and then release a new patch release.

@blairham
Copy link
Author

Looks like this is working as intended now. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/config Issues related to the config kind/design Must be conceptually designed kind/feature New feature or feature request
Projects
None yet
Development

No branches or pull requests

3 participants