feat: deployment (#46)

This commit is contained in:
Matouš Volf 2024-09-13 12:42:20 +02:00 committed by GitHub
commit ddf3970f85
8 changed files with 163 additions and 6 deletions

85
Cargo.lock generated
View File

@ -687,6 +687,17 @@ dependencies = [
"syn 2.0.74",
]
[[package]]
name = "diesel_migrations"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a73ce704bad4231f001bff3314d91dce4aba0770cee8b233991859abc15c1f6"
dependencies = [
"diesel",
"migrations_internals",
"migrations_macros",
]
[[package]]
name = "diesel_table_macro_syntax"
version = "0.2.0"
@ -2028,6 +2039,27 @@ version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "migrations_internals"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd01039851e82f8799046eabbb354056283fb265c8ec0996af940f4e85a380ff"
dependencies = [
"serde",
"toml",
]
[[package]]
name = "migrations_macros"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffb161cc72176cb37aa47f1fc520d3ef02263d67d661f44f05d05a079e1237fd"
dependencies = [
"migrations_internals",
"proc-macro2",
"quote",
]
[[package]]
name = "mime"
version = "0.3.17"
@ -2575,6 +2607,15 @@ dependencies = [
"syn 2.0.74",
]
[[package]]
name = "serde_spanned"
version = "0.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d"
dependencies = [
"serde",
]
[[package]]
name = "serde_urlencoded"
version = "0.7.1"
@ -2944,6 +2985,7 @@ dependencies = [
"async-std",
"chrono",
"diesel",
"diesel_migrations",
"dioxus",
"dioxus-logger",
"dioxus-query",
@ -3028,6 +3070,40 @@ dependencies = [
"tokio",
]
[[package]]
name = "toml"
version = "0.8.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e"
dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"toml_edit",
]
[[package]]
name = "toml_datetime"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
version = "0.22.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d"
dependencies = [
"indexmap 2.4.0",
"serde",
"serde_spanned",
"toml_datetime",
"winnow",
]
[[package]]
name = "tower"
version = "0.4.13"
@ -3625,6 +3701,15 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "winnow"
version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f"
dependencies = [
"memchr",
]
[[package]]
name = "xxhash-rust"
version = "0.8.12"

View File

@ -27,6 +27,7 @@ time = "0.3.36"
dioxus-sdk = { version = "0.5.0", features = ["i18n"] }
unic-langid-impl = "0.9.5"
voca_rs = "1.15.2"
diesel_migrations = { version = "2.2.0", features = ["postgres"] }
[features]
default = []

View File

@ -0,0 +1,27 @@
services:
app:
build:
dockerfile: docker/prod/app/Dockerfile
networks:
- default
- web-server-network
restart: always
depends_on: [ "db" ]
db:
image: postgres:16.4-bookworm
volumes: [ "db_data:/var/lib/postgresql/data" ]
networks:
- default
environment:
POSTGRES_DB: todo_baggins
POSTGRES_USER: app
POSTGRES_PASSWORD: app
restart: always
volumes:
db_data:
networks:
web-server-network:
external: true

View File

@ -1,5 +1,3 @@
#!/bin/bash
diesel migration run
supervisord -c /etc/supervisor/conf.d/supervisord.conf

View File

@ -0,0 +1,29 @@
FROM rust:1.80-bookworm AS builder
RUN rustup target add wasm32-unknown-unknown && \
cargo install dioxus-cli diesel_cli && \
apt-get update && apt-get install -y nodejs=18.19.0+dfsg-6~deb12u2 npm=9.2.0~ds1-1 supervisor=4.2.5-1
COPY . /srv/app
WORKDIR /srv/app
RUN npm install && \
npm run build && \
dx build --release
FROM debian:bookworm-slim AS runner
RUN apt-get update && apt-get install -y libpq5=15.8-0+deb12u1
COPY --from=builder /srv/app/dist /srv/app/dist
COPY .env /srv/app/.env
RUN chown -R 1000:1000 /srv/app
WORKDIR /srv/app
HEALTHCHECK CMD curl --fail http://localhost:8000 || exit 1
USER 1000:1000
CMD ["./dist/todo-baggins"]

View File

@ -7,18 +7,23 @@ mod server;
mod query;
mod utils;
mod internationalization;
mod migrations;
use components::app::App;
use dioxus::prelude::*;
use dioxus_logger::tracing::{info, Level};
fn main() {
dioxus_logger::init(Level::INFO).expect("failed to initialize logger");
info!("starting app");
dioxus_logger::init(Level::INFO).expect("Failed to initialize the logger.");
info!("Running migrations.");
server_only!(
migrations::run_migrations().expect("Failed to run migrations.");
);
info!("Starting app.");
let cfg = server_only!(
dioxus::fullstack::Config::new().addr(std::net::SocketAddr::from(([0, 0, 0, 0], 8000)))
);
LaunchBuilder::fullstack().with_cfg(cfg).launch(App);
}

12
src/migrations/mod.rs Normal file
View File

@ -0,0 +1,12 @@
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
use std::error::Error;
const MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations");
pub(crate) fn run_migrations() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
let mut connection = crate::server::database_connection::establish_database_connection()?;
connection.run_pending_migrations(MIGRATIONS)?;
Ok(())
}

View File

@ -1,4 +1,4 @@
mod database_connection;
pub(crate) mod database_connection;
pub(crate) mod projects;
pub(crate) mod tasks;
pub(crate) mod subtasks;