Merge branch '24-diesel' into develop
commit
758a332138
|
@ -6,3 +6,6 @@
|
||||||
# Cargo files
|
# Cargo files
|
||||||
!Cargo.toml
|
!Cargo.toml
|
||||||
!Cargo.lock
|
!Cargo.lock
|
||||||
|
|
||||||
|
# Entrypoint for devop container
|
||||||
|
!docker/entrypoint_dev.sh
|
||||||
|
|
|
@ -331,6 +331,7 @@ dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"diesel_derives",
|
"diesel_derives",
|
||||||
"pq-sys",
|
"pq-sys",
|
||||||
|
"r2d2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -741,6 +742,15 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "instant"
|
||||||
|
version = "0.1.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if 1.0.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iovec"
|
name = "iovec"
|
||||||
version = "0.1.4"
|
version = "0.1.4"
|
||||||
|
@ -805,6 +815,15 @@ version = "0.2.93"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41"
|
checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lock_api"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5a3c91c24eae6777794bb1997ad98bbb87daf92890acab859f7eaa4320333176"
|
||||||
|
dependencies = [
|
||||||
|
"scopeguard",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
|
@ -1045,6 +1064,31 @@ dependencies = [
|
||||||
"vcpkg",
|
"vcpkg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parking_lot"
|
||||||
|
version = "0.11.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb"
|
||||||
|
dependencies = [
|
||||||
|
"instant",
|
||||||
|
"lock_api",
|
||||||
|
"parking_lot_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parking_lot_core"
|
||||||
|
version = "0.8.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if 1.0.0",
|
||||||
|
"instant",
|
||||||
|
"libc",
|
||||||
|
"redox_syscall",
|
||||||
|
"smallvec",
|
||||||
|
"winapi 0.3.9",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parse-zoneinfo"
|
name = "parse-zoneinfo"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
|
@ -1204,6 +1248,17 @@ dependencies = [
|
||||||
"proc-macro2 1.0.26",
|
"proc-macro2 1.0.26",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "r2d2"
|
||||||
|
version = "0.8.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "545c5bc2b880973c9c10e4067418407a0ccaa3091781d1671d46eb35107cb26f"
|
||||||
|
dependencies = [
|
||||||
|
"log 0.4.14",
|
||||||
|
"parking_lot",
|
||||||
|
"scheduled-thread-pool",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand"
|
name = "rand"
|
||||||
version = "0.8.3"
|
version = "0.8.3"
|
||||||
|
@ -1359,13 +1414,28 @@ version = "0.4.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d7954a707f9ca18aa74ca8c1f5d1f900f52a4dceb68e96e3112143f759cfd20e"
|
checksum = "d7954a707f9ca18aa74ca8c1f5d1f900f52a4dceb68e96e3112143f759cfd20e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"diesel",
|
||||||
"log 0.4.14",
|
"log 0.4.14",
|
||||||
"notify",
|
"notify",
|
||||||
|
"r2d2",
|
||||||
"rocket",
|
"rocket",
|
||||||
|
"rocket_contrib_codegen",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rocket_contrib_codegen"
|
||||||
|
version = "0.4.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "30deb6dec53b91fac3538a2a3935cf13e0f462745f9f33bf27bedffbe7265b5d"
|
||||||
|
dependencies = [
|
||||||
|
"devise",
|
||||||
|
"quote 0.6.13",
|
||||||
|
"version_check 0.9.3",
|
||||||
|
"yansi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rocket_http"
|
name = "rocket_http"
|
||||||
version = "0.4.7"
|
version = "0.4.7"
|
||||||
|
@ -1423,6 +1493,21 @@ dependencies = [
|
||||||
"winapi 0.3.9",
|
"winapi 0.3.9",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "scheduled-thread-pool"
|
||||||
|
version = "0.2.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dc6f74fd1204073fa02d5d5d68bec8021be4c38690b61264b2fdb48083d0e7d7"
|
||||||
|
dependencies = [
|
||||||
|
"parking_lot",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "scopeguard"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "security-framework"
|
name = "security-framework"
|
||||||
version = "2.2.0"
|
version = "2.2.0"
|
||||||
|
|
|
@ -32,4 +32,4 @@ diesel = { version = "1.4.6", features = ["postgres"] }
|
||||||
[dependencies.rocket_contrib]
|
[dependencies.rocket_contrib]
|
||||||
version = "0.4.7"
|
version = "0.4.7"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["json"]
|
features = ["json", "diesel_postgres_pool"]
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
[development]
|
||||||
|
address = "0.0.0.0"
|
||||||
|
port = 8000
|
||||||
|
keep_alive = 5
|
||||||
|
read_timeout = 5
|
||||||
|
write_timeout = 5
|
||||||
|
log = "normal"
|
||||||
|
limits = { forms = 32768 }
|
||||||
|
|
||||||
|
[global.databases]
|
||||||
|
postgres_fej = { url = "postgres://fej:fej@fej_db:5432/fej" }
|
|
@ -4,14 +4,13 @@ FROM alpine:latest AS builder
|
||||||
ENV PATH "$PATH:/root/.cargo/bin"
|
ENV PATH "$PATH:/root/.cargo/bin"
|
||||||
# Needed for proper compiling of openssl-dev
|
# Needed for proper compiling of openssl-dev
|
||||||
ENV RUSTFLAGS "-C target-feature=-crt-static"
|
ENV RUSTFLAGS "-C target-feature=-crt-static"
|
||||||
# Otherwise, the debug build can't be used from the container
|
|
||||||
ENV ROCKET_ADDRESS "0.0.0.0"
|
|
||||||
|
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
# Install build dependencies, rustup & rust's nightly build & toolchain
|
# Install build dependencies, rustup & rust's nightly build & toolchain
|
||||||
RUN apk update && apk add --no-cache openssl-dev build-base curl && \
|
RUN apk update && apk add --no-cache openssl-dev curl postgresql-dev libgcc musl-dev gcc && \
|
||||||
{ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly; }
|
{ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly; } && \
|
||||||
|
rustup target add x86_64-unknown-linux-musl --toolchain nightly
|
||||||
|
|
||||||
# Copy source code over to builder
|
# Copy source code over to builder
|
||||||
COPY Cargo.toml Cargo.lock ./
|
COPY Cargo.toml Cargo.lock ./
|
||||||
|
|
|
@ -2,5 +2,7 @@ FROM chewingbever/fej-builder:latest
|
||||||
|
|
||||||
ENV RUST_BACKTRACE 1
|
ENV RUST_BACKTRACE 1
|
||||||
|
|
||||||
ENTRYPOINT ["cargo"]
|
COPY ./docker/entrypoint_dev.sh /entrypoint.sh
|
||||||
|
|
||||||
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
CMD ["run", "--bin", "server"]
|
CMD ["run", "--bin", "server"]
|
||||||
|
|
|
@ -7,7 +7,10 @@ FROM chewingbever/fej-builder:latest AS builder
|
||||||
# NOTE: cargo install auto-appends bin to the path
|
# NOTE: cargo install auto-appends bin to the path
|
||||||
RUN --mount=type=cache,target=/usr/src/app/target \
|
RUN --mount=type=cache,target=/usr/src/app/target \
|
||||||
--mount=type=cache,target=/root/.cargo/registry \
|
--mount=type=cache,target=/root/.cargo/registry \
|
||||||
cargo install --path . --root /usr/local
|
cargo install \
|
||||||
|
--path . \
|
||||||
|
--root /usr/local \
|
||||||
|
--target x86_64-unknown-linux-musl
|
||||||
|
|
||||||
|
|
||||||
# Now, we create the actual image
|
# Now, we create the actual image
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
# All this file does is inject the target
|
||||||
|
cargo "$@" --target x86_64-unknown-linux-musl
|
5
fejctl
5
fejctl
|
@ -28,6 +28,10 @@ function create_images() {
|
||||||
#
|
#
|
||||||
# $@: the arguments to pass to the image (passed as arguments to cargo)
|
# $@: the arguments to pass to the image (passed as arguments to cargo)
|
||||||
function run_image() {
|
function run_image() {
|
||||||
|
docker volume create fej_build-cache
|
||||||
|
docker volume create fej_registry-cache
|
||||||
|
docker volume create fej_db-data
|
||||||
|
|
||||||
# Run the database image
|
# Run the database image
|
||||||
docker run --rm \
|
docker run --rm \
|
||||||
--detach \
|
--detach \
|
||||||
|
@ -52,6 +56,7 @@ function run_image() {
|
||||||
--network fej \
|
--network fej \
|
||||||
-v 'fej_build-cache:/usr/src/app/target' \
|
-v 'fej_build-cache:/usr/src/app/target' \
|
||||||
-v 'fej_registry-cache:/root/.cargo/registry' \
|
-v 'fej_registry-cache:/root/.cargo/registry' \
|
||||||
|
-v "$PWD/Rocket.toml:/usr/src/app/Rocket.toml:ro" \
|
||||||
"$image:dev" "$@"
|
"$image:dev" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rocket;
|
extern crate rocket;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate rocket_contrib;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
@ -14,6 +16,7 @@ mod routes;
|
||||||
use rocket::fairing::{Fairing, Info, Kind};
|
use rocket::fairing::{Fairing, Info, Kind};
|
||||||
use rocket::http::Header;
|
use rocket::http::Header;
|
||||||
use rocket::{Request, Response};
|
use rocket::{Request, Response};
|
||||||
|
use rocket_contrib::databases::diesel;
|
||||||
|
|
||||||
pub struct CORS;
|
pub struct CORS;
|
||||||
|
|
||||||
|
@ -36,9 +39,14 @@ impl Fairing for CORS {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This defines a connection to the database
|
||||||
|
#[database("postgres_fej")]
|
||||||
|
struct FejDbConn(diesel::PgConnection);
|
||||||
|
|
||||||
fn rocket() -> rocket::Rocket {
|
fn rocket() -> rocket::Rocket {
|
||||||
rocket::ignite()
|
rocket::ignite()
|
||||||
.attach(CORS)
|
.attach(CORS)
|
||||||
|
.attach(FejDbConn::fairing())
|
||||||
.mount("/ivago", routes::ivago())
|
.mount("/ivago", routes::ivago())
|
||||||
.register(catchers![catchers::not_found])
|
.register(catchers![catchers::not_found])
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue