|
9 | 9 | "slices"
|
10 | 10 | "strings"
|
11 | 11 |
|
| 12 | + "al.essio.dev/pkg/shellescape" |
12 | 13 | "github.com/DefangLabs/defang/src/pkg/cli/client"
|
13 | 14 | "github.com/DefangLabs/defang/src/pkg/cli/compose"
|
14 | 15 | "github.com/DefangLabs/defang/src/pkg/surveyor"
|
@@ -232,6 +233,50 @@ func cleanupComposeFile(in string) (string, error) {
|
232 | 233 | })
|
233 | 234 | }
|
234 | 235 | }
|
| 236 | + |
| 237 | + // railpack generates images with `Entrypoint: "bash -c"`, and |
| 238 | + // compose-go normalizes string commands into arrays, for example: |
| 239 | + // `command: npm start` -> `command: [ "npm", "start" ]`. As a |
| 240 | + // result, the command which ultimately gets run is |
| 241 | + // `bash -c npm start`. When this gets run, `bash` will ignore |
| 242 | + // `start` and `npm` will get run in a subprocess--only printing |
| 243 | + // the help text. As it is common for users to type their service |
| 244 | + // command as a string, this cleanup step will help ensure the |
| 245 | + // command is run as intended by replacing `command: npm start` |
| 246 | + // with `command: [ "npm start" ]`. |
| 247 | + if kk.Value == "command" { |
| 248 | + if vk.Kind == yaml.ScalarNode { |
| 249 | + cmd := vk.Value |
| 250 | + vk.Value = "" |
| 251 | + vk.Kind = yaml.SequenceNode |
| 252 | + vk.Tag = "!!seq" |
| 253 | + vk.Content = []*yaml.Node{ |
| 254 | + { |
| 255 | + Tag: "!!str", |
| 256 | + Kind: yaml.ScalarNode, |
| 257 | + Value: cmd, |
| 258 | + }, |
| 259 | + } |
| 260 | + } |
| 261 | + // We will do the same for |
| 262 | + // `command: ["npm", "start"]`, which will also get transformed |
| 263 | + // to `command: [ "npm start" ]`. |
| 264 | + if vk.Kind == yaml.SequenceNode && len(vk.Content) > 1 { |
| 265 | + var parts []string |
| 266 | + for _, c := range vk.Content { |
| 267 | + parts = append(parts, c.Value) |
| 268 | + } |
| 269 | + cmd := shellescape.QuoteCommand(parts) |
| 270 | + // combine content nodes into one |
| 271 | + vk.Content = []*yaml.Node{ |
| 272 | + { |
| 273 | + Tag: "!!str", |
| 274 | + Kind: yaml.ScalarNode, |
| 275 | + Value: cmd, |
| 276 | + }, |
| 277 | + } |
| 278 | + } |
| 279 | + } |
235 | 280 | }
|
236 | 281 | }
|
237 | 282 | }
|
|
0 commit comments