Skip to content

Commit

Permalink
feat(docker): create Dockerfile to deploy to fly.io
Browse files Browse the repository at this point in the history
  • Loading branch information
obviyus committed Mar 4, 2023
1 parent a94f7cd commit 0412c53
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 4 deletions.
18 changes: 18 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# will have compiled files and executables
debug/
target/
vendor/

# These are backup files generated by rustfmt
**/*.rs.bk
Expand All @@ -13,8 +14,5 @@ target/
.idea/
.vscode/

# Configs
config.toml

# Data
*.db
*.db
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -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]]

0 comments on commit 0412c53

Please sign in to comment.