Fix inline comments in dropshell handling
This commit is contained in:
15
TEMPLATES.md
15
TEMPLATES.md
@@ -122,17 +122,21 @@ CONFIG_VOLUME="${CONTAINER_NAME}_config"
|
|||||||
Default service configuration that **will be modified per installation**. When a user creates a service from this template, they edit this file to customize the deployment:
|
Default service configuration that **will be modified per installation**. When a user creates a service from this template, they edit this file to customize the deployment:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Service-specific settings
|
# Service identification (REQUIRED)
|
||||||
CONTAINER_NAME=service-name
|
CONTAINER_NAME=service-name
|
||||||
IMAGE_TAG="latest"
|
|
||||||
|
|
||||||
# Server settings
|
# Server settings (REQUIRED by dropshell)
|
||||||
SSH_USER="root"
|
SSH_USER="root" # CRITICAL: This must always be defined!
|
||||||
|
|
||||||
|
# Docker settings (optional)
|
||||||
|
IMAGE_TAG="latest"
|
||||||
|
|
||||||
# Service-specific variables
|
# Service-specific variables
|
||||||
# (Add any configuration specific to your service)
|
# (Add any configuration specific to your service)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**CRITICAL REQUIREMENT**: The `SSH_USER` variable MUST be defined in every service.env file. Dropshell uses this internally for server management. Without it, the template will fail with "SSH_USER variable not defined" error.
|
||||||
|
|
||||||
**Important**: This is the file users edit to customize each service instance. Different deployments of the same template will have different `service.env` files.
|
**Important**: This is the file users edit to customize each service instance. Different deployments of the same template will have different `service.env` files.
|
||||||
|
|
||||||
### How Environment Variables Work
|
### How Environment Variables Work
|
||||||
@@ -332,6 +336,7 @@ Templates must pass these validation checks:
|
|||||||
2. **Scripts are executable**: All `.sh` files must have execute permissions
|
2. **Scripts are executable**: All `.sh` files must have execute permissions
|
||||||
3. **TEMPLATE variable matches**: The `TEMPLATE` variable in `.template_info.env` must match the directory name
|
3. **TEMPLATE variable matches**: The `TEMPLATE` variable in `.template_info.env` must match the directory name
|
||||||
4. **Valid environment files**: Both `.env` files must be parseable
|
4. **Valid environment files**: Both `.env` files must be parseable
|
||||||
|
5. **SSH_USER defined**: The `SSH_USER` variable MUST be present in `service.env`
|
||||||
|
|
||||||
## Best Practices
|
## Best Practices
|
||||||
|
|
||||||
@@ -377,6 +382,7 @@ CONTENT_VOLUME="${CONTAINER_NAME}_content"
|
|||||||
`service.env`:
|
`service.env`:
|
||||||
```bash
|
```bash
|
||||||
CONTAINER_NAME=nginx-server
|
CONTAINER_NAME=nginx-server
|
||||||
|
SSH_USER="root"
|
||||||
IMAGE_TAG="alpine"
|
IMAGE_TAG="alpine"
|
||||||
HTTP_PORT=8080
|
HTTP_PORT=8080
|
||||||
```
|
```
|
||||||
@@ -434,6 +440,7 @@ CONFIG_VOLUME="${CONTAINER_NAME}_config"
|
|||||||
`service.env`:
|
`service.env`:
|
||||||
```bash
|
```bash
|
||||||
CONTAINER_NAME=postgres-db
|
CONTAINER_NAME=postgres-db
|
||||||
|
SSH_USER="root"
|
||||||
IMAGE_TAG="15-alpine"
|
IMAGE_TAG="15-alpine"
|
||||||
DB_PORT=5432
|
DB_PORT=5432
|
||||||
POSTGRES_PASSWORD="changeme"
|
POSTGRES_PASSWORD="changeme"
|
||||||
|
@@ -35,6 +35,26 @@ bool envmanager::load() {
|
|||||||
std::string key = line.substr(0, pos);
|
std::string key = line.substr(0, pos);
|
||||||
std::string value = line.substr(pos + 1);
|
std::string value = line.substr(pos + 1);
|
||||||
|
|
||||||
|
// Remove inline comments (everything after unquoted #)
|
||||||
|
bool in_quotes = false;
|
||||||
|
char quote_char = '\0';
|
||||||
|
for (size_t i = 0; i < value.length(); ++i) {
|
||||||
|
char c = value[i];
|
||||||
|
|
||||||
|
// Handle quote state changes
|
||||||
|
if (!in_quotes && (c == '\'' || c == '"')) {
|
||||||
|
in_quotes = true;
|
||||||
|
quote_char = c;
|
||||||
|
} else if (in_quotes && c == quote_char && (i == 0 || value[i-1] != '\\')) {
|
||||||
|
in_quotes = false;
|
||||||
|
quote_char = '\0';
|
||||||
|
} else if (!in_quotes && c == '#') {
|
||||||
|
// Found unquoted # - truncate value here
|
||||||
|
value = value.substr(0, i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// trim whitespace from the key and value
|
// trim whitespace from the key and value
|
||||||
m_variables[dequote(trim(key))] = dequote(trim(value));
|
m_variables[dequote(trim(key))] = dequote(trim(value));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user