@@ -75,6 +75,40 @@ export default function dockerize(
7575 `EXPOSE ${ port } ` ,
7676 execute_cmd ,
7777 ] . join ( "\n" ) ;
78+ } else if ( stack === "Rust" ) {
79+ let rustBuildOverride : string [ ] = [ ] ;
80+ let processed_build_steps = build_steps ;
81+
82+ if ( last_cmd . startsWith ( "cargo run" ) ) {
83+ processed_build_steps = build_steps . filter ( step => ! step . includes ( "cargo build" ) ) ;
84+ rustBuildOverride = [ `RUN cargo build --release && find target/release -maxdepth 1 -type f -executable -exec mv {} ./app_binary \\;` ] ;
85+ execute_cmd = 'CMD ["./app_binary"]' ;
86+ } else if ( last_cmd . startsWith ( "rustc " ) ) {
87+ const target = last_cmd . replace ( "rustc " , "" ) ;
88+ processed_build_steps = build_steps . filter ( step => ! step . includes ( "rustc " ) ) ;
89+ rustBuildOverride = [ `RUN rustc ${ target } -o app_binary` ] ;
90+ execute_cmd = 'CMD ["./app_binary"]' ;
91+ }
92+
93+ dockerfile = [
94+ "FROM rust:1.77-alpine3.19 AS builder" ,
95+ "RUN apk add --no-cache musl-dev" ,
96+ "WORKDIR /app" ,
97+ "COPY . ." ,
98+ ...processed_build_steps ,
99+ ...rustBuildOverride ,
100+ "# Generator limitation: Since we don't know the exact binary name, we delete all source files and keep only the compiled executables" ,
101+ "RUN find . -type f ! -executable -delete && rm -rf src/ .git/ Cargo.* vendor/ target/" ,
102+ "" ,
103+ "FROM alpine:3.19" ,
104+ "RUN addgroup -S appgroup && adduser -S appuser -G appgroup" ,
105+ "RUN apk add --no-cache ca-certificates libgcc" ,
106+ "WORKDIR /app" ,
107+ "COPY --from=builder /app /app" ,
108+ "USER appuser" ,
109+ `EXPOSE ${ port } ` ,
110+ execute_cmd ,
111+ ] . join ( "\n" ) ;
78112 }
79113 return dockerfile . toString ( ) ;
80114}
@@ -89,6 +123,7 @@ export function dockerignore(stack: string): string {
89123 Python : [ "__pycache__/" , "*.pyc" , "*.pyo" , ".venv/" , "dist/" , "*.egg-info/" ] ,
90124 NodeJS : [ "node_modules/" , "dist/" , ".npm/" , "*.log" , "coverage/" ] ,
91125 Go : [ "bin/" , "obj/" , "*.exe" , "*.dll" , "*.so" , "*.dylib" ] ,
126+ Rust : [ "target/" , "**/*.rs.bk" ] ,
92127 } ;
93128
94129 return [ ...common , ...( stackRules [ stack ] ?? [ ] ) ] . join ( "\n" ) + "\n" ;
0 commit comments