Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge(dockerize): dockerize app & release profile Rocket.toml; #10

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
target
database

.git
.gitignore

Dockerfile
.dockerignore
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ features = ["sqlite_pool"]

[dependencies.serde_json]
version = "1.0.0"

[dependencies.rusqlite]
version = "0.29.0"
features = ["bundled"]
58 changes: 58 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# First Stage
FROM rust:alpine as build

WORKDIR /src

# ca-certificates so we can copy /etc/ssl to the release stage
RUN apk update && apk add --no-cache \
ca-certificates \
build-base \
pkgconfig \
libressl-dev \
musl-dev \
perl

RUN rustup target add x86_64-unknown-linux-musl


# Build & Cache Dependencies
RUN USER=root cargo new tuna

WORKDIR /src/tuna

COPY Cargo.toml Cargo.lock ./

RUN cargo build --target x86_64-unknown-linux-musl --release


# Build the App
COPY ./src ./src

# Refinery embeds the migrations at build time
COPY ./migrations ./migrations

# Cargo checks if it needs to rebuild based on the mtime of the files...
# The copied main.rs retains the original timestamp, so the dummy looks newer -_-
RUN touch src/main.rs
# It was consensual I swear!

RUN cargo build --target x86_64-unknown-linux-musl --release


# Second Stage
FROM scratch as release

# We can use the ssl certs from the build stage
COPY --from=build /etc/ssl /etc/ssl

# Copy the binary from build stage
COPY --from=build /src/tuna/target/x86_64-unknown-linux-musl/release/tuna .

# Runtime config files
COPY ./Rocket.toml /Rocket.toml

# blast off
CMD ["/tuna"]
# Notes:
# - rusqlite has a feature bundled which automatically compiles and links SQLite.
# - you need to add volumes for the database directory or the data won't be persistent.
5 changes: 5 additions & 0 deletions Rocket.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[release]
address = "0.0.0.0"
port = 8000
ip_header = false

# Fun Fact: In-memory Databases don't support transactions...
[default.databases.db]
url = "file:database/sqlite/db.sqlite?cache=shared"
Loading