Skip to content

Commit e56d627

Browse files
committed
adds support for links
1 parent be0c471 commit e56d627

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

examples/docker-compose.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
redis:
2+
image: redis:2.8
3+
ports:
4+
- 6379
5+
16
api:
27
command: npm start
38
image: docker.mydomain.com/api:latest
@@ -10,6 +15,8 @@ api:
1015
MONGO_DATABASE: develop_api
1116
volumes:
1217
- .:/src
18+
links:
19+
- 'redis:redis'
1320

1421
app:
1522
image: docker.mydomain.com/app:latest

main.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"log"
88
"os"
99
"path"
10+
"strings"
1011
"text/template"
1112

1213
"gopkg.in/yaml.v2"
@@ -32,6 +33,7 @@ fi
3233
-d \
3334
--name {{.Name}}_1 \
3435
{{range .Volumes}}-v {{.}} {{end}} \
36+
{{range .Links}}--link {{.}} {{end}} \
3537
{{range $key, $value := .Environment}}-e {{$key}}="{{$value}}" {{end}} \
3638
{{range .Ports}}-p {{.}} {{end}} \
3739
{{.Image}} {{.Command}}
@@ -43,6 +45,7 @@ type Service struct {
4345
Image string
4446
Ports []string
4547
Volumes []string
48+
Links []string
4649
Privileged bool
4750
Command string
4851
Environment map[string]string
@@ -59,6 +62,19 @@ func loadYaml(filename string) (services map[string]Service, err error) {
5962
return
6063
}
6164

65+
func setLinksWithAppName(service *Service) {
66+
for i := range service.Links {
67+
links := strings.Split(service.Links[i], ":")
68+
containerName := links[0]
69+
containerAlias := containerName + "_1"
70+
if len(links) > 1 {
71+
containerAlias = links[1]
72+
}
73+
74+
service.Links[i] = fmt.Sprintf("%s-%s_1:%s", appName, containerName, containerAlias)
75+
}
76+
}
77+
6278
// Saves the services data into bash scripts
6379
func saveToBash(services map[string]Service) (err error) {
6480
t := template.New("service-bash-template")

0 commit comments

Comments
 (0)