File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ( / R U N g o r u n ( .+ ) / , "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 ( ) ;
You can’t perform that action at this time.
0 commit comments