Skip to content

Commit

Permalink
fix: fixed volume referencing to support source output
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Meier <[email protected]>
  • Loading branch information
astromechza committed Mar 10, 2024
1 parent 9fe52ad commit b3d2ef2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
14 changes: 13 additions & 1 deletion internal/command/default.provisioners.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
[]
- uri: template://default-provisioners/volume
type: volume
class: default
state: |
name: {{ if .State.name }}{{ .State.name }}{{ else }}{{ uuidv4 }}{{ end }}
outputs: |
source: {{ .State.name }}
volumes: |
{{ .State.name }}:
name: {{ .State.name }}
driver: local
labels:
dev.score.compose.res.uid: {{ .Uid }}
5 changes: 5 additions & 0 deletions internal/command/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ arguments.
}
}

sd.State = *currentState
if err := sd.Persist(); err != nil {
return fmt.Errorf("failed to persist updated state directory: %w", err)
}

raw, _ := yaml.Marshal(superProject)

v, _ := cmd.Flags().GetString("output")
Expand Down
9 changes: 6 additions & 3 deletions internal/compose/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,9 @@ func ConvertSpec(spec *score.Workload, resources map[string]project.OutputLookup
return nil, fmt.Errorf("containers.%s.volumes[%d].path: can't mount named volume with sub path '%s': not supported", containerName, idx, *vol.Path)
}

// TODO: deprecate this - volume should be linked directly
resolvedVolumeSource, err := ctx.Substitute(vol.Source)
if err != nil {
return nil, fmt.Errorf("containers.%s.volumes[%d].source: %w", containerName, idx, err)
} else if resolvedVolumeSource != vol.Source {
slog.Warn(fmt.Sprintf("containers.%s.volumes[%d].source: interpolation will be deprecated in the future", containerName, idx))
}

if res, ok := spec.Resources[resolvedVolumeSource]; !ok {
Expand All @@ -108,6 +105,12 @@ func ConvertSpec(spec *score.Workload, resources map[string]project.OutputLookup
return nil, fmt.Errorf("containers.%s.volumes[%d].source: resource '%s' is not a volume", containerName, idx, resolvedVolumeSource)
}

if v, err := resources[resolvedVolumeSource]("source"); err != nil {
slog.Warn(fmt.Sprintf("containers.%s.volumes[%d].source: failed to find 'source' key in volume resource '%s': %v", containerName, idx, resolvedVolumeSource, err))
} else if sv, ok := v.(string); ok {
resolvedVolumeSource = sv
}

volumes[idx] = compose.ServiceVolumeConfig{
Type: "volume",
Source: resolvedVolumeSource,
Expand Down

0 comments on commit b3d2ef2

Please sign in to comment.