Dockerfile
This commit is contained in:
parent
3c6f22b4a6
commit
ac3587f560
1 changed files with 64 additions and 0 deletions
64
Dockerfile
Normal file
64
Dockerfile
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
##### 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"]
|
||||
Loading…
Add table
Reference in a new issue