-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
79 lines (64 loc) · 2.46 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# This Dockerfile is used to build and run the Kasuki bot.
# Use the official Rust image as a base
# This image includes all the necessary tools to compile a Rust project.
FROM rust:slim-bookworm AS builder
# Create a new empty project
# This is done as root to avoid permission issues.
RUN USER=root cargo new --bin kasuki
WORKDIR /kasuki
# Install system dependencies
# These are required for the Kasuki bot to function correctly.
RUN apt-get update && apt-get install -y --no-install-recommends \
libssl-dev libsqlite3-dev \
libpng-dev libjpeg-dev \
ca-certificates pkg-config \
protobuf-compiler \
&& rm -rf /var/lib/apt/lists/*
# Copy over your manifests
# This includes the Cargo.toml file which specifies the Rust dependencies.
COPY ./Cargo.toml ./Cargo.toml
COPY ./proto ./proto
COPY ./schemas ./schemas
COPY ./build.rs ./build.rs
# Build a dummy project
# This is done to cache the dependencies.
RUN cargo build --release
# Remove the dummy project
RUN rm src/*.rs
# Remove the dummy project's build artifacts
RUN rm target/release/deps/kasuki*
RUN rm target/release/kasuki*
# Now copy your actual source code
# This is done after the dummy build to take advantage of Docker's layer caching.
COPY ./src ./src
# Build for release. Dependencies will be reused from the previous build
# This compiles the Kasuki bot for release.
RUN cargo build --release
# Start a new stage
# This is a multi-stage build. The previous stage was used to compile the bot.
# This stage is used to create the final image that will be run.
FROM debian:trixie-slim AS bot
# Set labels
# These provide metadata about the image.
LABEL maintainer="valgul"
LABEL author="valgul"
# Set the working directory
# This is where the Kasuki bot will be run from.
WORKDIR /kasuki/
# Install system dependencies
# These are required for the Kasuki bot to function correctly.
RUN apt-get update && apt-get install -y --no-install-recommends \
libssl-dev libsqlite3-dev \
libpng-dev libjpeg-dev \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Copy other necessary files
# These include JSON files and server images used by the Kasuki bot.
COPY json /kasuki/json
COPY server_image /kasuki/server_image
# Copy over the built binary file from the builder stage
# This is the compiled Kasuki bot.
COPY --from=builder /kasuki/target/release/kasuki /kasuki/
# Set the command to run your application
# This is the command that will be run when a container is started from this image.
CMD ["./kasuki"]