Fix Dockerfile
This commit is contained in:
parent
baef99cfe9
commit
531b61ab94
2 changed files with 17 additions and 14 deletions
2
.dockerignore
Normal file
2
.dockerignore
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
.git
|
||||
target
|
||||
29
Dockerfile
29
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"]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue