From 531b61ab94f83b6f2d9913208661570193a63a8e Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 2 Aug 2022 16:14:56 -0400 Subject: [PATCH] Fix Dockerfile --- .dockerignore | 2 ++ Dockerfile | 29 +++++++++++++++-------------- 2 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5874b8c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.git +target diff --git a/Dockerfile b/Dockerfile index a25b1dc..a366460 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,13 @@ ##### Builder #### -FROM rust:1.62-alpine as builder +FROM rust:1.62-slim-bullseye as builder -RUN apk update && apk upgrade - -RUN apk add --no-cache sqlite npm +RUN apt-get update && apt-get -y upgrade +RUN apt-get -y install --no-install-recommends sqlite3 libsqlite3-dev npm && rm -rf /var/lib/apt/lists/* WORKDIR /usr/src # Create blank project -RUN USER=root cargo new rust-dockerize +RUN USER=root cargo new --bin huellas # We want dependencies cached, so copy those first. COPY Cargo.toml Cargo.lock /usr/src/huellas/ @@ -16,20 +15,20 @@ 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 +RUN cargo build --release # Now copy in the rest of the sources COPY src /usr/src/huellas/src/ +COPY migrations /usr/src/huellas/migrations/ +COPY db /usr/src/huellas/db/ +COPY .env sqlx-data.json Rocket.toml /usr/src/huellas/ ## 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 +RUN cargo build --release # Now TS client COPY ts-client /usr/src/huellas/ts-client/ @@ -48,17 +47,19 @@ RUN tsc ################ ##### Runtime -FROM alpine:3.16.0 AS runtime +FROM debian:bullseye-slim AS runtime +RUN apt-get update && apt-get -y upgrade +RUN apt-get -y install --no-install-recommends sqlite3 && rm -rf /var/lib/apt/lists/* # Copy application binary from builder image -COPY --from=builder /usr/src/huellas/target/x86_64-unknown-linux-musl/release/huellas /usr/local/bin +COPY --from=builder /usr/src/huellas/target/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 +# Delete the first line of jvascript ts-client +RUN sed -i '1d' /usr/local/bin/static/client.js # Run the application CMD ["/usr/local/bin/huellas"]