Skip to content

Commit 048f89e

Browse files
chore: add test case for railpack command fixup (#1392)
* chore: add test case for railpack command fixup * fixup railpack commands to compensate for bash -c entrypoint * golden file does not include fixup --------- Co-authored-by: Jordan Stephens <[email protected]>
1 parent 6705c66 commit 048f89e

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

src/pkg/cli/compose/fixup.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strconv"
1010
"strings"
1111

12+
"al.essio.dev/pkg/shellescape"
1213
"github.com/DefangLabs/defang/src/pkg/cli/client"
1314
"github.com/DefangLabs/defang/src/pkg/term"
1415
defangv1 "github.com/DefangLabs/defang/src/protos/io/defang/v1"
@@ -95,6 +96,20 @@ func FixupServices(ctx context.Context, provider client.Provider, project *compo
9596
}
9697
// hint to CD that we want to use Railpack
9798
svccfg.Build.Dockerfile = RAILPACK
99+
100+
// railpack generates images with `Entrypoint: "bash -c"`, and
101+
// compose-go normalizes string commands into arrays, for example:
102+
// `command: npm start` -> `command: [ "npm", "start" ]`. As a
103+
// result, the command which ultimately gets run is
104+
// `bash -c npm start`. When this gets run, `bash` will ignore
105+
// `start` and `npm` will get run in a subprocess--only printing
106+
// the help text. As it is common for users to type their service
107+
// command as a string, this cleanup step will help ensure the
108+
// command is run as intended by replacing `command: [ "npm", "start" ]`
109+
// with `command: [ "npm start" ]`.
110+
if len(svccfg.Command) > 1 {
111+
svccfg.Command = []string{shellescape.QuoteCommand(svccfg.Command)}
112+
}
98113
}
99114
}
100115

src/testdata/railpack/compose.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
services:
22
railpack-short:
33
build: .
4+
command: npm start
45
railpack-long:
56
build:
67
context: .
8+
command: exec node index.js
79
railpackwithdockerfile:
810
build:
911
context: .
1012
dockerfile: Dockerfile
13+
command: something "with space"

src/testdata/railpack/compose.yaml.fixup

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"context": ".",
55
"dockerfile": "*Railpack"
66
},
7-
"command": null,
7+
"command": [
8+
"exec node index.js"
9+
],
810
"entrypoint": null,
911
"networks": {
1012
"default": null
@@ -15,7 +17,9 @@
1517
"context": ".",
1618
"dockerfile": "*Railpack"
1719
},
18-
"command": null,
20+
"command": [
21+
"npm start"
22+
],
1923
"entrypoint": null,
2024
"networks": {
2125
"default": null
@@ -26,7 +30,9 @@
2630
"context": ".",
2731
"dockerfile": "*Railpack"
2832
},
29-
"command": null,
33+
"command": [
34+
"something 'with space'"
35+
],
3036
"entrypoint": null,
3137
"networks": {
3238
"default": null

src/testdata/railpack/compose.yaml.golden

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,28 @@ services:
44
build:
55
context: .
66
dockerfile: Dockerfile
7+
command:
8+
- exec
9+
- node
10+
- index.js
711
networks:
812
default: null
913
railpack-short:
1014
build:
1115
context: .
1216
dockerfile: Dockerfile
17+
command:
18+
- npm
19+
- start
1320
networks:
1421
default: null
1522
railpackwithdockerfile:
1623
build:
1724
context: .
1825
dockerfile: Dockerfile
26+
command:
27+
- something
28+
- with space
1929
networks:
2030
default: null
2131
networks:

0 commit comments

Comments
 (0)