Skip to content

Commit 4a4461a

Browse files
authored
Merge pull request #125 from deploystackio/feat/service-connections
feat(docs): enhance service connection documentation with new mappings structure and examples
2 parents a08b2bb + 94e476c commit 4a4461a

3 files changed

Lines changed: 57 additions & 9 deletions

File tree

docs/deploystack/deploystack-config-file.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ You can override these values using the `config.yml` (only on your main branch)
4343

4444
| Property | Type | Description | Constraints |
4545
|----------|------|-------------|-------------|
46-
| `name` | String | Override the repository name for DeployStack display | Maximum 40 characters |
47-
| `description` | String | Override the repository description for DeployStack display | Maximum 500 characters |
48-
| `logo` | String | URL to your application logo | [Application Logo Configuration](/docs/deploystack/application-logo-configuration.md) |
46+
| `mappings` | Array | Defines relationships between services for connection configuration | Required |
47+
| `mappings[].fromService` | String | Service that needs to connect to another service | Required |
48+
| `mappings[].toService` | String | Service being connected to | Required |
49+
| `mappings[].environmentVariables` | Array of Strings | Environment variable names that reference the target service | Required |
50+
| `mappings[].property` | String | Type of connection property to reference (e.g., 'connectionString', 'hostport') | Optional, defaults to 'hostport' |
4951

5052
The override process follows this order:
5153

@@ -148,10 +150,12 @@ deployment:
148150
environmentVariables:
149151
- "DATABASE_HOST"
150152
- "DATABASE_URL"
153+
property: "connectionString"
151154
- fromService: "frontend"
152155
toService: "api"
153156
environmentVariables:
154157
- "API_URL"
158+
property: "hostport"
155159
```
156160

157161
This configuration tells DeployStack how to properly configure communication between:

docs/docker-to-iac/api.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ type ServiceConnectionsConfig = {
426426
fromService: string; // Service that needs to connect
427427
toService: string; // Service to connect to
428428
environmentVariables: string[]; // Environment variables that reference the service
429+
property?: string; // Connection property type (connectionString, hostport, etc.)
429430
}>
430431
};
431432
```
@@ -443,7 +444,14 @@ serviceConnections: {
443444
{
444445
fromService: 'frontend',
445446
toService: 'api',
446-
environmentVariables: ['API_URL']
447+
environmentVariables: ['API_URL'],
448+
property: 'hostport'
449+
},
450+
{
451+
fromService: 'app',
452+
toService: 'db',
453+
environmentVariables: ['DATABASE_URL'],
454+
property: 'connectionString'
447455
}
448456
]
449457
}

docs/docker-to-iac/service-connections.md

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ menuTitle: Service Connections
55

66
# Service Connections
77

8-
The `docker-to-iac` module now supports configuring service-to-service communication when translating Docker Compose files to cloud provider IaC templates. This feature is essential for multi-container applications where services need to communicate with each other (e.g., web applications connecting to databases).
8+
The `docker-to-iac` module supports configuring service-to-service communication when translating Docker Compose files to cloud provider IaC templates. This feature is essential for multi-container applications where services need to communicate with each other (e.g., web applications connecting to databases).
99

1010
## The Challenge
1111

@@ -63,7 +63,8 @@ const result = translate(dockerComposeContent, {
6363
environmentVariables: [ // List of env vars that reference the service
6464
'DATABASE_HOST',
6565
'API_URL'
66-
]
66+
],
67+
property: 'connectionString' // The type of connection (connectionString, hostport, etc.)
6768
}
6869
]
6970
}
@@ -77,6 +78,7 @@ For each service connection mapping:
7778
- `fromService`: The service that needs to connect to another service
7879
- `toService`: The service being connected to
7980
- `environmentVariables`: Array of environment variable names that reference the target service
81+
- `property`: The type of connection property to reference (e.g., 'connectionString', 'hostport', etc.)
8082

8183
## Provider-Specific Implementations
8284

@@ -99,7 +101,7 @@ services:
99101
fromService:
100102
name: db
101103
type: pserv
102-
property: hostport
104+
property: hostport # This property is derived from the 'property' parameter in your mapping
103105
```
104106
105107
This approach leverages Render's built-in service discovery capabilities for reliable inter-service communication.
@@ -122,7 +124,7 @@ services:
122124
123125
## Complete Example
124126
125-
Here's a complete example showing Node.js microservices communicating with each other:
127+
Here's a complete example showing Node.js microservices communicating with each other, and a more detailed database connection example:
126128
127129
```javascript
128130
const dockerComposeContent = `
@@ -148,13 +150,47 @@ const serviceConnections = {
148150
{
149151
fromService: 'frontend',
150152
toService: 'api',
151-
environmentVariables: ['API_URL']
153+
environmentVariables: ['API_URL'],
154+
property: 'hostport'
152155
}
153156
]
154157
};
155158
156159
// For DigitalOcean - Service name stays as "api" in http://api:3000
157160
// For Render - Will use fromService syntax instead of string replacement
161+
162+
// Database Connection Example
163+
const databaseComposeContent = `
164+
services:
165+
app:
166+
image: node:18-alpine
167+
environment:
168+
- DATABASE_URL=postgresql://postgres:secret@postgres:5432/mydb
169+
ports:
170+
- "3000:3000"
171+
172+
postgres:
173+
image: postgres:latest
174+
environment:
175+
- POSTGRES_DB: mydb
176+
- POSTGRES_USER: postgres
177+
- POSTGRES_PASSWORD: secret
178+
`;
179+
180+
const dbServiceConnections = {
181+
mappings: [
182+
{
183+
fromService: 'app',
184+
toService: 'postgres',
185+
environmentVariables: ['DATABASE_URL'],
186+
property: 'connectionString' // Use connectionString for full database URL
187+
}
188+
]
189+
};
190+
191+
// Result will include proper connection format for each provider
192+
// DigitalOcean: DATABASE_URL=${postgres.DATABASE_URL}
193+
// Render: fromDatabase: { name: "postgres", property: "connectionString" }
158194
```
159195

160196
## Response Format

0 commit comments

Comments
 (0)