##### Builder #### FROM rust:1.62-alpine as builder RUN apk update && apk upgrade RUN apk add --no-cache sqlite npm WORKDIR /usr/src # Create blank project RUN USER=root cargo new rust-dockerize # We want dependencies cached, so copy those first. COPY Cargo.toml Cargo.lock /usr/src/huellas/ # Set the working directory WORKDIR /usr/src/huellas ## Install target platform (Cross-Compilation) --> Needed for Alpine RUN rustup target add x86_64-unknown-linux-musl # This is an empty build to get the dependencies cached. RUN cargo build --target x86_64-unknown-linux-musl --release # Now copy in the rest of the sources COPY src /usr/src/huellas/src/ ## Touch main.rs to prevent cached release build RUN touch /usr/src/huellas/src/main.rs # This is the actual application build. RUN cargo build --target x86_64-unknown-linux-musl --release # Now TS client COPY ts-client /usr/src/huellas/ts-client/ # Set the working directory WORKDIR /usr/src/huellas/ts-client/ # Install dependencies RUN npm install # Install Typescript RUN npm install -g typescript # Transpile RUN tsc ################ ##### Runtime FROM alpine:3.16.0 AS runtime # Copy application binary from builder image COPY --from=builder /usr/src/huellas/target/x86_64-unknown-linux-musl/release/huellas /usr/local/bin # Copy static files COPY static /usr/local/bin/static/ # Copy javascript client COPY --from=builder /usr/src/huellas/ts-client/build/client.js /usr/local/bin/static # EXPOSE 3030 # Run the application CMD ["/usr/local/bin/huellas"]