Fix Dockerfile on x86_64 and run migrations at boot
Diff
Cargo.lock | 34 ++++++++++++++++++++++++++++++++++
Dockerfile | 12 ++++--------
chartered-db/Cargo.toml | 2 ++
chartered-db/src/lib.rs | 14 +++++++++++++-
4 files changed, 51 insertions(+), 11 deletions(-)
@@ -200,11 +200,13 @@
"chrono",
"diesel",
"diesel_logger",
"diesel_migrations",
"displaydoc",
"dotenv",
"hex",
"http",
"itertools",
"libsqlite3-sys",
"option_set",
"rand",
"serde",
@@ -418,6 +420,16 @@
dependencies = [
"diesel",
"log",
]
[[package]]
name = "diesel_migrations"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf3cde8413353dc7f5d72fa8ce0b99a560a359d2c5ef1e5817ca731cd9008f4c"
dependencies = [
"migrations_internals",
"migrations_macros",
]
[[package]]
@@ -835,6 +847,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290b64917f8b0cb885d9de0f9959fe1f775d7fa12f1da2db9001c1c8ab60f89d"
dependencies = [
"cc",
"pkg-config",
"vcpkg",
]
@@ -874,6 +887,27 @@
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
[[package]]
name = "migrations_internals"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b4fc84e4af020b837029e017966f86a1c2d5e83e64b589963d5047525995860"
dependencies = [
"diesel",
]
[[package]]
name = "migrations_macros"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9753f12909fd8d923f75ae5c3258cae1ed3c8ec052e1b38c93c21a6d157f789c"
dependencies = [
"migrations_internals",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "mime"
@@ -1,21 +1,17 @@
FROM rust:alpine AS builder
RUN apk add --update gcc g++ build-base alpine-sdk sqlite-dev
WORKDIR /app
COPY . /app
RUN cargo build --release
FROM alpine AS chartered-git
RUN apk add --update sqlite sqlite-dev && \
ln -s /lib/ld-musl-$(uname -m).so.1 /lib/ld-linux-$(uname -m).so.1
FROM scratch AS chartered-git
WORKDIR /app
COPY --from=builder /app/target/release/chartered-git /app/chartered-git
ENV RUST_LOG=info
ENV RUST_LOG=debug
ENTRYPOINT ["/app/chartered-git"]
FROM alpine AS chartered-web
RUN apk add --update sqlite sqlite-dev && \
ln -s /lib/ld-musl-$(uname -m).so.1 /lib/ld-linux-$(uname -m).so.1
FROM scratch AS chartered-web
WORKDIR /app
COPY --from=builder /app/target/release/chartered-web /app/chartered-web
ENV RUST_LOG=info
ENV RUST_LOG=debug
ENTRYPOINT ["/app/chartered-web"]
@@ -14,10 +14,12 @@
chrono = "0.4"
diesel = { version = "1", features = ["sqlite", "r2d2", "chrono"] }
diesel_logger = "0.1"
diesel_migrations = "1.4"
displaydoc = "0.2"
hex = "0.4"
http = "0.2"
itertools = "0.10"
libsqlite3-sys = { version = "*", features = ["bundled"] }
option_set = "0.1"
rand = "0.8"
serde = { version = "1", features = ["derive"] }
@@ -38,8 +38,8 @@
pub mod users;
pub mod uuid;
#[macro_use]
extern crate diesel;
#[macro_use] extern crate diesel;
#[macro_use] extern crate diesel_migrations;
use diesel::{
expression::{grouped::Grouped, AsExpression, Expression},
@@ -54,14 +54,22 @@
pub type ConnectionPool = Arc<Pool<ConnectionManager<LoggingConnection<diesel::SqliteConnection>>>>;
pub type Result<T> = std::result::Result<T, Error>;
embed_migrations!();
pub fn init() -> Result<ConnectionPool> {
Ok(Arc::new(Pool::new(ConnectionManager::new("chartered.db"))?))
let pool = Pool::new(ConnectionManager::new("chartered.db"))?;
embedded_migrations::run_with_output(&pool.get()?, &mut std::io::stdout())?;
Ok(Arc::new(pool))
}
#[derive(Error, Display, Debug)]
pub enum Error {
Connection(#[from] diesel::r2d2::PoolError),
MigrationError(#[from] diesel_migrations::RunMigrationsError),
Query(#[from] diesel::result::Error),