| 158 | } |
| 159 | |
| 160 | func extractInterpolationVariablesFromModel(ctx context.Context, dockerCli command.Cli, projectOptions *ProjectOptions, cmdEnvs []string) ([]varInfo, bool, error) { |
| 161 | cmdEnvMap := extractEnvCLIDefined(cmdEnvs) |
| 162 | |
| 163 | // Create a model without interpolation to extract variables |
| 164 | opts := configOptions{ |
| 165 | noInterpolate: true, |
| 166 | ProjectOptions: projectOptions, |
| 167 | } |
| 168 | |
| 169 | model, err := opts.ToModel(ctx, dockerCli, nil, cli.WithoutEnvironmentResolution, cli.WithLoadOptions(loader.WithSkipValidation)) |
| 170 | if err != nil { |
| 171 | return nil, false, err |
| 172 | } |
| 173 | |
| 174 | // Extract variables that need interpolation |
| 175 | variables := template.ExtractVariables(model, template.DefaultPattern) |
| 176 | if len(variables) == 0 { |
| 177 | return nil, true, nil |
| 178 | } |
| 179 | |
| 180 | var varsInfo []varInfo |
| 181 | proposedValues := make(map[string]string) |
| 182 | |
| 183 | for name, variable := range variables { |
| 184 | info := varInfo{ |
| 185 | name: name, |
| 186 | required: variable.Required, |
| 187 | defaultValue: variable.DefaultValue, |
| 188 | } |
| 189 | |
| 190 | // Determine value and source based on priority |
| 191 | if value, exists := cmdEnvMap[name]; exists { |
| 192 | info.value = value |
| 193 | info.source = "command-line" |
| 194 | proposedValues[name] = value |
| 195 | } else if value, exists := os.LookupEnv(name); exists { |
| 196 | info.value = value |
| 197 | info.source = "environment" |
| 198 | proposedValues[name] = value |
| 199 | } else if variable.DefaultValue != "" { |
| 200 | info.value = variable.DefaultValue |
| 201 | info.source = "compose file" |
| 202 | proposedValues[name] = variable.DefaultValue |
| 203 | } else { |
| 204 | info.value = "<unset>" |
| 205 | info.source = "none" |
| 206 | } |
| 207 | |
| 208 | varsInfo = append(varsInfo, info) |
| 209 | } |
| 210 | return varsInfo, false, nil |
| 211 | } |
| 212 | |
| 213 | func extractEnvCLIDefined(cmdEnvs []string) map[string]string { |
| 214 | // Parse command-line environment variables |