Skip to content

Commit ef579ac

Browse files
committed
Merge conflicts
2 parents 8e23e8b + e910983 commit ef579ac

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

internal/local_runner.go

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,9 +624,9 @@ func (d *LocalRunner) toDockerComposeService(s *service) (map[string]interface{}
624624

625625
// create the bind volumes
626626
for localPath, volumeName := range s.volumesMapped {
627-
volumeDirAbsPath, err := d.out.CreateDir(fmt.Sprintf("volume-%s-%s", s.Name, volumeName))
627+
volumeDirAbsPath, err := d.createVolume(s.Name, volumeName)
628628
if err != nil {
629-
return nil, fmt.Errorf("failed to create volume dir %s: %w", volumeName, err)
629+
return nil, err
630630
}
631631
volumes[volumeDirAbsPath] = localPath
632632
}
@@ -765,6 +765,15 @@ func (d *LocalRunner) generateDockerCompose() ([]byte, error) {
765765
return yamlData, nil
766766
}
767767

768+
func (d *LocalRunner) createVolume(service, volumeName string) (string, error) {
769+
// create the volume in the output folder
770+
volumeDirAbsPath, err := d.out.CreateDir(fmt.Sprintf("volume-%s-%s", service, volumeName))
771+
if err != nil {
772+
return "", fmt.Errorf("failed to create volume dir %s: %w", volumeName, err)
773+
}
774+
return volumeDirAbsPath, nil
775+
}
776+
768777
// runOnHost runs the service on the host machine
769778
func (d *LocalRunner) runOnHost(ss *service) error {
770779
// TODO: Use env vars in host processes
@@ -773,6 +782,34 @@ func (d *LocalRunner) runOnHost(ss *service) error {
773782
return fmt.Errorf("failed to apply template, err: %w", err)
774783
}
775784

785+
// Create the volumes for this service
786+
volumesMapped := map[string]string{}
787+
for pathInDocker, volumeName := range ss.volumesMapped {
788+
volumeDirAbsPath, err := d.createVolume(ss.Name, volumeName)
789+
if err != nil {
790+
return err
791+
}
792+
volumesMapped[pathInDocker] = volumeDirAbsPath
793+
}
794+
795+
// We have to replace the names of the files it is using as artifacts for the full names
796+
// Just a string replacement should be enough
797+
for i, arg := range args {
798+
// If any of the args contains any of the files mapped, we need to replace it
799+
for pathInDocker, artifactName := range ss.filesMapped {
800+
if strings.Contains(arg, pathInDocker) {
801+
args[i] = strings.ReplaceAll(arg, pathInDocker, filepath.Join(d.out.dst, artifactName))
802+
}
803+
}
804+
// If any of the args contains any of the volumes mapped, we need to create
805+
// the volume and replace it
806+
for pathInDocker, volumeAbsPath := range volumesMapped {
807+
if strings.Contains(arg, pathInDocker) {
808+
args[i] = strings.ReplaceAll(arg, pathInDocker, volumeAbsPath)
809+
}
810+
}
811+
}
812+
776813
execPath := d.overrides[ss.Name]
777814
cmd := exec.Command(execPath, args...)
778815

internal/manifest.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,20 @@ func (s *Manifest) Validate() error {
163163
}
164164
}
165165

166+
// validate that the mounts are correct
167+
for _, ss := range s.services {
168+
for _, fileNameRef := range ss.filesMapped {
169+
fileLoc := filepath.Join(s.out.dst, fileNameRef)
170+
171+
if _, err := os.Stat(fileLoc); err != nil {
172+
if os.IsNotExist(err) {
173+
return fmt.Errorf("service %s includes an unknown file %s does not exist", ss.Name, fileLoc)
174+
}
175+
return fmt.Errorf("failed to stat file %s: %w", fileLoc, err)
176+
}
177+
}
178+
}
179+
166180
return nil
167181
}
168182

0 commit comments

Comments
 (0)