-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[Feature] Set environment variables for an app #382
Comments
step 3: |
I'm using the internal |
the UI is great, specifically I think When you click on |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Unfortunately Docker doesn't provide an direct way to do this. There is a hacky approach where you modify the Docker container json config file, but then we have to restart the Docker daemon which will stop all the apps until it's restarted. |
This comment has been minimized.
This comment has been minimized.
So this was something that I briefly discussed with @songz. I originally was going to use the ID for this, but he thought better to use the domain name to not reveal the internal IDs and to make it more readable at the same time. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@coltonehrman readable domains in the url is generally preferred. Imagine if twitter handle was ids used in the systems internally. Using |
This comment has been minimized.
This comment has been minimized.
Would be: |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@ggwadera |
Would the environment variables be saved into data.db? Could you add a snippet of how the ending |
step 2 comes after step 3 right? page loads then query for env vars? |
|
As Docker already stores the environment variables inside the container configuration, I thought we could use that instead of storing in another place. The only modification in I included an example of how the Docker configuration would look like with a new variable. |
Currently there is no way for an user to set environment variables for their apps if they need to. This feature would enable a new configuration option for the apps, so an user can add, edit, or remove environment variables for an app.
Goals
Design
The environment variables are stored inside the docker container configuration files, and we can get those variables by inspecting a container with the docker API, so there's no need to store them somewhere else.
To modify the environment variables for a existing container, we have to recreate the container with the new variables.
In summary, the steps for this feature are:
Manage
button for the domain the user wants to edit./manage/${fullDomain}
) where the user can manage the environment variables (add, modify, delete).Add
button creates a new input form at the end of the list.Remove
button will remove that environment variable from the list.Submit
button will send a POST request to the API with the environment variables on the list.NAME
input is automatically converted to uppercase and validated to contain only letters, numbers and/or underscore.The client queries the server for the container existing environment variables.
Server queries docker to inspect the container and get the container info back.
Server filters out the default environment variables like
NODE_ENV
andPORT
, then returns the filtered variables.User presses the submit button to send the new environment variables to the server.
If the container is running, warns the user to confirm that the app will be restarted and asks if it's OK.
The server stops and removes the existing container.
The server recreates the container with the new environment variables and starts the container.
API Spec
GET:
/api/mappings/${fullDomain}/environment
This endpoint will query the Docker API to inspect the container configurations, extract the current environment variables, and then filter out the default variables (
NODE_ENV
,PORT
,PATH
,NODE_VERSION
,YARN_VERSION
), returning the non-default variables with name and value.Response sample (success):
Response sample (failure):
PUT:
/api/mappings/${fullDomain}/environment
This will save the new environment variables for the app. To do this, the container needs to be recreated with the new environment variables appended in the container configuration options (like restarting an app to pass a new env variable). After recreating, the container is started.
As we are using the same ID from the Docker container as the domain mapping ID, this will also update the mapping ID to the new container ID and update the
data.db
file.Request body sample:
Response sample (success): status code 204, no body.
Response sample (failure):
The text was updated successfully, but these errors were encountered: