Skip to content

Commit ae0d8d3

Browse files
fix
1 parent ab37004 commit ae0d8d3

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/backend/utils/container.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,19 @@ export default function dockerize(
5151
execute_cmd,
5252
].join("\n");
5353
} else if (stack === "Go") {
54+
let goBuildOverride: string[] = [];
55+
if (last_cmd.startsWith("go run")) {
56+
const target = last_cmd.replace("go run ", "");
57+
goBuildOverride = [`RUN go build -o app_binary ${target}`];
58+
execute_cmd = 'CMD ["./app_binary"]';
59+
}
5460
dockerfile = [
5561
"FROM golang:1.22-alpine AS builder",
5662
"WORKDIR /app",
5763
"COPY . .",
5864
"RUN if [ -f go.mod ]; then go mod download; fi",
59-
...build_steps.map(step => step.replace(/RUN go run (.+)/, "RUN go build -o app_binary $1")),
65+
...build_steps,
66+
...goBuildOverride,
6067
"RUN find . -type f ! -executable -delete && rm -rf vendor/ .git/ *.go go.*",
6168
"",
6269
"FROM alpine:3.19",
@@ -66,7 +73,7 @@ export default function dockerize(
6673
"COPY --from=builder /app /app",
6774
"USER appuser",
6875
`EXPOSE ${port}`,
69-
last_cmd.startsWith("go run") ? 'CMD ["./app_binary"]' : execute_cmd,
76+
execute_cmd,
7077
].join("\n");
7178
}
7279
return dockerfile.toString();

0 commit comments

Comments
 (0)