Skip to content

Commit ddb8c3f

Browse files
authored
Merge pull request #2 from apocas/main
updates
2 parents 4c935f5 + 0fdfd7d commit ddb8c3f

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed

lib/services.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,14 @@ module.exports = async function (docker, projectName, recipe, output) {
8383
if (service.volumes) {
8484
opts['Volumes'] = {};
8585
for (var volume of service.volumes) {
86-
var v = volume.split(':');
87-
opts['Volumes'][v[1]] = {};
86+
if (typeof volume === 'string' || volume instanceof String) {
87+
var v = volume.split(':');
88+
opts['Volumes'][v[1]] = {};
89+
} else {
90+
if (volume.target) {
91+
opts['Volumes'][volume.target] = {};
92+
}
93+
}
8894
}
8995
}
9096

@@ -122,7 +128,29 @@ var buildHostConfig = function (service) {
122128
};
123129

124130
if (service.volumes) {
125-
output['Binds'] = service.volumes;
131+
output['Binds'] = [];
132+
133+
for (var volume of service.volumes) {
134+
if (typeof volume === 'string' || volume instanceof String) {
135+
output['Binds'].push(volume);
136+
} else {
137+
var volumestr = '';
138+
if (volume.source && volume.target) {
139+
volumestr += volume.source + ':' + volume.target + ':';
140+
}
141+
if (volume.read_only) {
142+
volumestr += 'ro,';
143+
}
144+
if (volume.volume && volume.volume.nocopy) {
145+
volumestr += 'nocopy,';
146+
}
147+
if (volume.bind && volume.bind.propagation) {
148+
volumestr += volume.bind.propagation + ',';
149+
}
150+
volumestr = volumestr.slice(0, -1);
151+
output['Binds'].push(volumestr);
152+
}
153+
}
126154
}
127155

128156
if (service.ports && service.ports.length > 0) {

test/assets/wordpress_long.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
version: "3.9"
2+
3+
services:
4+
db:
5+
image: mysql:5.7
6+
volumes:
7+
- source: db_data
8+
target: /var/lib/mysql
9+
restart: always
10+
environment:
11+
MYSQL_ROOT_PASSWORD: somewordpress
12+
MYSQL_DATABASE: wordpress
13+
MYSQL_USER: wordpress
14+
MYSQL_PASSWORD: wordpress
15+
16+
wordpress:
17+
depends_on:
18+
- db
19+
image: wordpress:latest
20+
ports:
21+
- "8000:80"
22+
restart: always
23+
environment:
24+
WORDPRESS_DB_HOST: db:3306
25+
WORDPRESS_DB_USER: wordpress
26+
WORDPRESS_DB_PASSWORD: wordpress
27+
WORDPRESS_DB_NAME: wordpress
28+
volumes:
29+
db_data: {}

0 commit comments

Comments
 (0)