From 0412c53207961e4d008ed4630620a7cf9801b9cd Mon Sep 17 00:00:00 2001 From: Ayaan Zaidi Date: Sat, 4 Mar 2023 11:56:04 +0530 Subject: [PATCH] feat(docker): create Dockerfile to deploy to fly.io --- .dockerignore | 18 ++++++++++++++++++ .gitignore | 6 ++---- Dockerfile | 38 ++++++++++++++++++++++++++++++++++++++ fly.toml | 18 ++++++++++++++++++ 4 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 fly.toml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..099ac1a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,18 @@ +# Generated by Cargo +# will have compiled files and executables +**/debug +**/target +**/vendor + +# These are backup files generated by rustfmt +**/**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +**/*.pdb + +# IDE +**/.idea +**/.vscode + +# Configs +fly.toml diff --git a/.gitignore b/.gitignore index e4d5459..cf65236 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ # will have compiled files and executables debug/ target/ +vendor/ # These are backup files generated by rustfmt **/*.rs.bk @@ -13,8 +14,5 @@ target/ .idea/ .vscode/ -# Configs -config.toml - # Data -*.db \ No newline at end of file +*.db diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..add9663 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +FROM rust:latest as builder + +# Make a fake Rust app to keep a cached layer of compiled crates +RUN USER=root cargo new app +WORKDIR /usr/src/app +COPY Cargo.toml Cargo.lock ./ + +# Needs at least a main.rs file with a main function +RUN mkdir src && echo "fn main(){}" > src/main.rs + +# Will build all dependent crates in release mode +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/usr/src/app/target \ + cargo build --release + +# Copy the rest +COPY . . + +# Build (install) the actual binaries +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/usr/src/app/target \ + cargo install --path . + +# Runtime image +FROM debian:bullseye-slim + +# Run as "app" user +RUN useradd -ms /bin/bash app + +USER app +WORKDIR /app + +# Get compiled binaries from builder's cargo install directory +COPY --from=builder /usr/local/cargo/bin/HamVerBot /app/HamVerBot + +# Copy the config and DB files (workaround!) +COPY config.toml /app/config.toml +COPY db/HamVerBot.db /app/db/HamVerBot.db \ No newline at end of file diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000..7f30c1c --- /dev/null +++ b/fly.toml @@ -0,0 +1,18 @@ +# fly.toml file generated for hamverbot on 2023-02-27T17:38:35+05:30 + +app = "hamverbot" +kill_signal = "SIGINT" +kill_timeout = 5 +processes = [] + +[env] + +[experimental] +auto_rollback = true +cmd = "./HamVerBot" + +[[mounts]] +source = "hamverbot_data" +destination = "/app/db" + +[[services]]